Search in sources :

Example 11 with ClusterView

use of org.apache.sling.discovery.ClusterView in project sling by apache.

the class TopologyWebConsolePlugin method renderOverview.

/**
     * Render the overview of the entire topology
     */
private void renderOverview(final PrintWriter pw, final TopologyView topology) {
    pw.println("<p class=\"statline ui-state-highlight\">Configuration</p>");
    pw.println("<br/>");
    pw.print("<a href=\"${appRoot}/configMgr/org.apache.sling.discovery.impl.Config\">Configure Discovery Service</a>");
    pw.println("<br/>");
    pw.println("<br/>");
    final String changing;
    if (!topology.isCurrent()) {
        changing = " <b><i>CHANGING!</i> (the view is no longer current!)</b>";
    } else {
        changing = "";
    }
    pw.println("<p class=\"statline ui-state-highlight\">Topology" + changing + "</p>");
    pw.println("<div class=\"ui-widget-header ui-corner-top buttonGroup\" style=\"height: 15px;\">");
    pw.println("<span style=\"float: left; margin-left: 1em;\">Instances in the topology</span>");
    pw.println("</div>");
    pw.println("<table class=\"adapters nicetable ui-widget tablesorter\">");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class=\"header ui-widget-header\">Sling id (click for properties)</th>");
    pw.println("<th class=\"header ui-widget-header\">ClusterView id</th>");
    pw.println("<th class=\"header ui-widget-header\">Local instance</th>");
    pw.println("<th class=\"header ui-widget-header\">Leader instance</th>");
    pw.println("<th class=\"header ui-widget-header\">In local cluster</th>");
    pw.println("<th class=\"header ui-widget-header\">Announced by instance</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    Set<ClusterView> clusters = topology.getClusterViews();
    ClusterView myCluster = topology.getLocalInstance().getClusterView();
    boolean odd = true;
    renderCluster(pw, myCluster, myCluster, odd, topology.isCurrent());
    for (Iterator<ClusterView> it = clusters.iterator(); it.hasNext(); ) {
        ClusterView clusterView = it.next();
        if (clusterView.equals(myCluster)) {
            // skip - I already rendered that
            continue;
        }
        odd = !odd;
        renderCluster(pw, clusterView, myCluster, odd, topology.isCurrent());
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("<br/>");
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">Connectors</p>");
    listIncomingTopologyConnectors(pw);
    listOutgoingTopologyConnectors(pw);
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">Topology Change History</p>");
    pw.println("<pre>");
    for (Iterator<String> it = topologyLog.iterator(); it.hasNext(); ) {
        String aLogEntry = it.next();
        pw.println(aLogEntry);
    }
    pw.println("</pre>");
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">Property Change History</p>");
    pw.println("<pre>");
    for (Iterator<String> it = propertyChangeLog.iterator(); it.hasNext(); ) {
        String aLogEntry = it.next();
        pw.println(aLogEntry);
    }
    pw.println("</pre>");
    pw.println("</br>");
    pw.println("<p class=\"statline ui-state-highlight\">SyncTokenService History</p>");
    pw.println("<pre>");
    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("</pre>");
    pw.println("<br/>");
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) ClusterSyncHistory(org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory)

Example 12 with ClusterView

use of org.apache.sling.discovery.ClusterView 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));
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) InstanceDescription(org.apache.sling.discovery.InstanceDescription) DiscoveryService(org.apache.sling.discovery.DiscoveryService) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) TopologyView(org.apache.sling.discovery.TopologyView) DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) Test(org.junit.Test)

Example 13 with ClusterView

use of org.apache.sling.discovery.ClusterView in project sling by apache.

the class TopologyWebConsolePlugin method handleTopologyEvent.

/**
     * keep a truncated history of the log events for information purpose (to be shown in the webconsole)
     */
