Search in sources :

Example 31 with MastershipRole

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MastershipAdminService(org.onosproject.mastership.MastershipAdminService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) MastershipRole(org.onosproject.net.MastershipRole) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 32 with MastershipRole

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) MastershipService(org.onosproject.mastership.MastershipService) MastershipRole(org.onosproject.net.MastershipRole) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

MastershipRole (org.onosproject.net.MastershipRole)32 NodeId (org.onosproject.cluster.NodeId)18 DeviceId (org.onosproject.net.DeviceId)10 MastershipEvent (org.onosproject.mastership.MastershipEvent)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 MastershipTerm (org.onosproject.mastership.MastershipTerm)4 ExecutionException (java.util.concurrent.ExecutionException)3 MastershipInfo (org.onosproject.mastership.MastershipInfo)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2