Search in sources :

Example 1 with RoleInfo

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

the class ConsistentVirtualDeviceMastershipStore method getNodes.

@Override
public RoleInfo getNodes(NetworkId networkId, DeviceId deviceId) {
    checkArgument(networkId != null, NETWORK_ID_NULL);
    checkArgument(deviceId != null, DEVICE_ID_NULL);
    Leadership leadership = leadershipService.getLeadership(createDeviceMastershipTopic(networkId, deviceId));
    return new RoleInfo(leadership.leaderNodeId(), leadership.candidates());
}
Also used : Leadership(org.onosproject.cluster.Leadership) RoleInfo(org.onosproject.cluster.RoleInfo)

Example 2 with RoleInfo

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

the class RoleInfoCodec method decode.

@Override
public RoleInfo decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    // parse node identifier of master
    NodeId nodeId = json.get(MASTER) == null ? null : NodeId.nodeId(json.get(MASTER).asText());
    // parse node identifier of backups
    List<NodeId> backups = new ArrayList<>();
    ArrayNode backupsJson = (ArrayNode) nullIsIllegal(json.get(BACKUPS), BACKUPS + MISSING_MEMBER_MESSAGE);
    IntStream.range(0, backupsJson.size()).forEach(i -> {
        JsonNode backupJson = nullIsIllegal(backupsJson.get(i), "Backup node id cannot be null");
        backups.add(NodeId.nodeId(backupJson.asText()));
    });
    return new RoleInfo(nodeId, backups);
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with RoleInfo

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

the class RoleInfoCodecTest method testRoleInfoEncode.

/**
 * Tests encoding of a role info object.
 */
@Test
public void testRoleInfoEncode() {
    NodeId masterNodeId = NodeId.nodeId("1");
    NodeId backupNodeId1 = NodeId.nodeId("1");
    NodeId backupNodeId2 = NodeId.nodeId("2");
    NodeId backupNodeId3 = NodeId.nodeId("3");
    List<NodeId> backupNodeIds = ImmutableList.of(backupNodeId1, backupNodeId2, backupNodeId3);
    RoleInfo roleInfo = new RoleInfo(masterNodeId, backupNodeIds);
    ObjectNode roleInfoJson = roleInfoCodec.encode(roleInfo, context);
    assertThat(roleInfoJson, RoleInfoJsonMatcher.matchesRoleInfo(roleInfo));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId) Test(org.junit.Test)

Example 4 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 5 with RoleInfo

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

the class RoleInfoProtoTranslator method translate.

/**
 * Translates gRPC RoleInfo to {@link RoleInfo}.
 *
 * @param roleInfo gRPC message
 * @return {@link RoleInfo}
 */
public static RoleInfo translate(RoleInfoProtoOuterClass.RoleInfoProto roleInfo) {
    NodeId master = NodeIdProtoTranslator.translate(roleInfo.getMaster());
    List<NodeId> backups = Lists.newArrayList();
    backups = roleInfo.getBackupsList().stream().map(r -> NodeIdProtoTranslator.translate(r)).collect(Collectors.toList());
    return new RoleInfo(master, backups);
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId)

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