use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class TestInitDelayingTopologyEventListener method createView.
private TopologyView createView(boolean current) {
final TopologyView view = Mockito.mock(TopologyView.class);
Mockito.when(view.isCurrent()).thenReturn(current);
final InstanceDescription local = Mockito.mock(InstanceDescription.class);
Mockito.when(local.isLeader()).thenReturn(true);
Mockito.when(local.isLocal()).thenReturn(true);
Mockito.when(local.getSlingId()).thenReturn("id");
Mockito.when(view.getLocalInstance()).thenReturn(local);
final ClusterView localView = Mockito.mock(ClusterView.class);
Mockito.when(localView.getId()).thenReturn("1");
Mockito.when(localView.getInstances()).thenReturn(Collections.singletonList(local));
Mockito.when(view.getClusterViews()).thenReturn(Collections.singleton(localView));
Mockito.when(local.getClusterView()).thenReturn(localView);
return view;
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class DummyTopologyView method clone.
public static DummyTopologyView clone(final DummyTopologyView view) {
final DummyTopologyView result = new DummyTopologyView(view.id);
final Iterator<InstanceDescription> it = view.getInstances().iterator();
Map<String, DefaultClusterView> clusters = new HashMap<String, DefaultClusterView>();
while (it.hasNext()) {
InstanceDescription id = it.next();
String clusterId = id.getClusterView().getId();
DefaultClusterView cluster = clusters.get(clusterId);
if (cluster == null) {
cluster = new DefaultClusterView(clusterId);
clusters.put(clusterId, cluster);
}
DefaultInstanceDescription clone = clone(cluster, id);
result.addInstanceDescription(clone);
}
if (!view.isCurrent()) {
result.setNotCurrent();
}
return result;
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class ViewStateManagerImpl method onlyDiffersInProperties.
protected boolean onlyDiffersInProperties(BaseTopologyView newView) {
if (previousView == null) {
return false;
}
if (newView == null) {
throw new IllegalArgumentException("newView must not be null");
}
String previousSyncTokenId = null;
String newSyncTokenId = null;
try {
previousSyncTokenId = previousView.getLocalClusterSyncTokenId();
} catch (IllegalStateException re) {
previousSyncTokenId = null;
}
try {
newSyncTokenId = newView.getLocalClusterSyncTokenId();
} catch (IllegalStateException re) {
newSyncTokenId = null;
}
if ((previousSyncTokenId == null && newSyncTokenId != null) || (newSyncTokenId == null && previousSyncTokenId != null) || (previousSyncTokenId != null && !previousSyncTokenId.equals(newSyncTokenId))) {
return false;
}
if (previousView.getInstances().size() != newView.getInstances().size()) {
return false;
}
if (previousView.equals(newView)) {
return false;
}
Set<String> newIds = new HashSet<String>();
for (InstanceDescription newInstance : newView.getInstances()) {
newIds.add(newInstance.getSlingId());
}
for (InstanceDescription oldInstance : previousView.getInstances()) {
InstanceDescription newInstance = newView.getInstance(oldInstance.getSlingId());
if (newInstance == null) {
return false;
}
if (oldInstance.isLeader() != newInstance.isLeader()) {
return false;
}
if (!oldInstance.getClusterView().getId().equals(newInstance.getClusterView().getId())) {
return false;
}
}
return true;
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class TopologyWebConsolePlugin method printCluster.
/**
* Render a particular cluster
*/
private void printCluster(final PrintWriter pw, final ClusterView renderCluster, final ClusterView localCluster) {
final Collection<Announcement> announcements = announcementRegistry.listAnnouncementsInSameCluster(localCluster);
for (final InstanceDescription instanceDescription : renderCluster.getInstances()) {
final boolean inLocalCluster = renderCluster == localCluster;
Announcement parentAnnouncement = null;
for (Iterator<Announcement> it2 = announcements.iterator(); it2.hasNext(); ) {
Announcement announcement = it2.next();
for (Iterator<InstanceDescription> it3 = announcement.listInstances().iterator(); it3.hasNext(); ) {
InstanceDescription announcedInstance = it3.next();
if (announcedInstance.getSlingId().equals(instanceDescription.getSlingId())) {
parentAnnouncement = announcement;
break;
}
}
}
final boolean isLocal = instanceDescription.isLocal();
final String slingId = instanceDescription.getSlingId();
pw.print("Sling ID : ");
pw.print(slingId);
pw.println();
pw.print("Cluster View ID : ");
pw.print(instanceDescription.getClusterView() == null ? "null" : instanceDescription.getClusterView().getId());
pw.println();
pw.print("Local instance : ");
pw.print(isLocal);
pw.println();
pw.print("Leader instance : ");
pw.print(instanceDescription.isLeader());
pw.println();
pw.print("In local cluster : ");
if (inLocalCluster) {
pw.print("local");
} else {
pw.print("remote");
}
pw.println();
pw.print("Announced by : ");
if (inLocalCluster) {
pw.print("n/a");
} else {
if (parentAnnouncement != null) {
pw.print(parentAnnouncement.getOwnerId());
} else {
pw.print("(changing)");
}
}
pw.println();
pw.println("Properties:");
for (final Map.Entry<String, String> entry : instanceDescription.getProperties().entrySet()) {
pw.print("- ");
pw.print(entry.getKey());
pw.print(" : ");
pw.print(entry.getValue());
pw.println();
}
pw.println();
pw.println();
}
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class TestViewStateManager method testChangedPropertiesChanged.
@Test
public void testChangedPropertiesChanged() throws Exception {
final DummyListener listener = new DummyListener();
mgr.installMinEventDelayHandler(new DiscoveryService() {
@Override
public TopologyView getTopology() {
throw new IllegalStateException("not yet impl");
}
}, new DummyScheduler(), 1);
mgr.handleActivated();
TestHelper.assertNoEvents(listener);
mgr.bind(listener);
TestHelper.assertNoEvents(listener);
mgr.handleChanging();
TestHelper.assertNoEvents(listener);
final BaseTopologyView view1 = new DummyTopologyView().addInstance();
InstanceDescription instance1 = view1.getInstances().iterator().next();
ClusterView cluster1 = instance1.getClusterView();
mgr.handleNewView(view1);
assertEvents(listener, EventHelper.newInitEvent(view1));
DefaultClusterView cluster2 = new DefaultClusterView(new String(cluster1.getId()));
final BaseTopologyView view2 = new DummyTopologyView(view1.getLocalClusterSyncTokenId()).addInstance(instance1.getSlingId(), cluster2, instance1.isLeader(), instance1.isLocal());
DefaultInstanceDescription instance2 = (DefaultInstanceDescription) view2.getLocalInstance();
instance2.setProperty("foo", "bar");
mgr.handleNewView(view2);
assertEvents(listener, EventHelper.newPropertiesChangedEvent(view1, view2));
}
Aggregations