use of org.onosproject.net.MastershipRole 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.net.MastershipRole 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.net.MastershipRole in project onos by opennetworkinglab.
the class SimpleMastershipStore method requestRole.
@Override
public synchronized CompletableFuture<MastershipRole> requestRole(DeviceId deviceId) {
// query+possible reelection
NodeId node = clusterService.getLocalNode().id();
MastershipRole role = getRole(node, deviceId);
switch(role) {
case MASTER:
return CompletableFuture.completedFuture(MastershipRole.MASTER);
case STANDBY:
if (getMaster(deviceId) == null) {
// no master => become master
masterMap.put(deviceId, node);
incrementTerm(deviceId);
// remove from backup list
removeFromBackups(deviceId, node);
notifyDelegate(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
return CompletableFuture.completedFuture(MastershipRole.MASTER);
}
return CompletableFuture.completedFuture(MastershipRole.STANDBY);
case NONE:
if (getMaster(deviceId) == null) {
// no master => become master
masterMap.put(deviceId, node);
incrementTerm(deviceId);
notifyDelegate(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
return CompletableFuture.completedFuture(MastershipRole.MASTER);
}
// add to backup list
if (addToBackup(deviceId, node)) {
notifyDelegate(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(deviceId)));
}
return CompletableFuture.completedFuture(MastershipRole.STANDBY);
default:
log.warn("unknown Mastership Role {}", role);
}
return CompletableFuture.completedFuture(role);
}
use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.
the class MastershipWebResource method requestRoleFor.
/**
* Returns the mastership status of the local controller for a given
* device forcing master selection if necessary.
*
* @param deviceId device identifier
* @return 200 OK with the role of this controller instance
* @onos.rsModel MastershipRole
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/request")
public Response requestRoleFor(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
DeviceService deviceService = get(DeviceService.class);
DeviceId id = DeviceId.deviceId(deviceId);
nullIsNotFound(deviceService.getDevice(id), DEVICE_ID_NOT_FOUND);
MastershipRole role = nullIsNotFound(mastershipService.requestRoleForSync(id), MASTERSHIP_ROLE_NOT_FOUND);
ObjectNode root = codec(MastershipRole.class).encode(role, this);
return ok(root).build();
}
use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.
the class MastershipWebResource method getLocalRole.
/**
* Returns the role of the local node for the specified device.
*
* @param deviceId device identifier
* @return 200 OK with role of the current node
* @onos.rsModel MastershipRole
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/local")
public Response getLocalRole(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
MastershipRole role = mastershipService.getLocalRole(DeviceId.deviceId(deviceId));
ObjectNode root = codec(MastershipRole.class).encode(role, this);
return ok(root).build();
}
Aggregations