Search in sources :

Example 21 with ClusterView

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

the class Announcement method asJSON.

/** convert an instance description into a json object **/
private static JsonObject asJSON(final InstanceDescription instanceDescription) {
    JsonObjectBuilder obj = Json.createObjectBuilder();
    obj.add("slingId", instanceDescription.getSlingId());
    obj.add("isLeader", instanceDescription.isLeader());
    ClusterView cluster = instanceDescription.getClusterView();
    if (cluster != null) {
        obj.add("cluster", cluster.getId());
    }
    JsonObjectBuilder propertiesObj = Json.createObjectBuilder();
    Map<String, String> propertiesMap = instanceDescription.getProperties();
    for (Iterator<Entry<String, String>> it = propertiesMap.entrySet().iterator(); it.hasNext(); ) {
        Entry<String, String> entry = it.next();
        propertiesObj.add(entry.getKey(), entry.getValue());
    }
    obj.add("properties", propertiesObj);
    return obj.build();
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) Entry(java.util.Map.Entry) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 22 with ClusterView

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

the class LargeTopologyWithHubTest method setup.

@Before
public void setup() throws Throwable {
    instances = new LinkedList<VirtualInstance>();
    // 1 hour should be enough, really
    final int defaultHeartbeatTimeout = 3600;
    final int heartbeatTimeout = TimeoutsProvider.getInstance().getTimeout(defaultHeartbeatTimeout);
    VirtualInstanceBuilder hubBuilder = newBuilder().newRepository("/var/discovery/impl/", true).setDebugName("hub").setConnectorPingInterval(5).setConnectorPingTimeout(heartbeatTimeout);
    hub = hubBuilder.build();
    instances.add(hub);
    hub.getConfig().setViewCheckTimeout(heartbeatTimeout);
    //        hub.installVotingOnHeartbeatHandler();
    hub.heartbeatsAndCheckView();
    hub.heartbeatsAndCheckView();
    assertNotNull(hub.getClusterViewService().getLocalClusterView());
    hub.startViewChecker(1);
    hub.dumpRepo();
    slingIds = new LinkedList<String>();
    slingIds.add(hub.getSlingId());
    logger.info("setUp: using heartbeatTimeout of " + heartbeatTimeout + "sec " + "(default: " + defaultHeartbeatTimeout + ")");
    for (int i = 0; i < TEST_SIZE; i++) {
        logger.info("setUp: creating instance" + i);
        VirtualInstanceBuilder builder2 = newBuilder().newRepository("/var/discovery/impl/", false).setDebugName("instance" + i).setConnectorPingInterval(5).setConnectorPingTimeout(heartbeatTimeout);
        VirtualInstance instance = builder2.build();
        instances.add(instance);
        instance.getConfig().setViewCheckTimeout(heartbeatTimeout);
        //            instance.installVotingOnHeartbeatHandler();
        instance.heartbeatsAndCheckView();
        instance.heartbeatsAndCheckView();
        ClusterView clusterView = instance.getClusterViewService().getLocalClusterView();
        assertNotNull(clusterView);
        new VirtualConnector(instance, hub);
        slingIds.add(instance.getSlingId());
    }
}
Also used : VirtualInstanceBuilder(org.apache.sling.discovery.base.its.setup.VirtualInstanceBuilder) ClusterView(org.apache.sling.discovery.ClusterView) VirtualConnector(org.apache.sling.discovery.base.its.setup.VirtualConnector) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) Before(org.junit.Before)

Example 23 with ClusterView

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

the class AnnouncementRegistryImplTest method doTestCluster.

private void doTestCluster(boolean includeFinalExpiryCheck) throws Exception {
    ClusterView cluster1 = createCluster(2);
    ClusterView cluster2 = createCluster(4);
    ClusterView cluster3 = createCluster(7);
    Announcement ann1 = createAnnouncement(cluster1, 1, true);
    Announcement ann2 = createAnnouncement(cluster2, 2, true);
    Announcement ann3 = createAnnouncement(cluster3, 3, false);
    final String instance1 = UUID.randomUUID().toString();
    final String instance2 = UUID.randomUUID().toString();
    final String instance3 = UUID.randomUUID().toString();
    ClusterView myCluster = createCluster(instance1, instance2, instance3);
    AnnouncementRegistryImpl registry1 = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(instance1), config);
    AnnouncementRegistryImpl registry2 = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(instance2), config);
    AnnouncementRegistryImpl registry3 = AnnouncementRegistryImpl.testConstructorAndActivate(resourceResolverFactory, new DummySlingSettingsService(instance3), config);
    assertTrue(registry1.registerAnnouncement(ann1) != -1);
    assertTrue(registry2.registerAnnouncement(ann2) != -1);
    assertTrue(registry3.registerAnnouncement(ann3) != -1);
    assertTrue(registry1.hasActiveAnnouncement(cluster1.getInstances().get(1).getSlingId()));
    assertTrue(registry2.hasActiveAnnouncement(cluster2.getInstances().get(2).getSlingId()));
    assertTrue(registry3.hasActiveAnnouncement(cluster3.getInstances().get(3).getSlingId()));
    assertEquals(3, registry1.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry1.listLocalAnnouncements().size());
    assertEquals(0, registry1.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry1, myCluster, 4, 16);
    assertEquals(3, registry2.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry2.listLocalAnnouncements().size());
    assertEquals(0, registry2.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry2, myCluster, 4, 16);
    assertEquals(3, registry3.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry3.listLocalAnnouncements().size());
    assertEquals(1, registry3.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry3, myCluster, 4, 16);
    myCluster = createCluster(instance1, instance2);
    VirtualInstanceHelper.dumpRepo(resourceResolverFactory);
    assertEquals(2, registry1.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry1.listLocalAnnouncements().size());
    assertEquals(0, registry1.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry1, myCluster, 3, 8);
    assertEquals(2, registry2.listAnnouncementsInSameCluster(myCluster).size());
    assertEquals(1, registry2.listLocalAnnouncements().size());
    assertEquals(0, registry2.listLocalIncomingAnnouncements().size());
    assertAnnouncements(registry2, myCluster, 3, 8);
    if (includeFinalExpiryCheck) {
        Thread.sleep(10500);
        assertAnnouncements(registry1, myCluster, 3, 8);
        assertAnnouncements(registry2, myCluster, 3, 8);
        registry1.checkExpiredAnnouncements();
        registry2.checkExpiredAnnouncements();
        assertAnnouncements(registry1, myCluster, 1, 2);
        assertAnnouncements(registry2, myCluster, 1, 2);
    }
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)

Example 24 with ClusterView

use of org.apache.sling.discovery.ClusterView 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 25 with ClusterView

use of org.apache.sling.discovery.ClusterView 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);
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) InstanceDescription(org.apache.sling.discovery.InstanceDescription) TopologyView(org.apache.sling.discovery.TopologyView) Before(org.junit.Before)

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