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