use of org.onosproject.cluster.RoleInfo in project onos by opennetworkinglab.
the class MastershipResourceTest method testGetNodesFor.
/**
* Tests the result of the REST API GET when there are active nodes.
*/
@Test
public void testGetNodesFor() {
RoleInfo mockRoleInfo = createMockRoleInfo();
expect(mockService.getNodesFor(anyObject())).andReturn(mockRoleInfo).anyTimes();
replay(mockService);
final WebTarget wt = target();
final String response = wt.path("mastership/" + deviceId1.toString() + "/role").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result, matchesRoleInfo(mockRoleInfo));
}
use of org.onosproject.cluster.RoleInfo 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();
}
Aggregations