Search in sources :

Example 1 with DefaultTopologyView

use of org.apache.sling.discovery.base.commons.DefaultTopologyView in project sling by apache.

the class TopologyHelper method createTopologyView.

public static DefaultTopologyView createTopologyView(String clusterViewId, String slingId) {
    DefaultTopologyView t = new DefaultTopologyView();
    DefaultClusterView c = new DefaultClusterView(clusterViewId);
    DefaultInstanceDescription i = new DefaultInstanceDescription(c, true, false, slingId, new HashMap<String, String>());
    Collection<InstanceDescription> instances = new LinkedList<InstanceDescription>();
    instances.add(i);
    t.addInstances(instances);
    return t;
}
Also used : DefaultTopologyView(org.apache.sling.discovery.base.commons.DefaultTopologyView) 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) LinkedList(java.util.LinkedList)

Example 2 with DefaultTopologyView

use of org.apache.sling.discovery.base.commons.DefaultTopologyView in project sling by apache.

the class TopologyHelper method cloneTopologyView.

public static DefaultTopologyView cloneTopologyView(DefaultTopologyView view, String newLeader) throws NoSuchFieldException {
    final DefaultTopologyView clone = cloneTopologyView(view);
    final DefaultClusterView cluster = (DefaultClusterView) clone.getClusterViews().iterator().next();
    for (Iterator it = cluster.getInstances().iterator(); it.hasNext(); ) {
        DefaultInstanceDescription id = (DefaultInstanceDescription) it.next();
        PrivateAccessor.setField(id, "isLeader", id.getSlingId().equals(newLeader));
    }
    return clone;
}
Also used : DefaultTopologyView(org.apache.sling.discovery.base.commons.DefaultTopologyView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) Iterator(java.util.Iterator) DefaultInstanceDescription(org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)

Example 3 with DefaultTopologyView

use of org.apache.sling.discovery.base.commons.DefaultTopologyView in project sling by apache.

the class TopologyHelper method cloneTopologyView.

public static DefaultTopologyView cloneTopologyView(DefaultTopologyView original) {
    DefaultTopologyView t = new DefaultTopologyView();
    Iterator<ClusterView> it = original.getClusterViews().iterator();
    while (it.hasNext()) {
        DefaultClusterView c = (DefaultClusterView) it.next();
        t.addInstances(clone(c).getInstances());
    }
    return t;
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) DefaultTopologyView(org.apache.sling.discovery.base.commons.DefaultTopologyView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView)

Example 4 with DefaultTopologyView

use of org.apache.sling.discovery.base.commons.DefaultTopologyView in project sling by apache.

the class OakDiscoveryService method checkForTopologyChange.

/**
     * Check the current topology for any potential change
     */
public void checkForTopologyChange() {
    viewStateManagerLock.lock();
    try {
        if (!activated) {
            logger.debug("checkForTopologyChange: not yet activated, ignoring");
            return;
        }
        DefaultTopologyView t = (DefaultTopologyView) getTopology();
        if (t.isCurrent()) {
            // if we have a valid view, let the viewStateManager do the
            // comparison and sending of an event, if necessary
            viewStateManager.handleNewView(t);
            setOldView(t);
        } else {
            // if we don't have a view, then we might have to send
            // a CHANGING event, let that be decided by the viewStateManager as well
            viewStateManager.handleChanging();
        }
    } finally {
        if (viewStateManagerLock != null) {
            viewStateManagerLock.unlock();
        }
    }
}
Also used : DefaultTopologyView(org.apache.sling.discovery.base.commons.DefaultTopologyView)

Example 5 with DefaultTopologyView

use of org.apache.sling.discovery.base.commons.DefaultTopologyView 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

DefaultTopologyView (org.apache.sling.discovery.base.commons.DefaultTopologyView)7 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)5 DefaultInstanceDescription (org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)4 InstanceDescription (org.apache.sling.discovery.InstanceDescription)3 URL (java.net.URL)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Activate (org.apache.felix.scr.annotations.Activate)2 LoginException (org.apache.sling.api.resource.LoginException)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 TopologyEventListener (org.apache.sling.discovery.TopologyEventListener)2 ClusterSyncService (org.apache.sling.discovery.commons.providers.spi.ClusterSyncService)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 ClusterView (org.apache.sling.discovery.ClusterView)1 UndefinedClusterViewException (org.apache.sling.discovery.base.commons.UndefinedClusterViewException)1 ClusterSyncHistory (org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncHistory)1 ClusterSyncServiceChain (org.apache.sling.discovery.commons.providers.spi.base.ClusterSyncServiceChain)1