@Override
public void handleTopologyEvent(final TopologyEvent event) {
    if (event.getType() == Type.PROPERTIES_CHANGED) {
        this.currentView = event.getNewView();
        Set<InstanceDescription> newInstances = event.getNewView().getInstances();
        StringBuilder sb = new StringBuilder();
        for (Iterator<InstanceDescription> it = newInstances.iterator(); it.hasNext(); ) {
            final InstanceDescription newInstanceDescription = it.next();
            InstanceDescription oldInstanceDescription = findInstance(event.getOldView(), newInstanceDescription.getSlingId());
            if (oldInstanceDescription == null) {
                logger.error("handleTopologyEvent: got a property changed but did not find instance " + newInstanceDescription + " in oldview.. event=" + event);
                addEventLog(event.getType(), event.getType().toString());
                return;
            }
            Map<String, String> oldProps = oldInstanceDescription.getProperties();
            Map<String, String> newProps = newInstanceDescription.getProperties();
            StringBuilder diff = diff(oldProps, newProps);
            if (diff.length() > 0) {
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append("on instance " + newInstanceDescription.getSlingId() + (newInstanceDescription.isLeader() ? " [isLeader]" : "") + ": " + diff);
            }
        }
        addEventLog(event.getType(), sb.toString());
    } else if (event.getType() == Type.TOPOLOGY_INIT) {
        this.currentView = event.getNewView();
        StringBuilder details = new StringBuilder();
        for (Iterator<InstanceDescription> it = event.getNewView().getInstances().iterator(); it.hasNext(); ) {
            InstanceDescription newInstance = it.next();
            if (details.length() != 0) {
                details.append(", ");
            }
            details.append(newInstance.getSlingId());
            if (newInstance.isLeader()) {
                details.append(" [isLeader]");
            }
        }
        addEventLog(event.getType(), "view: " + shortViewInfo(event.getNewView()) + ". " + details);
    } else if (event.getType() == Type.TOPOLOGY_CHANGING) {
        this.currentView = event.getOldView();
        addEventLog(event.getType(), "old view: " + shortViewInfo(event.getOldView()));
    } else {
        this.currentView = event.getNewView();
        if (event.getOldView() == null) {
            addEventLog(event.getType(), "new view: " + shortViewInfo(event.getNewView()));
        } else {
            StringBuilder details = new StringBuilder();
            for (Iterator<InstanceDescription> it = event.getNewView().getInstances().iterator(); it.hasNext(); ) {
                InstanceDescription newInstance = it.next();
                if (findInstance(event.getOldView(), newInstance.getSlingId()) == null) {
                    if (details.length() != 0) {
                        details.append(", ");
                    }
                    details.append(newInstance.getSlingId() + " joined");
                }
            }
            for (Iterator<InstanceDescription> it = event.getOldView().getInstances().iterator(); it.hasNext(); ) {
                InstanceDescription oldInstance = it.next();
                if (findInstance(event.getNewView(), oldInstance.getSlingId()) == null) {
                    if (details.length() != 0) {
                        details.append(", ");
                    }
                    details.append(oldInstance.getSlingId() + " left");
                }
            }
            final InstanceDescription li = event.getNewView().getLocalInstance();
            if (li != null) {
                ClusterView clusterView = li.getClusterView();
                if (clusterView != null) {
                    final InstanceDescription leader = clusterView.getLeader();
                    if (leader != null) {
                        if (details.length() != 0) {
                            details.append(", ");
                        }
                        details.append("[isLeader: " + leader.getSlingId() + "]");
                    }
                }
            }
            addEventLog(event.getType(), "old view: " + shortViewInfo(event.getOldView()) + ", new view: " + shortViewInfo(event.getNewView()) + ". " + details);
        }
    }
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) Iterator(java.util.Iterator) InstanceDescription(org.apache.sling.discovery.InstanceDescription)

Example 14 with ClusterView

use of org.apache.sling.discovery.ClusterView in project sling by apache.

the class JobManagerConfigurationTest method createView.

private TopologyView createView() {
    final TopologyView view = Mockito.mock(TopologyView.class);
    Mockito.when(view.isCurrent()).thenReturn(true);
    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;
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) InstanceDescription(org.apache.sling.discovery.InstanceDescription) TopologyView(org.apache.sling.discovery.TopologyView)

Example 15 with ClusterView

use of org.apache.sling.discovery.ClusterView in project sling by apache.

the class TopologyWebConsolePlugin method renderOverview.

/**
     * Render the overview of the entire topology
     */
