use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method getDeviceOf.
/**
* Returns the devices for which a controller is master.
*
* @param nodeId controller identifier
* @return 200 OK with a set of device identifiers
* @onos.rsModel DeviceIds
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{nodeId}/device")
public Response getDeviceOf(@PathParam("nodeId") String nodeId) {
MastershipService mastershipService = get(MastershipService.class);
ObjectNode root = mapper().createObjectNode();
ArrayNode devicesNode = root.putArray(DEVICE_IDS);
Set<DeviceId> devices = mastershipService.getDevicesOf(NodeId.nodeId(nodeId));
if (devices != null) {
devices.forEach(id -> devicesNode.add(id.toString()));
}
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method getLocalRole.
/**
* Returns the role of the local node for the specified device.
*
* @param deviceId device identifier
* @return 200 OK with role of the current node
* @onos.rsModel MastershipRole
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/local")
public Response getLocalRole(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
MastershipRole role = mastershipService.getLocalRole(DeviceId.deviceId(deviceId));
ObjectNode root = codec(MastershipRole.class).encode(role, this);
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method getNodesFor.
/**
* Returns controllers connected to a given device, in order of
* preference. The first entry in the list is the current master.
*
* @param deviceId device identifier
* @return 200 OK with a list of controller identifiers
* @onos.rsModel RoleInfo
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/role")
public Response getNodesFor(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
RoleInfo info = nullIsNotFound(mastershipService.getNodesFor(DeviceId.deviceId(deviceId)), ROLE_INFO_NOT_FOUND);
ObjectNode root = codec(RoleInfo.class).encode(info, this);
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService 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();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class TestCodecService method setup.
@Before
public void setup() throws IOException {
storageService = new TestStorageService();
mastershipService = createNiceMock(MastershipService.class);
coreService = createNiceMock(CoreService.class);
hostService = createNiceMock(HostService.class);
deviceService = createNiceMock(DeviceService.class);
expect(deviceService.getDevices()).andReturn(ImmutableList.of()).anyTimes();
networkConfigRegistry = createNiceMock(NetworkConfigRegistry.class);
networkConfigService = createNiceMock(NetworkConfigService.class);
manager = new SimpleIntManager();
manager.coreService = coreService;
manager.deviceService = deviceService;
manager.storageService = storageService;
manager.mastershipService = mastershipService;
manager.hostService = hostService;
manager.netcfgService = networkConfigService;
manager.netcfgRegistry = networkConfigRegistry;
manager.eventExecutor = MoreExecutors.newDirectExecutorService();
manager.codecService = codecService;
expect(coreService.registerApplication(APP_NAME)).andReturn(APP_ID).anyTimes();
networkConfigRegistry.registerConfigFactory(anyObject());
expectLastCall().once();
Capture<NetworkConfigListener> capture = newCapture();
networkConfigService.addListener(EasyMock.capture(capture));
expectLastCall().once();
IntReportConfig config = getIntReportConfig("/report-config.json");
expect(networkConfigService.getConfig(APP_ID, IntReportConfig.class)).andReturn(config).anyTimes();
replay(mastershipService, deviceService, coreService, hostService, networkConfigRegistry, networkConfigService);
manager.activate();
networkConfigListener = capture.getValue();
}
Aggregations