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;
}
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;
}
}
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);
}
Aggregations