Search in sources :

Example 6 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class ServerHandshaker method getRole.

@Override
public MastershipRole getRole() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Probe the driver to ask for mastership service
    MastershipService mastershipService = getHandler().get(MastershipService.class);
    return mastershipService.getLocalRole(deviceId);
}
Also used : DeviceId(org.onosproject.net.DeviceId) MastershipService(org.onosproject.mastership.MastershipService)

Example 7 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class ServerControllerConfig method removeControllers.

@Override
public void removeControllers(List<ControllerInfo> controllers) {
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    MastershipService mastershipService = getHandler().get(MastershipService.class);
    checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn("I am not master for {}. " + "Please use master {} to remove controllers from this device", deviceId, mastershipService.getMasterFor(deviceId));
        return;
    }
    for (ControllerInfo ctrl : controllers) {
        log.info("Remove controller with {}:{}:{}", ctrl.type(), ctrl.ip().toString(), ctrl.port());
        String remCtrlUrl = URL_CONTROLLERS_DEL + SLASH + ctrl.ip().toString();
        // Remove this controller
        int response = getController().delete(deviceId, remCtrlUrl, null, JSON);
        if (!checkStatusCode(response)) {
            log.error("Failed to remove controller {}:{}:{} from device {}", ctrl.type(), ctrl.ip().toString(), ctrl.port(), deviceId);
        }
    }
    return;
}
Also used : DeviceId(org.onosproject.net.DeviceId) MastershipService(org.onosproject.mastership.MastershipService) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 8 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class ServerControllerConfig method setControllers.

@Override
public void setControllers(List<ControllerInfo> controllers) {
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    MastershipService mastershipService = getHandler().get(MastershipService.class);
    checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn("I am not master for {}. " + "Please use master {} to set controllers for this device", deviceId, mastershipService.getMasterFor(deviceId));
        return;
    }
    ObjectMapper mapper = new ObjectMapper();
    // Create the object node to host the data
    ObjectNode sendObjNode = mapper.createObjectNode();
    // Insert header
    ArrayNode ctrlsArrayNode = sendObjNode.putArray(PARAM_CTRL);
    // Add each controller's information object
    for (ControllerInfo ctrl : controllers) {
        ObjectNode ctrlObjNode = mapper.createObjectNode();
        ctrlObjNode.put(PARAM_CTRL_IP, ctrl.ip().toString());
        ctrlObjNode.put(PARAM_CTRL_PORT, ctrl.port());
        ctrlObjNode.put(PARAM_CTRL_TYPE, ctrl.type());
        ctrlsArrayNode.add(ctrlObjNode);
    }
    // Post the controllers to the device
    int response = getController().post(deviceId, URL_CONTROLLERS_SET, new ByteArrayInputStream(sendObjNode.toString().getBytes()), JSON);
    if (!checkStatusCode(response)) {
        log.error("Failed to set controllers on device {}", deviceId);
    }
    return;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) MastershipService(org.onosproject.mastership.MastershipService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 9 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class MastershipWebResource method getMasterFor.

/**
 * Returns the current master for a given device.
 *
 * @param deviceId device identifier
 * @return 200 OK with the identifier of the master controller for the device
 * @onos.rsModel NodeId
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/master")
public Response getMasterFor(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    NodeId id = nullIsNotFound(mastershipService.getMasterFor(DeviceId.deviceId(deviceId)), NODE_ID_NOT_FOUND);
    ObjectNode root = mapper().createObjectNode();
    root.put(NODE_ID, id.id());
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class MastershipWebResource method relinquishMastership.

/**
 * Abandons mastership of the specified device on the local node thus
 * forcing selection of a new master. If the local node is not a master
 * for this device, no master selection will occur.
 *
 * @param deviceId device identifier
 * @return status of the request - CREATED if the JSON is correct
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/relinquish")
public Response relinquishMastership(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    DeviceId id = DeviceId.deviceId(deviceId);
    mastershipService.relinquishMastershipSync(id);
    return Response.created(id.uri()).build();
}
Also used : DeviceId(org.onosproject.net.DeviceId) MastershipService(org.onosproject.mastership.MastershipService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

MastershipService (org.onosproject.mastership.MastershipService)41 DeviceId (org.onosproject.net.DeviceId)29 DriverHandler (org.onosproject.net.driver.DriverHandler)20 NetconfController (org.onosproject.netconf.NetconfController)20 NetconfException (org.onosproject.netconf.NetconfException)20 NodeId (org.onosproject.cluster.NodeId)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)5 ArrayList (java.util.ArrayList)4 DeviceService (org.onosproject.net.device.DeviceService)4 ClusterService (org.onosproject.cluster.ClusterService)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Sets (com.google.common.collect.Sets)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2