use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class RegionUpdateCommand method doExecute.
@Override
protected void doExecute() {
RegionService regionService = get(RegionService.class);
RegionAdminService regionAdminService = get(RegionAdminService.class);
RegionId regionId = RegionId.regionId(id);
if (regionService.getRegion(regionId) == null) {
print("The region with id %s does not exist.", regionId);
return;
}
List<Set<NodeId>> masters = Lists.newArrayList();
Set<NodeId> nodeIds = Sets.newHashSet();
for (String masterArg : masterArgs) {
if ("/".equals(masterArg)) {
masters.add(nodeIds);
nodeIds = Sets.newHashSet();
} else {
nodeIds.add(NodeId.nodeId(masterArg));
}
}
masters.add(nodeIds);
regionAdminService.updateRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
print("Region with id %s is successfully updated.", regionId);
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class SimpleMastershipStore method getMastership.
@Override
public MastershipInfo getMastership(DeviceId deviceId) {
ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
NodeId master = masterMap.get(deviceId);
if (master != null) {
roleBuilder.put(master, MastershipRole.MASTER);
}
backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class SimpleMastershipStore method relinquishRole.
@Override
public synchronized CompletableFuture<MastershipEvent> relinquishRole(NodeId nodeId, DeviceId deviceId) {
MastershipRole role = getRole(nodeId, deviceId);
switch(role) {
case MASTER:
NodeId backup = reelect(deviceId, nodeId);
masterMap.put(deviceId, backup);
incrementTerm(deviceId);
return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
case STANDBY:
if (removeFromBackups(deviceId, nodeId)) {
return CompletableFuture.completedFuture(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(deviceId)));
}
break;
case NONE:
break;
default:
log.warn("unknown Mastership Role {}", role);
}
return CompletableFuture.completedFuture(null);
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class SimpleMastershipStore method setMaster.
@Override
public synchronized CompletableFuture<MastershipEvent> setMaster(NodeId nodeId, DeviceId deviceId) {
MastershipRole role = getRole(nodeId, deviceId);
switch(role) {
case MASTER:
// no-op
return CompletableFuture.completedFuture(null);
case STANDBY:
case NONE:
NodeId prevMaster = masterMap.put(deviceId, nodeId);
incrementTerm(deviceId);
removeFromBackups(deviceId, nodeId);
addToBackup(deviceId, prevMaster);
break;
default:
log.warn("unknown Mastership Role {}", role);
return null;
}
return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class UpgradeManager method handleClusterEvent.
/**
* Handles a cluster event.
*
* @param event the cluster event
*/
protected void handleClusterEvent(ClusterEvent event) {
checkPermission(CLUSTER_EVENT);
// If an instance was deactivated, check whether we need to roll back the upgrade.
if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
Upgrade upgrade = getState();
if (upgrade.status().upgraded()) {
// Get the upgraded subset of the cluster and check whether the down node is a member
// of the upgraded subset. If so, roll back the upgrade to tolerate the failure.
Set<NodeId> upgradedNodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> clusterService.getVersion(id).equals(upgrade.target())).collect(Collectors.toSet());
if (upgradedNodes.contains(event.subject().id())) {
log.warn("Upgrade failure detected: rolling back upgrade");
rollback();
}
}
}
}
Aggregations