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);
}
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;
}
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;
}
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();
}
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();
}
Aggregations