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