Search in sources :

Example 6 with Announcement

use of org.apache.sling.discovery.base.connectors.announcement.Announcement in project sling by apache.

the class TopologyWebConsolePlugin method renderCluster.

/**
     * Render a particular cluster (into table rows)
     */
private void renderCluster(final PrintWriter pw, final ClusterView renderCluster, final ClusterView localCluster, final boolean odd, final boolean current) {
    final Collection<Announcement> announcements = announcementRegistry.listAnnouncementsInSameCluster(localCluster);
    for (Iterator<InstanceDescription> it = renderCluster.getInstances().iterator(); it.hasNext(); ) {
        final InstanceDescription instanceDescription = it.next();
        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 String oddEven = odd ? "odd" : "even";
        if (current && (inLocalCluster || (parentAnnouncement != null))) {
            pw.println("<tr class=\"" + oddEven + " ui-state-default\">");
        } else {
            pw.println("<tr class=\"" + oddEven + " ui-state-error\">");
        }
        final boolean isLocal = instanceDescription.isLocal();
        final String slingId = instanceDescription.getSlingId();
        pw.print("<td>");
        if (isLocal) {
            pw.print("<b>");
        }
        pw.print("<a href=\"");
        pw.print(this.getLabel());
        pw.print('/');
        pw.print(slingId);
        pw.print("\">");
        pw.print(slingId);
        pw.print("</a>");
        if (isLocal) {
            pw.print("</b>");
        }
        pw.println("</td>");
        pw.println("<td>" + (instanceDescription.getClusterView() == null ? "null" : instanceDescription.getClusterView().getId()) + "</td>");
        pw.println("<td>" + (isLocal ? "<b>true</b>" : "false") + "</td>");
        pw.println("<td>" + (instanceDescription.isLeader() ? "<b>true</b>" : "false") + "</td>");
        if (inLocalCluster) {
            pw.println("<td>local</td>");
            pw.println("<td>n/a</td>");
        } else {
            pw.println("<td>remote</td>");
            if (parentAnnouncement != null) {
                pw.println("<td>" + parentAnnouncement.getOwnerId() + "</td>");
            } else {
                pw.println("<td><b>(changing)</b></td>");
            }
        }
        pw.println("</tr>");
    }
}
Also used : Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) CachedAnnouncement(org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement) InstanceDescription(org.apache.sling.discovery.InstanceDescription)

Example 7 with Announcement

use of org.apache.sling.discovery.base.connectors.announcement.Announcement 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();
    }
}
Also used : Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) CachedAnnouncement(org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map)

Example 8 with Announcement

use of org.apache.sling.discovery.base.connectors.announcement.Announcement 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 9 with Announcement

use of org.apache.sling.discovery.base.connectors.announcement.Announcement in project sling by apache.

the class SynchronizedClocksHealthCheck method execute.

