use of org.onosproject.mastership.MastershipAdminService in project onos by opennetworkinglab.
the class DeviceRoleCommand method doExecute.
@Override
protected void doExecute() {
MastershipAdminService service = get(MastershipAdminService.class);
MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
Futures.getUnchecked(service.setRole(new NodeId(node), deviceId(uri), mastershipRole));
}
use of org.onosproject.mastership.MastershipAdminService in project onos by opennetworkinglab.
the class MastershipWebResource method balanceRoles.
/**
* Balances the mastership to be shared as evenly as possibly by all
* online instances.
*
* @return status of the request - OK if the request is successfully processed
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response balanceRoles() {
MastershipAdminService mastershipAdminService = get(MastershipAdminService.class);
mastershipAdminService.balanceRoles();
return Response.ok().build();
}
use of org.onosproject.mastership.MastershipAdminService in project onos by opennetworkinglab.
the class MastershipWebResource method setRole.
/**
* Applies the current mastership role for the specified device.
*
* @param stream JSON representation of device, node, mastership info
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel MastershipPut
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response setRole(InputStream stream) {
MastershipAdminService mastershipAdminService = get(MastershipAdminService.class);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode deviceIdJson = jsonTree.get(DEVICE_ID);
JsonNode nodeIdJson = jsonTree.get(NODE_ID);
MastershipRole role = codec(MastershipRole.class).decode(jsonTree, this);
if (deviceIdJson == null) {
throw new IllegalArgumentException(DEVICE_ID_INVALID);
}
if (nodeIdJson == null) {
throw new IllegalArgumentException(NODE_ID_INVALID);
}
mastershipAdminService.setRoleSync(NodeId.nodeId(nodeIdJson.asText()), DeviceId.deviceId(deviceIdJson.asText()), role);
return Response.ok().build();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.mastership.MastershipAdminService in project onos by opennetworkinglab.
the class ResetMastershipCommand method doExecute.
@Override
protected void doExecute() {
MastershipAdminService mastershipService = get(MastershipAdminService.class);
ClusterService clusterService = get(ClusterService.class);
DeviceService deviceService = get(DeviceService.class);
if ((isConcentrate && isBalance) || (!isConcentrate && !isBalance)) {
print("Please specify either -b or -c option only");
return;
}
NodeId localId = clusterService.getLocalNode().id();
if (isConcentrate) {
deviceService.getAvailableDevices(Device.Type.SWITCH).forEach(d -> mastershipService.setRole(localId, d.id(), MastershipRole.MASTER));
}
if (isBalance) {
mastershipService.balanceRoles();
}
}
use of org.onosproject.mastership.MastershipAdminService in project onos by opennetworkinglab.
the class VirtualNetworkBalanceMastersCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkService vnetService = get(VirtualNetworkService.class);
MastershipAdminService mastershipAdminService = vnetService.get(NetworkId.networkId(networkId), MastershipAdminService.class);
mastershipAdminService.balanceRoles();
}
Aggregations