Search in sources :

Example 1 with LeadershipEvent

use of org.onosproject.cluster.LeadershipEvent in project onos by opennetworkinglab.

the class SimpleLeadershipManager method runForLeadership.

@Override
public Leadership runForLeadership(String path) {
    elections.put(path, true);
    Leadership leadership = new Leadership(path, new Leader(localNodeId, 0, 0), Arrays.asList(localNodeId));
    for (LeadershipEventListener listener : listeners) {
        listener.event(new LeadershipEvent(Type.LEADER_AND_CANDIDATES_CHANGED, leadership));
    }
    return leadership;
}
Also used : LeadershipEvent(org.onosproject.cluster.LeadershipEvent) Leadership(org.onosproject.cluster.Leadership) Leader(org.onosproject.cluster.Leader) LeadershipEventListener(org.onosproject.cluster.LeadershipEventListener)

Example 2 with LeadershipEvent

use of org.onosproject.cluster.LeadershipEvent in project onos by opennetworkinglab.

the class DistributedLeadershipStore method handleStatusChange.

private void handleStatusChange(Status status) {
    // Notify mastership Service of disconnect and reconnect
    if (status == Status.ACTIVE) {
        // Service Restored
        localLeaderCache.forEach((topic, leadership) -> leaderElector.run(topic, localNodeId));
        leaderElector.getLeaderships().forEach((topic, leadership) -> notifyDelegate(new LeadershipEvent(LeadershipEvent.Type.SERVICE_RESTORED, new Leadership(parseTopic(leadership.topic()), leadership.leader(), leadership.candidates()))));
    } else if (status == Status.SUSPENDED) {
        // Service Suspended
        localLeaderCache.forEach((topic, leadership) -> notifyDelegate(new LeadershipEvent(LeadershipEvent.Type.SERVICE_DISRUPTED, new Leadership(parseTopic(leadership.topic()), leadership.leader(), leadership.candidates()))));
    } else {
        // Should be only inactive state
        return;
    }
}
Also used : LeadershipEvent(org.onosproject.cluster.LeadershipEvent) ComponentContext(org.osgi.service.component.ComponentContext) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) CoordinationService(org.onosproject.store.service.CoordinationService) LeadershipStore(org.onosproject.cluster.LeadershipStore) Leadership(org.onosproject.cluster.Leadership) Component(org.osgi.service.component.annotations.Component) VersionService(org.onosproject.core.VersionService) Map(java.util.Map) Version(org.onosproject.core.Version) MANDATORY(org.osgi.service.component.annotations.ReferenceCardinality.MANDATORY) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) NodeId(org.onosproject.cluster.NodeId) UpgradeEventListener(org.onosproject.upgrade.UpgradeEventListener) Tools.get(org.onlab.util.Tools.get) UpgradeService(org.onosproject.upgrade.UpgradeService) Logger(org.slf4j.Logger) Change(org.onosproject.event.Change) Deactivate(org.osgi.service.component.annotations.Deactivate) OsgiPropertyConstants(org.onosproject.store.OsgiPropertyConstants) LeadershipStoreDelegate(org.onosproject.cluster.LeadershipStoreDelegate) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Status(org.onosproject.store.service.DistributedPrimitive.Status) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) UpgradeEvent(org.onosproject.upgrade.UpgradeEvent) LeaderElector(org.onosproject.store.service.LeaderElector) AbstractStore(org.onosproject.store.AbstractStore) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ClusterService(org.onosproject.cluster.ClusterService) LeadershipEvent(org.onosproject.cluster.LeadershipEvent) Reference(org.osgi.service.component.annotations.Reference) Dictionary(java.util.Dictionary) Leadership(org.onosproject.cluster.Leadership)

Example 3 with LeadershipEvent

use of org.onosproject.cluster.LeadershipEvent in project onos by opennetworkinglab.

the class VplsOperationManagerTest method testLeadershipEvent.

/**
 * Sends leadership event to the manager and checks if the manager is
 * leader or not.
 */
@Test
public void testLeadershipEvent() {
    vplsOperationManager.isLeader = false;
    vplsOperationManager.localNodeId = NODE_ID_1;
    // leader changed to self
    Leader leader = new Leader(NODE_ID_1, 0, 0);
    Leadership leadership = new Leadership(APP_NAME, leader, ImmutableList.of());
    LeadershipEvent event = new LeadershipEvent(LeadershipEvent.Type.LEADER_CHANGED, leadership);
    ((TestLeadershipService) vplsOperationManager.leadershipService).sendEvent(event);
    assertTrue(vplsOperationManager.isLeader);
    // leader changed to other
    leader = new Leader(NODE_ID_2, 0, 0);
    leadership = new Leadership(APP_NAME, leader, ImmutableList.of());
    event = new LeadershipEvent(LeadershipEvent.Type.LEADER_CHANGED, leadership);
    ((TestLeadershipService) vplsOperationManager.leadershipService).sendEvent(event);
    assertFalse(vplsOperationManager.isLeader);
}
Also used : LeadershipEvent(org.onosproject.cluster.LeadershipEvent) Leadership(org.onosproject.cluster.Leadership) Leader(org.onosproject.cluster.Leader) Test(org.junit.Test)

Aggregations

Leadership (org.onosproject.cluster.Leadership)3 LeadershipEvent (org.onosproject.cluster.LeadershipEvent)3 Leader (org.onosproject.cluster.Leader)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Maps (com.google.common.collect.Maps)1 Dictionary (java.util.Dictionary)1 Map (java.util.Map)1 Objects (java.util.Objects)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 Tools.get (org.onlab.util.Tools.get)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1 ClusterService (org.onosproject.cluster.ClusterService)1 LeadershipEventListener (org.onosproject.cluster.LeadershipEventListener)1 LeadershipStore (org.onosproject.cluster.LeadershipStore)1 LeadershipStoreDelegate (org.onosproject.cluster.LeadershipStoreDelegate)1