Search in sources :

Example 1 with MastershipAdminService

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));
}
Also used : MastershipAdminService(org.onosproject.mastership.MastershipAdminService) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 2 with MastershipAdminService

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();
}
Also used : MastershipAdminService(org.onosproject.mastership.MastershipAdminService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with MastershipAdminService

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);
    }
}
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 4 with MastershipAdminService

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();
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) MastershipAdminService(org.onosproject.mastership.MastershipAdminService) DeviceService(org.onosproject.net.device.DeviceService) NodeId(org.onosproject.cluster.NodeId)

Example 5 with MastershipAdminService

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();
}
Also used : VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) MastershipAdminService(org.onosproject.mastership.MastershipAdminService)

Aggregations

MastershipAdminService (org.onosproject.mastership.MastershipAdminService)5 NodeId (org.onosproject.cluster.NodeId)2 MastershipRole (org.onosproject.net.MastershipRole)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 ClusterService (org.onosproject.cluster.ClusterService)1 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)1 DeviceService (org.onosproject.net.device.DeviceService)1