Search in sources :

Example 1 with ClusterSyncHistory

use of org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory 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 2 with ClusterSyncHistory

use of org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory 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();
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) CachedAnnouncement(org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement) Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) CachedAnnouncement(org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement) ClusterSyncHistory(org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory) TopologyConnectorClientInformation(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorClientInformation) TopologyView(org.apache.sling.discovery.TopologyView)

Example 3 with ClusterSyncHistory

use of org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory in project sling by apache.

the class OakDiscoveryService method activate.

/**
     * Activate this service
     */
@Activate
protected void activate(final BundleContext bundleContext) {
    logger.debug("OakDiscoveryService activating...");
    if (settingsService == null) {
        throw new IllegalStateException("settingsService not found");
    }
    if (oakViewChecker == null) {
        throw new IllegalStateException("heartbeatHandler not found");
    }
    slingId = settingsService.getSlingId();
    ClusterSyncService consistencyService;
    if (config.getSyncTokenEnabled()) {
        //TODO: ConsistencyHistory is implemented a little bit hacky ..
        ClusterSyncHistory consistencyHistory = new ClusterSyncHistory();
        oakBacklogClusterSyncService.setConsistencyHistory(consistencyHistory);
        syncTokenService.setConsistencyHistory(consistencyHistory);
        consistencyService = new ClusterSyncServiceChain(oakBacklogClusterSyncService, syncTokenService);
    } else {
        consistencyService = oakBacklogClusterSyncService;
    }
    viewStateManager = ViewStateManagerFactory.newViewStateManager(viewStateManagerLock, consistencyService);
    if (config.getMinEventDelay() > 0) {
        viewStateManager.installMinEventDelayHandler(this, scheduler, config.getMinEventDelay());
    }
    final String isolatedClusterId = UUID.randomUUID().toString();
    {
        // create a pre-voting/isolated topologyView which would be used
        // until the first voting has finished.
        // this way for the single-instance case the clusterId can
        // remain the same between a getTopology() that is invoked before
        // the first TOPOLOGY_INIT and afterwards
        DefaultClusterView isolatedCluster = new DefaultClusterView(isolatedClusterId);
        Map<String, String> emptyProperties = new HashMap<String, String>();
        DefaultInstanceDescription isolatedInstance = new DefaultInstanceDescription(isolatedCluster, true, true, slingId, emptyProperties);
        Collection<InstanceDescription> col = new ArrayList<InstanceDescription>();
        col.add(isolatedInstance);
        final DefaultTopologyView topology = new DefaultTopologyView();
        topology.addInstances(col);
        topology.setNotCurrent();
        setOldView(topology);
    }
    setOldView((DefaultTopologyView) getTopology());
    getOldView().setNotCurrent();
    // make sure the first heartbeat is issued as soon as possible - which
    // is right after this service starts. since the two (discoveryservice
    // and heartbeatHandler need to know each other, the discoveryservice
    // is passed on to the heartbeatHandler in this initialize call).
    oakViewChecker.initialize(this);
    viewStateManagerLock.lock();
    try {
        viewStateManager.handleActivated();
        doUpdateProperties();
        DefaultTopologyView newView = (DefaultTopologyView) getTopology();
        if (newView.isCurrent()) {
            viewStateManager.handleNewView(newView);
        } else {
            // SLING-3750: just issue a log.info about the delaying
            logger.info("activate: this instance is in isolated mode and must yet finish voting before it can send out TOPOLOGY_INIT.");
        }
        activated = true;
        setOldView(newView);
        // bind them to the viewstatemanager too
        for (TopologyEventListener listener : pendingListeners) {
            viewStateManager.bind(listener);
        }
        pendingListeners.clear();
        viewStateManager.bind(changePropagationListener);
    } finally {
        if (viewStateManagerLock != null) {
            viewStateManagerLock.unlock();
        }
    }
    URL[] topologyConnectorURLs = config.getTopologyConnectorURLs();
    if (topologyConnectorURLs != null) {
        for (int i = 0; i < topologyConnectorURLs.length; i++) {
            final URL aURL = topologyConnectorURLs[i];
            if (aURL != null) {
                try {
                    logger.info("activate: registering outgoing topology connector to " + aURL);
                    connectorRegistry.registerOutgoingConnector(clusterViewService, aURL);
                } catch (final Exception e) {
                    logger.info("activate: could not register url: " + aURL + " due to: " + e, e);
                }
            }
        }
    }
    logger.debug("OakDiscoveryService activated.");
}
Also used : DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) URL(java.net.URL) PersistenceException(org.apache.sling.api.resource.PersistenceException) LoginException(org.apache.sling.api.resource.LoginException) ClusterSyncHistory(org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory) DefaultTopologyView(org.apache.sling.discovery.base.commons.DefaultTopologyView) ClusterSyncServiceChain(org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncServiceChain) ClusterSyncService(org.apache.sling.discovery.commons.providers.spi.ClusterSyncService) OakBacklogClusterSyncService(org.apache.sling.discovery.commons.providers.spi.base.OakBacklogClusterSyncService) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) Collection(java.util.Collection) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) HashMap(java.util.HashMap) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

ClusterSyncHistory (org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory)3 ClusterView (org.apache.sling.discovery.ClusterView)2 URL (java.net.URL)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Activate (org.apache.felix.scr.annotations.Activate)1 LoginException (org.apache.sling.api.resource.LoginException)1 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)1 PersistenceException (org.apache.sling.api.resource.PersistenceException)1 InstanceDescription (org.apache.sling.discovery.InstanceDescription)1 TopologyEventListener (org.apache.sling.discovery.TopologyEventListener)1 TopologyView (org.apache.sling.discovery.TopologyView)1 DefaultTopologyView (org.apache.sling.discovery.base.commons.DefaultTopologyView)1 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)1 CachedAnnouncement (org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement)1 TopologyConnectorClientInformation (org.apache.sling.discovery.base.connectors.ping.TopologyConnectorClientInformation)1 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)1 DefaultInstanceDescription (org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)1 ClusterSyncService (org.apache.sling.discovery.commons.providers.spi.ClusterSyncService)1