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;
}
}
}
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());
}
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();
}
}
}
Aggregations