Search in sources :

Example 11 with RoleInfo

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));
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) JsonObject(com.eclipsesource.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 12 with RoleInfo

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RoleInfo(org.onosproject.cluster.RoleInfo) MastershipService(org.onosproject.mastership.MastershipService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RoleInfo (org.onosproject.cluster.RoleInfo)12 NodeId (org.onosproject.cluster.NodeId)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 JsonObject (com.eclipsesource.json.JsonObject)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebTarget (javax.ws.rs.client.WebTarget)1 Leadership (org.onosproject.cluster.Leadership)1 MastershipInfo (org.onosproject.mastership.MastershipInfo)1 MastershipService (org.onosproject.mastership.MastershipService)1