private void renderOverview(final PrintWriter pw, final TopologyView topology) {
    pw.println("<p class=\"statline ui-state-highlight\">Configuration</p>");
    pw.println("<br/>");
    pw.print("<a href=\"${appRoot}/configMgr/org.apache.sling.discovery.oak.Config\">Configure Discovery.Oak Service</a>");
    pw.println("<br/>");
    pw.println("<br/>");
    final String changing;
    if (!topology.isCurrent()) {
        changing = " <b><i>CHANGING!</i> (the view is no longer current!)</b>";
    } else {
        changing = "";
    }
    pw.println("<p class=\"statline ui-state-highlight\">Topology" + changing + "</p>");
    pw.println("<div class=\"ui-widget-header ui-corner-top buttonGroup\" style=\"height: 15px;\">");
    pw.println("<span style=\"float: left; margin-left: 1em;\">Instances in the topology</span>");
    pw.println("</div>");
    pw.println("<table class=\"adapters nicetable ui-widget tablesorter\">");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class=\"header ui-widget-header\">Sling id (click for properties)</th>");
    pw.println("<th class=\"header ui-widget-header\">ClusterView id</th>");
    pw.println("<th class=\"header ui-widget-header\">Local instance</th>");
    pw.println("<th class=\"header ui-widget-header\">Leader instance</th>");
    pw.println("<th class=\"header ui-widget-header\">In local cluster</th>");
    pw.println("<th class=\"header ui-widget-header\">Announced by instance</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    Set<ClusterView> clusters = topology.getClusterViews();
    ClusterView myCluster = topology.getLocalInstance().getClusterView();
    boolean odd = true;
    renderCluster(pw, myCluster, myCluster, odd, topology.isCurrent());
    for (Iterator<ClusterView> it = clusters.iterator(); it.hasNext(); ) {
        ClusterView clusterView = it.next();
        if (clusterView.equals(myCluster)) {
            // skip - I already rendered that
            continue;
        }
        odd = !odd;
        renderCluster(pw, clusterView, myCluster, odd, topology.isCurrent());
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("<br/>");
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">Connectors</p>");
    listIncomingTopologyConnectors(pw);
    listOutgoingTopologyConnectors(pw);
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">Topology Change History</p>");
    pw.println("<pre>");
    for (Iterator<String> it = topologyLog.iterator(); it.hasNext(); ) {
        String aLogEntry = it.next();
        pw.println(aLogEntry);
    }
    pw.println("</pre>");
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">Property Change History</p>");
    pw.println("<pre>");
    for (Iterator<String> it = propertyChangeLog.iterator(); it.hasNext(); ) {
        String aLogEntry = it.next();
        pw.println(aLogEntry);
    }
    pw.println("</pre>");
    pw.println("</br>");
    pw.println("<p class=\"statline ui-state-highlight\">Oak Discovery-Lite Descriptor History</p>");
    updateDiscoveryLiteHistory();
    pw.println("<pre>");
    for (String discoLiteHistoryEntry : discoveryLiteHistory) {
        pw.println(discoLiteHistoryEntry);
    }
    pw.println("</pre>");
    pw.println("<br/>");
    pw.println("<p class=\"statline ui-state-highlight\">ClusterSyncService History</p>");
    pw.println("<pre>");
    for (String syncHistoryEntry : clusterSyncService.getSyncHistory()) {
        pw.println(syncHistoryEntry);
    }
    pw.println("</pre>");
    pw.println("<br/>");
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView)

Aggregations

ClusterView (org.apache.sling.discovery.ClusterView)30 InstanceDescription (org.apache.sling.discovery.InstanceDescription)16 TopologyView (org.apache.sling.discovery.TopologyView)8 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)6 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)6 Test (org.junit.Test)6 Iterator (java.util.Iterator)4 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)4 AnnouncementFilter (org.apache.sling.discovery.base.connectors.announcement.AnnouncementFilter)4 HashSet (java.util.HashSet)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 JsonException (javax.json.JsonException)2 CachedAnnouncement (org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement)2 TopologyConnectorClientInformation (org.apache.sling.discovery.base.connectors.ping.TopologyConnectorClientInformation)2 LocalClusterView (org.apache.sling.discovery.commons.providers.spi.LocalClusterView)2 ClusterSyncHistory (org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory)2 Before (org.junit.Before)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1