Search in sources :

Example 6 with RoleInfo

use of org.onosproject.cluster.RoleInfo in project onos by opennetworkinglab.

the class RoleInfoCodecTest method getRoleInfo.

/**
 * Reads in a role info from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded roleInfo
 * @throws IOException if processing the resource fails
 */
private RoleInfo getRoleInfo(String resourceName) throws IOException {
    InputStream jsonStream = RoleInfoCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat(json, notNullValue());
    RoleInfo roleInfo = roleInfoCodec.decode((ObjectNode) json, context);
    assertThat(roleInfo, notNullValue());
    return roleInfo;
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 7 with RoleInfo

use of org.onosproject.cluster.RoleInfo in project onos by opennetworkinglab.

the class MastershipResourceTest method createMockRoleInfo.

/**
 * Creates a mock role info which is comprised of one master and three backups.
 *
 * @return a mock role info instance
 */
private RoleInfo createMockRoleInfo() {
    NodeId master = NodeId.nodeId("master");
    List<NodeId> backups = ImmutableList.of(nodeId1, nodeId2, nodeId3);
    return new RoleInfo(master, backups);
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId)

Example 8 with RoleInfo

use of org.onosproject.cluster.RoleInfo in project onos by opennetworkinglab.

the class RolesCommand method json.

// Produces JSON structure with role information for the given device.
private JsonNode json(MastershipService service, ObjectMapper mapper, Device device) {
    NodeId master = service.getMasterFor(device.id());
    ObjectNode result = mapper.createObjectNode().put("id", device.id().toString()).put("master", master != null ? master.toString() : "none");
    RoleInfo nodes = service.getNodesFor(device.id());
    ArrayNode standbys = mapper.createArrayNode();
    for (NodeId nid : nodes.backups()) {
        standbys.add(nid.toString());
    }
    result.set("standbys", standbys);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 9 with RoleInfo

use of org.onosproject.cluster.RoleInfo in project onos by opennetworkinglab.

the class RolesCommand method printRoles.

/**
 * Prints the role information for a device.
 *
 * @param service  mastership service
 * @param deviceId the ID of the device
 */
protected void printRoles(MastershipService service, DeviceId deviceId) {
    RoleInfo nodes = service.getNodesFor(deviceId);
    StringBuilder builder = new StringBuilder();
    for (NodeId nid : nodes.backups()) {
        builder.append(nid).append(" ");
    }
    print(FMT_HDR, deviceId, nodes.master() == null ? "NONE" : nodes.master(), builder.toString());
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId)

Example 10 with RoleInfo

use of org.onosproject.cluster.RoleInfo in project onos by opennetworkinglab.

the class RoleInfoCodecTest method testRoleInfoDecode.

/**
 * Tests decoding of a role info JSON object.
 */
@Test
public void testRoleInfoDecode() throws IOException {
    RoleInfo roleInfo = getRoleInfo("RoleInfo.json");
    assertThat(roleInfo.backups().size(), is(3));
    assertThat(roleInfo.master().id(), is("1"));
    List<NodeId> backups = roleInfo.backups();
    assertThat(backups.contains(NodeId.nodeId("2")), is(true));
    assertThat(backups.contains(NodeId.nodeId("3")), is(true));
    assertThat(backups.contains(NodeId.nodeId("4")), is(true));
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId) Test(org.junit.Test)

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