use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class TopologyWebConsolePlugin method printConfiguration.
public void printConfiguration(final PrintWriter pw) {
final TopologyView topology = this.currentView;
pw.println(TITLE);
pw.println("---------------------------------------");
pw.println();
if (topology == null) {
pw.println("No topology available yet!");
return;
}
pw.print("Topology");
if (!topology.isCurrent()) {
pw.print(" CHANGING! (the view is no longer current!)");
}
pw.println();
pw.println();
final Set<ClusterView> clusters = topology.getClusterViews();
final ClusterView myCluster = topology.getLocalInstance().getClusterView();
printCluster(pw, myCluster, myCluster);
for (Iterator<ClusterView> it = clusters.iterator(); it.hasNext(); ) {
ClusterView clusterView = it.next();
if (clusterView.equals(myCluster)) {
// skip - I already rendered that
continue;
}
printCluster(pw, clusterView, myCluster);
}
pw.println();
pw.println();
final Collection<CachedAnnouncement> incomingConnections = announcementRegistry.listLocalIncomingAnnouncements();
if (incomingConnections.size() > 0) {
pw.println("Incoming topology connectors");
pw.println("---------------------------------------");
for (final CachedAnnouncement incomingCachedAnnouncement : incomingConnections) {
Announcement incomingAnnouncement = incomingCachedAnnouncement.getAnnouncement();
pw.print("Owner Sling Id : ");
pw.print(incomingAnnouncement.getOwnerId());
pw.println();
if (incomingAnnouncement.getServerInfo() != null) {
pw.print("Server Info : ");
pw.print(incomingAnnouncement.getServerInfo());
pw.println();
}
pw.println("Last heartbeat received : " + beautifiedTimeDiff(incomingCachedAnnouncement.getLastPing()));
pw.println("Timeout : " + beautifiedDueTime(incomingCachedAnnouncement.getSecondsUntilTimeout()));
pw.println();
}
pw.println();
pw.println();
}
final Collection<TopologyConnectorClientInformation> outgoingConnections = connectorRegistry.listOutgoingConnectors();
if (outgoingConnections.size() > 0) {
pw.println("Outgoing topology connectors");
pw.println("---------------------------------------");
for (final TopologyConnectorClientInformation topologyConnectorClient : outgoingConnections) {
final String remoteSlingId = topologyConnectorClient.getRemoteSlingId();
final boolean autoStopped = topologyConnectorClient.isAutoStopped();
final boolean isConnected = topologyConnectorClient.isConnected() && remoteSlingId != null;
pw.print("Connector URL : ");
pw.print(topologyConnectorClient.getConnectorUrl());
pw.println();
if (autoStopped) {
pw.println("Conncted to Sling Id : auto-stopped");
pw.println("Connector status : auto-stopped due to local-loop");
} else if (isConnected && !topologyConnectorClient.representsLoop()) {
pw.print("Connected to Sling Id : ");
pw.println(remoteSlingId);
pw.println("Connector status : ok, in use");
} else if (topologyConnectorClient.representsLoop()) {
pw.print("Connected to Sling Id : ");
pw.println(remoteSlingId);
pw.println("Connector status : ok, unused (loop or duplicate): standby");
} else {
final int statusCode = topologyConnectorClient.getStatusCode();
final String statusDetails = topologyConnectorClient.getStatusDetails();
final String tooltipText;
switch(statusCode) {
case HttpServletResponse.SC_UNAUTHORIZED:
tooltipText = HttpServletResponse.SC_UNAUTHORIZED + ": possible setup issue of discovery.impl on target instance, or wrong URL";
break;
case HttpServletResponse.SC_NOT_FOUND:
tooltipText = HttpServletResponse.SC_NOT_FOUND + ": possible white list rejection by target instance";
break;
case -1:
tooltipText = "-1: check error log. possible connection refused.";
break;
default:
tooltipText = null;
}
pw.println("Connected to Sling Id : not connected");
pw.print("Connector status : not ok");
if (tooltipText != null) {
pw.print(" (");
pw.print(tooltipText);
pw.print(")");
}
pw.print(" (HTTP StatusCode: " + statusCode + ", " + statusDetails + ")");
pw.println();
pw.println("Last heartbeat sent : " + beautifiedTimeDiff(topologyConnectorClient.getLastPingSent()));
pw.println("Next heartbeat due : " + beautifiedDueTime(topologyConnectorClient.getNextPingDue()));
}
pw.println();
}
pw.println();
pw.println();
}
if (topologyLog.size() > 0) {
pw.println("Topology Change History");
pw.println("---------------------------------------");
for (final String aLogEntry : topologyLog) {
pw.println(aLogEntry);
}
pw.println();
pw.println();
}
if (propertyChangeLog.size() > 0) {
pw.println("Property Change History");
pw.println("---------------------------------------");
for (final String aLogEntry : propertyChangeLog) {
pw.println(aLogEntry);
}
pw.println();
}
pw.println("SyncTokenService History");
pw.println("---------------------------------------");
if (!config.useSyncTokenService()) {
pw.println("(disabled - useSyncTokenService flag is false)");
} else if (syncTokenService == null) {
pw.println("(no SyncTokenService available)");
} else {
ClusterSyncHistory clusterSyncHistory = syncTokenService.getClusterSyncHistory();
if (clusterSyncHistory == null) {
pw.println("(no history available)");
} else {
for (String syncHistoryEntry : clusterSyncHistory.getSyncHistory()) {
pw.println(syncHistoryEntry);
}
}
}
pw.println();
pw.println();
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class JobManagerConfigurationTest method testTopologyChange.
@Test
public void testTopologyChange() throws Exception {
// mock scheduler
final ChangeListener ccl = new ChangeListener();
// add change listener and verify
ccl.init(1);
final JobManagerConfiguration config = new JobManagerConfiguration();
((AtomicBoolean) TestUtil.getFieldValue(config, "active")).set(true);
InitDelayingTopologyEventListener startupDelayListener = new InitDelayingTopologyEventListener(1, new TopologyEventListener() {
@Override
public void handleTopologyEvent(TopologyEvent event) {
config.doHandleTopologyEvent(event);
}
});
TestUtil.setFieldValue(config, "startupDelayListener", startupDelayListener);
config.addListener(ccl);
ccl.await();
assertEquals(1, ccl.events.size());
assertFalse(ccl.events.get(0));
// create init view
ccl.init(1);
final TopologyView initView = createView();
final TopologyEvent init = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_INIT, null, initView);
config.handleTopologyEvent(init);
ccl.await();
assertEquals(1, ccl.events.size());
assertTrue(ccl.events.get(0));
// change view, followed by change props
ccl.init(2);
final TopologyView view2 = createView();
Mockito.when(initView.isCurrent()).thenReturn(false);
final TopologyEvent change1 = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, initView, view2);
final TopologyView view3 = createView();
final TopologyEvent change2 = new TopologyEvent(TopologyEvent.Type.PROPERTIES_CHANGED, view2, view3);
config.handleTopologyEvent(change1);
Mockito.when(view2.isCurrent()).thenReturn(false);
config.handleTopologyEvent(change2);
ccl.await();
assertEquals(2, ccl.events.size());
assertFalse(ccl.events.get(0));
assertTrue(ccl.events.get(1));
// we wait another 4 secs to see if there is no another event
Thread.sleep(4000);
assertEquals(2, ccl.events.size());
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class TopologyCapabilitiesTest method setup.
@Before
public void setup() {
// local cluster view
final ClusterView cv = Mockito.mock(ClusterView.class);
Mockito.when(cv.getId()).thenReturn("cluster");
// local description
final InstanceDescription local = Mockito.mock(InstanceDescription.class);
Mockito.when(local.isLeader()).thenReturn(true);
Mockito.when(local.getSlingId()).thenReturn("local");
Mockito.when(local.getProperty(TopologyCapabilities.PROPERTY_TOPICS)).thenReturn("foo,bar/*,a/**,d/1/2,d/1/*,d/**");
Mockito.when(local.getClusterView()).thenReturn(cv);
// topology view
final TopologyView tv = Mockito.mock(TopologyView.class);
Mockito.when(tv.getInstances()).thenReturn(Collections.singleton(local));
Mockito.when(tv.getLocalInstance()).thenReturn(local);
final JobManagerConfiguration config = Mockito.mock(JobManagerConfiguration.class);
caps = new TopologyCapabilities(tv, config);
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class EventHelper method toShortString.
/**
* Returns a shorter toString than the default TopologyEvent.toString()
* which can be rather large and unusable in log files
*/
public static String toShortString(TopologyEvent event) {
final TopologyView oldView = event.getOldView();
final TopologyView newView = event.getNewView();
final String oldViewToString;
final String newViewtoString;
if (oldView instanceof BaseTopologyView) {
final BaseTopologyView baseOldView = (BaseTopologyView) oldView;
oldViewToString = baseOldView.toShortString();
} else {
oldViewToString = String.valueOf(oldView);
}
if (newView instanceof BaseTopologyView) {
final BaseTopologyView baseNewView = (BaseTopologyView) newView;
newViewtoString = baseNewView.toShortString();
} else {
newViewtoString = String.valueOf(newView);
}
return "TopologyEvent [type=" + event.getType() + ", oldView=" + oldViewToString + ", newView=" + newViewtoString + "]";
}
use of org.apache.sling.discovery.TopologyView in project sling by apache.
the class TestInitDelayingTopologyEventListener method createEvent.
private TopologyEvent createEvent(Type type) {
TopologyView oldView = createView(false);
TopologyView newView = createView(true);
switch(type) {
case TOPOLOGY_CHANGING:
{
return new TopologyEvent(type, oldView, null);
}
case PROPERTIES_CHANGED:
case TOPOLOGY_CHANGED:
{
return new TopologyEvent(type, oldView, newView);
}
case TOPOLOGY_INIT:
{
return new TopologyEvent(type, null, newView);
}
default:
{
throw new IllegalArgumentException("unknown type: " + type);
}
}
}
Aggregations