use of org.onosproject.cluster.Leadership in project onos by opennetworkinglab.
the class ConsistentVirtualDeviceMastershipStore method getRole.
@Override
public MastershipRole getRole(NetworkId networkId, NodeId nodeId, DeviceId deviceId) {
checkArgument(networkId != null, NETWORK_ID_NULL);
checkArgument(nodeId != null, NODE_ID_NULL);
checkArgument(deviceId != null, DEVICE_ID_NULL);
String leadershipTopic = createDeviceMastershipTopic(networkId, deviceId);
Leadership leadership = leadershipService.getLeadership(leadershipTopic);
NodeId leader = leadership == null ? null : leadership.leaderNodeId();
List<NodeId> candidates = leadership == null ? ImmutableList.of() : ImmutableList.copyOf(leadership.candidates());
return Objects.equal(nodeId, leader) ? MastershipRole.MASTER : candidates.contains(nodeId) ? MastershipRole.STANDBY : MastershipRole.NONE;
}
use of org.onosproject.cluster.Leadership in project onos by opennetworkinglab.
the class ConsistentVirtualDeviceMastershipStore method getNodes.
@Override
public RoleInfo getNodes(NetworkId networkId, DeviceId deviceId) {
checkArgument(networkId != null, NETWORK_ID_NULL);
checkArgument(deviceId != null, DEVICE_ID_NULL);
Leadership leadership = leadershipService.getLeadership(createDeviceMastershipTopic(networkId, deviceId));
return new RoleInfo(leadership.leaderNodeId(), leadership.candidates());
}
use of org.onosproject.cluster.Leadership 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.Leadership in project onos by opennetworkinglab.
the class ConsistentDeviceMastershipStore method getTermFor.
@Override
public MastershipTerm getTermFor(DeviceId deviceId) {
checkArgument(deviceId != null, DEVICE_ID_NULL);
String leadershipTopic = createDeviceMastershipTopic(deviceId);
Leadership leadership = leadershipService.getLeadership(leadershipTopic);
return leadership != null && leadership.leaderNodeId() != null ? MastershipTerm.of(leadership.leaderNodeId(), leadership.leader().term()) : null;
}
use of org.onosproject.cluster.Leadership in project onos by opennetworkinglab.
the class ConsistentVirtualDeviceMastershipStore method getTermFor.
@Override
public MastershipTerm getTermFor(NetworkId networkId, DeviceId deviceId) {
checkArgument(networkId != null, NETWORK_ID_NULL);
checkArgument(deviceId != null, DEVICE_ID_NULL);
String leadershipTopic = createDeviceMastershipTopic(networkId, deviceId);
Leadership leadership = leadershipService.getLeadership(leadershipTopic);
return leadership != null && leadership.leaderNodeId() != null ? MastershipTerm.of(leadership.leaderNodeId(), leadership.leader().term()) : null;
}
Aggregations