Search in sources :

Example 1 with Leader

use of org.onosproject.cluster.Leader 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 Leader

use of org.onosproject.cluster.Leader 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

Leader (org.onosproject.cluster.Leader)2 Leadership (org.onosproject.cluster.Leadership)2 LeadershipEvent (org.onosproject.cluster.LeadershipEvent)2 Test (org.junit.Test)1 LeadershipEventListener (org.onosproject.cluster.LeadershipEventListener)1