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());
}
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);
}
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));
}
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;
}
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);
}
Aggregations