Search in sources :

Example 56 with InstanceDescription

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

the class ViewStateManagerImpl method handleNewView.

/* (non-Javadoc)
     * @see org.apache.sling.discovery.commons.providers.impl.ViewStateManager#handleNewView(org.apache.sling.discovery.commons.providers.BaseTopologyView)
     */
@Override
public void handleNewView(final BaseTopologyView newView) {
    logger.trace("handleNewView: start, newView={}", newView);
    if (newView == null) {
        throw new IllegalArgumentException("newView must not be null");
    }
    if (!newView.isCurrent()) {
        logger.debug("handleNewView: newView is not current - calling handleChanging.");
        handleChanging();
        // false;
        return;
    }
    // paranoia-testing:
    InstanceDescription localInstance = newView.getLocalInstance();
    if (localInstance == null) {
        throw new IllegalStateException("newView does not contain the local instance - hence cannot be current");
    }
    if (!localInstance.isLocal()) {
        throw new IllegalStateException("newView's local instance is not isLocal - very unexpected - hence cannot be current");
    }
    // cancel any potentially ongoing sync
    if (consistencyService != null) {
        consistencyService.cancelSync();
    }
    logger.debug("handleNewView: newView is current, so trying with minEventDelayHandler...");
    if (minEventDelayHandler != null) {
        if (minEventDelayHandler.handlesNewView(newView)) {
            // true;
            return;
        } else {
            logger.debug("handleNewView: event delaying not applicable this time, invoking hanldeNewViewNonDelayed next.");
        }
    } else {
        logger.debug("handleNewView: minEventDelayHandler not set, invoking hanldeNewViewNonDelayed...");
    }
    handleNewViewNonDelayed(newView);
}
Also used : InstanceDescription(org.apache.sling.discovery.InstanceDescription)

Example 57 with InstanceDescription

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

the class TopologyHelper method clone.

public static DefaultClusterView clone(DefaultClusterView original) {
    DefaultClusterView c = new DefaultClusterView(original.getId());
    Iterator<InstanceDescription> it = original.getInstances().iterator();
    while (it.hasNext()) {
        DefaultInstanceDescription id = (DefaultInstanceDescription) it.next();
        c.addInstanceDescription(cloneWOClusterView(id));
    }
    return c;
}
Also used : DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) InstanceDescription(org.apache.sling.discovery.InstanceDescription) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)

Example 58 with InstanceDescription

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

the class AbstractSingleInstanceTest method testGetters.

@Test
public void testGetters() throws UndefinedClusterViewException, InterruptedException {
    logger.info("testGetters: start");
    assertNotNull(instance);
    logger.info("sling id=" + instance.getSlingId());
    try {
        instance.getClusterViewService().getLocalClusterView();
        // SLING-5030
        fail("should complain");
    } catch (UndefinedClusterViewException e) {
    // ok
    }
    instance.heartbeatsAndCheckView();
    // wait 4000ms for the vote to happen
    Thread.sleep(4000);
    assertNotNull(instance.getClusterViewService().getLocalClusterView());
    ClusterView cv = instance.getClusterViewService().getLocalClusterView();
    logger.info("cluster view: id=" + cv.getId());
    assertNotNull(cv.getId());
    assertNotSame(cv.getId(), "");
    List<InstanceDescription> instances = cv.getInstances();
    assertNotNull(instances);
    assertTrue(instances.size() == 1);
    InstanceDescription myInstance = instances.get(0);
    assertNotNull(myInstance);
    assertTrue(myInstance.getClusterView() == cv);
    logger.info("instance id: " + myInstance.getSlingId());
    assertEquals(instance.getSlingId(), myInstance.getSlingId());
    Map<String, String> properties = myInstance.getProperties();
    assertNotNull(properties);
    assertNull(myInstance.getProperty("foo"));
    assertTrue(myInstance.isLeader());
    assertTrue(myInstance.isLocal());
    logger.info("testGetters: end");
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) UndefinedClusterViewException(org.apache.sling.discovery.base.commons.UndefinedClusterViewException) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Test(org.junit.Test)

Example 59 with InstanceDescription

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

the class InstancesDiffTest method testIsInClusterView.

@Test
public void testIsInClusterView() throws Exception {
    ClusterView clusterView = clusterView("viewId");
    Collection<InstanceDescription> instances = new InstancesDiff(Arrays.asList(new Instance("one", true, false, Collections.<String, String>emptyMap(), "otherView"), new Instance("two", false, true, Collections.<String, String>emptyMap(), "viewId")), empty()).all(true).isInClusterView(clusterView).get();
    TestCase.assertEquals(1, instances.size());
    TestCase.assertEquals("two", instances.iterator().next().getSlingId());
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Test(org.junit.Test)

Aggregations

InstanceDescription (org.apache.sling.discovery.InstanceDescription)59 ClusterView (org.apache.sling.discovery.ClusterView)16 DefaultInstanceDescription (org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)11 Map (java.util.Map)10 PersistenceException (org.apache.sling.api.resource.PersistenceException)10 TopologyView (org.apache.sling.discovery.TopologyView)9 HashMap (java.util.HashMap)8 LoginException (org.apache.sling.api.resource.LoginException)8 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)8 Test (org.junit.Test)8 Announcement (org.apache.sling.discovery.base.connectors.announcement.Announcement)7 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)6 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)6 HashSet (java.util.HashSet)5 Resource (org.apache.sling.api.resource.Resource)5 ValueMap (org.apache.sling.api.resource.ValueMap)5 LocalClusterView (org.apache.sling.discovery.commons.providers.spi.LocalClusterView)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 LinkedList (java.util.LinkedList)4