use of org.onosproject.net.MastershipRole 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.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();
}
Aggregations