use of org.onosproject.store.service.PartitionClientInfo in project onos by opennetworkinglab.
the class PartitionsListCommand method jsonForClientInfo.
/**
* Converts partition client info into a JSON object.
*
* @param partitionClientInfo partition client descriptions
*/
private JsonNode jsonForClientInfo(List<PartitionClientInfo> partitionClientInfo) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode partitions = mapper.createArrayNode();
ClusterService clusterService = get(ClusterService.class);
// Create a JSON node for each partition client
partitionClientInfo.forEach(info -> {
ObjectNode partition = mapper.createObjectNode();
// Add each member to the "servers" array for this partition
ArrayNode servers = partition.putArray("servers");
info.servers().stream().map(clusterService::getNode).map(node -> String.format("%s:%d", node.ip(), node.tcpPort())).forEach(servers::add);
// Complete the partition attributes and add it to the array
partition.put("partitionId", info.partitionId().toString());
partitions.add(partition);
});
return partitions;
}
use of org.onosproject.store.service.PartitionClientInfo in project onos by opennetworkinglab.
the class PartitionsListCommand method displayPartitionClients.
/**
* Displays partition client info as text.
*
* @param partitionClientInfo partition client information
*/
private void displayPartitionClients(List<PartitionClientInfo> partitionClientInfo) {
if (partitionClientInfo.isEmpty()) {
return;
}
ClusterService clusterService = get(ClusterService.class);
print("-------------------------------------------------------------------");
print(CLIENT_FMT, "Name", "Servers");
print("-------------------------------------------------------------------");
for (PartitionClientInfo info : partitionClientInfo) {
boolean first = true;
for (NodeId serverId : Ordering.natural().sortedCopy(info.servers())) {
ControllerNode server = clusterService.getNode(serverId);
String serverString = String.format("%s:%d", server.id(), server.tcpPort());
if (first) {
print(CLIENT_FMT, info.partitionId(), serverString);
first = false;
} else {
print(CLIENT_FMT, "", serverString);
}
}
if (!first) {
print("-------------------------------------------------------------------");
}
}
}
Aggregations