Search in sources :

Example 56 with NodeId

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

the class GossipIntentStore method getPeerNodes.

private Collection<NodeId> getPeerNodes(Key key, IntentData data) {
    NodeId master = partitionService.getLeader(key, Key::hash);
    NodeId origin = (data != null) ? data.origin() : null;
    if (data != null && (master == null || origin == null)) {
        log.debug("Intent {} missing master and/or origin; master = {}, origin = {}", key, master, origin);
    }
    NodeId me = clusterService.getLocalNode().id();
    boolean isMaster = Objects.equals(master, me);
    boolean isOrigin = Objects.equals(origin, me);
    if (isMaster && isOrigin) {
        return getRandomNode();
    } else if (isMaster) {
        return origin != null ? ImmutableList.of(origin) : getRandomNode();
    } else if (isOrigin) {
        return master != null ? ImmutableList.of(master) : getRandomNode();
    } else {
        log.warn("No master or origin for intent {}", key);
        return master != null ? ImmutableList.of(master) : getRandomNode();
    }
}
Also used : NodeId(org.onosproject.cluster.NodeId) Key(org.onosproject.net.intent.Key)

Example 57 with NodeId

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

the class ConsistentDeviceMastershipStore method requestRole.

@Override
public CompletableFuture<MastershipRole> requestRole(DeviceId deviceId) {
    checkArgument(deviceId != null, DEVICE_ID_NULL);
    String leadershipTopic = createDeviceMastershipTopic(deviceId);
    Leadership leadership = leadershipService.runForLeadership(leadershipTopic);
    NodeId leader = leadership == null ? null : leadership.leaderNodeId();
    List<NodeId> candidates = leadership == null ? ImmutableList.of() : ImmutableList.copyOf(leadership.candidates());
    MastershipRole role = Objects.equals(localNodeId, leader) ? MastershipRole.MASTER : candidates.contains(localNodeId) ? MastershipRole.STANDBY : MastershipRole.NONE;
    return CompletableFuture.completedFuture(role);
}
Also used : Leadership(org.onosproject.cluster.Leadership) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 58 with NodeId

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

the class ConsistentDeviceMastershipStore method setStandby.

@Override
public CompletableFuture<MastershipEvent> setStandby(NodeId nodeId, DeviceId deviceId) {
    checkArgument(nodeId != null, NODE_ID_NULL);
    checkArgument(deviceId != null, DEVICE_ID_NULL);
    NodeId currentMaster = getMaster(deviceId);
    if (!nodeId.equals(currentMaster)) {
        return CompletableFuture.completedFuture(null);
    }
    String leadershipTopic = createDeviceMastershipTopic(deviceId);
    List<NodeId> candidates = leadershipService.getCandidates(leadershipTopic);
    NodeId newMaster = candidates.stream().filter(candidate -> !Objects.equals(nodeId, candidate)).findFirst().orElse(null);
    log.info("Transitioning to role {} for {}. Next master: {}", newMaster != null ? MastershipRole.STANDBY : MastershipRole.NONE, deviceId, newMaster);
    if (newMaster != null) {
        return setMaster(newMaster, deviceId);
    }
    return relinquishRole(nodeId, deviceId);
}
Also used : NodeId(org.onosproject.cluster.NodeId)

Example 59 with NodeId

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

the class ModelCache method addOrUpdateClusterMember.

// invoked from UiSharedTopologyModel cluster event listener
void addOrUpdateClusterMember(ControllerNode cnode) {
    NodeId id = cnode.id();
    String memo = MEMO_UPDATED;
    UiClusterMember member = uiTopology.findClusterMember(id);
    if (member == null) {
        member = addNewClusterMember(cnode);
        memo = MEMO_ADDED;
    }
    updateClusterMember(member);
    postEvent(CLUSTER_MEMBER_ADDED_OR_UPDATED, member, memo);
}
Also used : NodeId(org.onosproject.cluster.NodeId) UiClusterMember(org.onosproject.ui.model.topo.UiClusterMember)

Example 60 with NodeId

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

the class ModelCache method removeClusterMember.

// invoked from UiSharedTopologyModel cluster event listener
void removeClusterMember(ControllerNode cnode) {
    NodeId id = cnode.id();
    UiClusterMember member = uiTopology.findClusterMember(id);
    if (member != null) {
        uiTopology.remove(member);
        postEvent(CLUSTER_MEMBER_REMOVED, member, MEMO_REMOVED);
    } else {
        log.warn(E_NO_ELEMENT, "cluster node", id);
    }
}
Also used : NodeId(org.onosproject.cluster.NodeId) UiClusterMember(org.onosproject.ui.model.topo.UiClusterMember)

Aggregations

NodeId (org.onosproject.cluster.NodeId)145 ClusterService (org.onosproject.cluster.ClusterService)36 DeviceId (org.onosproject.net.DeviceId)36 Set (java.util.Set)26 MastershipRole (org.onosproject.net.MastershipRole)23 ControllerNode (org.onosproject.cluster.ControllerNode)22 Test (org.junit.Test)18 Activate (org.osgi.service.component.annotations.Activate)18 List (java.util.List)16 MastershipService (org.onosproject.mastership.MastershipService)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 Map (java.util.Map)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)10 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)10 Component (org.osgi.service.component.annotations.Component)9 Deactivate (org.osgi.service.component.annotations.Deactivate)9