Search in sources :

Example 1 with Leadership

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;
}
Also used : Leadership(org.onosproject.cluster.Leadership) NodeId(org.onosproject.cluster.NodeId)

Example 2 with Leadership

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

the class ConsistentVirtualDeviceMastershipStore method getMastership.

@Override
public MastershipInfo getMastership(NetworkId networkId, DeviceId deviceId) {
    checkArgument(networkId != null, NETWORK_ID_NULL);
    checkArgument(deviceId != null, DEVICE_ID_NULL);
    Leadership leadership = leadershipService.getLeadership(createDeviceMastershipTopic(networkId, deviceId));
    return buildMastershipFromLeadership(leadership);
}
Also used : Leadership(org.onosproject.cluster.Leadership)

Example 3 with Leadership

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());
}
Also used : Leadership(org.onosproject.cluster.Leadership) RoleInfo(org.onosproject.cluster.RoleInfo)

Example 4 with Leadership

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

the class ConsistentVirtualDeviceMastershipStore method requestRole.

@Override
public CompletableFuture<MastershipRole> requestRole(NetworkId networkId, DeviceId deviceId) {
    checkArgument(networkId != null, NETWORK_ID_NULL);
    checkArgument(deviceId != null, DEVICE_ID_NULL);
    String leadershipTopic = createDeviceMastershipTopic(networkId, deviceId);
    Leadership leadership = leadershipService.runForLeadership(leadershipTopic);
    return CompletableFuture.completedFuture(localNodeId.equals(leadership.leaderNodeId()) ? MastershipRole.MASTER : MastershipRole.STANDBY);
}
Also used : Leadership(org.onosproject.cluster.Leadership)

Example 5 with Leadership

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

the class LeaderCommand method doExecute.

@Override
protected void doExecute() {
    LeadershipAdminService leaderService = get(LeadershipAdminService.class);
    Map<String, Leadership> leaderBoard = leaderService.getLeaderBoard();
    if (topicPattern == null) {
        allTopics = true;
    } else {
        allTopics = false;
        pattern = Pattern.compile(topicPattern);
    }
    if (outputJson()) {
        print("%s", json(leaderBoard));
        return;
    }
    if (showCandidates) {
        displayCandidates(leaderBoard);
    } else {
        displayLeaders(leaderBoard);
    }
}
Also used : Leadership(org.onosproject.cluster.Leadership) LeadershipAdminService(org.onosproject.cluster.LeadershipAdminService)

Aggregations

Leadership (org.onosproject.cluster.Leadership)15 NodeId (org.onosproject.cluster.NodeId)6 LeadershipEvent (org.onosproject.cluster.LeadershipEvent)3 Map (java.util.Map)2 Leader (org.onosproject.cluster.Leader)2 LeadershipAdminService (org.onosproject.cluster.LeadershipAdminService)2 Activate (org.osgi.service.component.annotations.Activate)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Maps (com.google.common.collect.Maps)1 Comparator (java.util.Comparator)1 Dictionary (java.util.Dictionary)1 List (java.util.List)1 Objects (java.util.Objects)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Consumer (java.util.function.Consumer)1 Pattern (java.util.regex.Pattern)1