Search in sources :

Example 1 with ClusterViewService

use of org.apache.sling.discovery.base.commons.ClusterViewService in project sling by apache.

the class AbstractClusterTest method ping.

private Announcement ping(VirtualInstance to, final Announcement incomingTopologyAnnouncement) throws UndefinedClusterViewException {
    final String slingId = to.slingId;
    final ClusterViewService clusterViewService = to.getClusterViewService();
    final AnnouncementRegistry announcementRegistry = to.getAnnouncementRegistry();
    incomingTopologyAnnouncement.removeInherited(slingId);
    final Announcement replyAnnouncement = new Announcement(slingId);
    long backoffInterval = -1;
    final ClusterView clusterView = clusterViewService.getLocalClusterView();
    if (!incomingTopologyAnnouncement.isCorrectVersion()) {
        fail("incorrect version");
        // never reached
        return null;
    } else if (ClusterViewHelper.contains(clusterView, incomingTopologyAnnouncement.getOwnerId())) {
        fail("loop=true");
        // never reached
        return null;
    } else if (ClusterViewHelper.containsAny(clusterView, incomingTopologyAnnouncement.listInstances())) {
        fail("incoming announcement contains instances that are part of my cluster");
        // never reached
        return null;
    } else {
        backoffInterval = announcementRegistry.registerAnnouncement(incomingTopologyAnnouncement);
        if (backoffInterval == -1) {
            fail("rejecting an announcement from an instance that I already see in my topology: ");
            // never reached
            return null;
        } else {
            // normal, successful case: replying with the part of the topology which this instance sees
            replyAnnouncement.setLocalCluster(clusterView);
            announcementRegistry.addAllExcept(replyAnnouncement, clusterView, new AnnouncementFilter() {

                @Override
                public boolean accept(final String receivingSlingId, Announcement announcement) {
                    if (announcement.getPrimaryKey().equals(incomingTopologyAnnouncement.getPrimaryKey())) {
                        return false;
                    }
                    return true;
                }
            });
            return replyAnnouncement;
        }
    }
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) AnnouncementRegistry(org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistry) AnnouncementFilter(org.apache.sling.discovery.base.connectors.announcement.AnnouncementFilter) ClusterViewService(org.apache.sling.discovery.base.commons.ClusterViewService)

Example 2 with ClusterViewService

use of org.apache.sling.discovery.base.commons.ClusterViewService in project sling by apache.

the class ConnectorRegistryImplTest method testRegisterUnregister.

@Test
public void testRegisterUnregister() throws Exception {
    BaseConfig config = new SimpleConnectorConfig() {

        @Override
        public long getConnectorPingTimeout() {
            return 20000;
        }
    };
    AnnouncementRegistryImpl announcementRegistry = AnnouncementRegistryImpl.testConstructorAndActivate(MockFactory.mockResourceResolverFactory(), new DummySlingSettingsService(UUID.randomUUID().toString()), config);
    ConnectorRegistry c = ConnectorRegistryImpl.testConstructor(announcementRegistry, config);
    final URL url = new URL("http://localhost:1234/connector");
    final ClusterViewService cvs = i.getClusterViewService();
    try {
        c.registerOutgoingConnector(null, url);
        fail("should have complained");
    } catch (IllegalArgumentException e) {
    // ok
    }
    try {
        c.registerOutgoingConnector(cvs, null);
        fail("should have complained");
    } catch (IllegalArgumentException e) {
    // ok
    }
    TopologyConnectorClientInformation client = c.registerOutgoingConnector(cvs, url);
    try {
        // should not be able to register same url twice
        client = c.registerOutgoingConnector(cvs, url);
    // ok - no longer complains - SLING-3446
    } catch (IllegalStateException e) {
        // SLING-3446
        fail("should no longer be thrown");
    }
    try {
        c.unregisterOutgoingConnector(null);
        fail("should have complained");
    } catch (IllegalArgumentException e) {
    // ok
    }
    c.unregisterOutgoingConnector(client.getId());
}
Also used : SimpleConnectorConfig(org.apache.sling.discovery.base.its.setup.mock.SimpleConnectorConfig) AnnouncementRegistryImpl(org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistryImpl) BaseConfig(org.apache.sling.discovery.base.connectors.BaseConfig) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService) ClusterViewService(org.apache.sling.discovery.base.commons.ClusterViewService) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ClusterViewService

use of org.apache.sling.discovery.base.commons.ClusterViewService in project sling by apache.

the class DiscoveryServiceImpl method checkForLocalClusterViewChange.

/**
     * only checks for local clusterView changes.
     * thus eg avoids doing synchronized with annotationregistry
     **/
public void checkForLocalClusterViewChange() {
    viewStateManagerLock.lock();
    try {
        if (!activated) {
            logger.debug("checkForLocalClusterViewChange: not yet activated, ignoring");
            return;
        }
        try {
            ClusterViewService clusterViewService = getClusterViewService();
            if (clusterViewService == null) {
                throw new UndefinedClusterViewException(Reason.REPOSITORY_EXCEPTION, "no ClusterViewService available at the moment");
            }
            LocalClusterView localClusterView = clusterViewService.getLocalClusterView();
        } catch (UndefinedClusterViewException e) {
            // SLING-5030 : when we're cut off from the local cluster we also
            // treat it as being cut off from the entire topology, ie we don't
            // update the announcements but just return
            // the previous oldView marked as !current
            logger.info("checkForLocalClusterViewChange: undefined cluster view: " + e.getReason() + "] " + e);
            getOldView().setNotCurrent();
            viewStateManager.handleChanging();
            if (e.getReason() == Reason.ISOLATED_FROM_TOPOLOGY) {
                handleIsolatedFromTopology();
            }
        }
    } finally {
        if (viewStateManagerLock != null) {
            viewStateManagerLock.unlock();
        }
    }
}
Also used : LocalClusterView(org.apache.sling.discovery.commons.providers.spi.LocalClusterView) UndefinedClusterViewException(org.apache.sling.discovery.base.commons.UndefinedClusterViewException) ClusterViewService(org.apache.sling.discovery.base.commons.ClusterViewService)

Aggregations

ClusterViewService (org.apache.sling.discovery.base.commons.ClusterViewService)3 URL (java.net.URL)1 ClusterView (org.apache.sling.discovery.ClusterView)1 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)1 BaseConfig (org.apache.sling.discovery.base.connectors.BaseConfig)1 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)1 AnnouncementFilter (org.apache.sling.discovery.base.connectors.announcement.AnnouncementFilter)1 AnnouncementRegistry (org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistry)1 AnnouncementRegistryImpl (org.apache.sling.discovery.base.connectors.announcement.AnnouncementRegistryImpl)1 SimpleConnectorConfig (org.apache.sling.discovery.base.its.setup.mock.SimpleConnectorConfig)1 LocalClusterView (org.apache.sling.discovery.commons.providers.spi.LocalClusterView)1 DummySlingSettingsService (org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)1 Test (org.junit.Test)1