@Override
public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();
    resultLog.debug("Checking cluster internal clocks");
    try {
        final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName n = new ObjectName(DOCUMENT_NODE_STORE_MBEAN);
        Set<ObjectName> names = jmxServer.queryNames(n, null);
        if (names.size() == 0) {
            resultLog.info("Intra-cluster test n/a (No DocumentNodeStore MBean found)");
        } else {
            ObjectName firstName = names.iterator().next();
            final Object value = jmxServer.invoke(firstName, TIME_DIFF_METHOD_NAME, new Object[0], new String[0]);
            logger.debug("{} returns {}", new Object[] { firstName, TIME_DIFF_METHOD_NAME, value });
            resultLog.debug("{} returns {}", firstName, TIME_DIFF_METHOD_NAME, value);
            if (value != null && (value instanceof Long)) {
                Long diffMillis = (Long) value;
                if (Math.abs(diffMillis) >= INTRA_CLUSTER_HIGH_WATER_MARK) {
                    logger.warn("execute: clocks in local cluster out of sync by {}ms " + "which is equal or higher than the high-water mark of {}ms.", diffMillis, INTRA_CLUSTER_HIGH_WATER_MARK);
                    resultLog.critical("Clocks heavily out of sync in local cluster: " + "time difference of this VM with DocumentStore server: " + "{}ms is equal or larger than high-water mark of {}ms", diffMillis, INTRA_CLUSTER_HIGH_WATER_MARK);
                } else if (Math.abs(diffMillis) >= INTRA_CLUSTER_LOW_WATER_MARK) {
                    logger.warn("execute: clocks in local cluster out of sync by {}ms" + "ms which is equal or higher than the low-water mark of {}ms.", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
                    resultLog.warn("Clocks noticeably out of sync in local cluster: " + "time difference of this VM with DocumentStore server: " + "{}ms is equal or larger than low-water mark of {}ms", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
                } else {
                    logger.debug("execute: clocks in local cluster in sync. diff is {}ms" + "ms which is within low-water mark of {}ms.", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
                    resultLog.info("Clocks in sync in local cluster: time difference of this VM with DocumentStore server: " + "{}ms is within low-water mark of {}ms", diffMillis, INTRA_CLUSTER_LOW_WATER_MARK);
                }
            }
        }
    } catch (final Exception e) {
        logger.warn("execute: {}, JMX method {} invocation failed: {}", new Object[] { DOCUMENT_NODE_STORE_MBEAN, TIME_DIFF_METHOD_NAME, e });
        resultLog.healthCheckError("{}, JMX method {} invocation failed: {}", DOCUMENT_NODE_STORE_MBEAN, TIME_DIFF_METHOD_NAME, e);
    }
    final String slingId = settingsService == null ? "n/a" : settingsService.getSlingId();
    if (announcementRegistry == null) {
        logger.warn("execute: no announcementRegistry ({}) set", announcementRegistry);
        resultLog.warn("Cannot determine topology clocks since no announcementRegistry ({}) set", announcementRegistry);
    } else {
        final Collection<Announcement> localAnnouncements = announcementRegistry.listLocalAnnouncements();
        if (localAnnouncements.isEmpty()) {
            logger.info("execute: no topology connectors connected to local instance.");
            resultLog.info("No topology connectors connected to local instance.");
        }
        for (Announcement ann : localAnnouncements) {
            final String peerSlingId = ann.getOwnerId();
            final long originallyCreatedAt = ann.getOriginallyCreatedAt();
            final long receivedAt = ann.getReceivedAt();
            long diffMillis = Math.abs(originallyCreatedAt - receivedAt);
            if (Math.abs(diffMillis) >= INTER_CLUSTER_HIGH_WATER_MARK) {
                logger.warn("execute: clocks between local instance (slingId: {}) and remote instance (slingId: {}) out of sync by {}ms" + "ms which is equal or higher than the high-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
                resultLog.critical("Clocks heavily out of sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "by {}ms which is equal or larger than high-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
            } else if (Math.abs(diffMillis) >= INTER_CLUSTER_LOW_WATER_MARK) {
                logger.warn("execute: clocks out of sync between local instance (slingId: {}) and remote instance (slingId: {}) by {}ms " + "ms which is equal or higher than the low-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
                resultLog.warn("Clocks noticeably out of sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "by {}ms which is equal or larger than low-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
            } else {
                logger.debug("execute: clocks in sync between local instance (slingId: {}) and remote instance (slingId: {}). " + "diff is {}ms which is within low-water mark of {}ms.", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
                resultLog.info("Clocks in sync between local instance (slingId: {}) and remote instance (slingId: {}): " + "diff is {}ms which is within low-water mark of {}ms", new Object[] { slingId, peerSlingId, diffMillis, INTER_CLUSTER_HIGH_WATER_MARK });
            }
        }
    }
    return new Result(resultLog);
}
Also used : Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) FormattingResultLog(org.apache.sling.hc.util.FormattingResultLog) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Result(org.apache.sling.hc.api.Result)

Example 10 with Announcement

use of org.apache.sling.discovery.base.connectors.announcement.Announcement in project sling by apache.

the class TopologyWebConsolePlugin method renderCluster.

/**
     * Render a particular cluster (into table rows)
     */
private void renderCluster(final PrintWriter pw, final ClusterView renderCluster, final ClusterView localCluster, final boolean odd, final boolean current) {
    final Collection<Announcement> announcements = announcementRegistry.listAnnouncementsInSameCluster(localCluster);
    for (Iterator<InstanceDescription> it = renderCluster.getInstances().iterator(); it.hasNext(); ) {
        final InstanceDescription instanceDescription = it.next();
        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 String oddEven = odd ? "odd" : "even";
        if (current && (inLocalCluster || (parentAnnouncement != null))) {
            pw.println("<tr class=\"" + oddEven + " ui-state-default\">");
        } else {
            pw.println("<tr class=\"" + oddEven + " ui-state-error\">");
        }
        final boolean isLocal = instanceDescription.isLocal();
        final String slingId = instanceDescription.getSlingId();
        pw.print("<td>");
        if (isLocal) {
            pw.print("<b>");
        }
        pw.print("<a href=\"");
        pw.print(this.getLabel());
        pw.print('/');
        pw.print(slingId);
        pw.print("\">");
        pw.print(slingId);
        pw.print("</a>");
        if (isLocal) {
            pw.print("</b>");
        }
        pw.println("</td>");
        pw.println("<td>" + (instanceDescription.getClusterView() == null ? "null" : instanceDescription.getClusterView().getId()) + "</td>");
        pw.println("<td>" + (isLocal ? "<b>true</b>" : "false") + "</td>");
        pw.println("<td>" + (instanceDescription.isLeader() ? "<b>true</b>" : "false") + "</td>");
        if (inLocalCluster) {
            pw.println("<td>local</td>");
            pw.println("<td>n/a</td>");
        } else {
            pw.println("<td>remote</td>");
            if (parentAnnouncement != null) {
                pw.println("<td>" + parentAnnouncement.getOwnerId() + "</td>");
            } else {
                pw.println("<td><b>(changing)</b></td>");
            }
        }
        pw.println("</tr>");
    }
}
Also used : Announcement(org.apache.sling.discovery.base.connectors.announcement.Announcement) CachedAnnouncement(org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement) InstanceDescription(org.apache.sling.discovery.InstanceDescription)

Aggregations

Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)15 CachedAnnouncement (org.apache.sling.discovery.base.connectors.announcement.CachedAnnouncement)8 InstanceDescription (org.apache.sling.discovery.InstanceDescription)7 ClusterView (org.apache.sling.discovery.ClusterView)6 AnnouncementFilter (org.apache.sling.discovery.base.connectors.announcement.AnnouncementFilter)4 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 JsonException (javax.json.JsonException)2 TopologyView (org.apache.sling.discovery.TopologyView)2 TopologyConnectorClientInformation (org.apache.sling.discovery.base.connectors.ping.TopologyConnectorClientInformation)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Header (org.apache.http.Header)1 AuthScope (org.apache.http.auth.AuthScope)1