Search in sources :

Example 1 with PartitionClientInfo

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;
}
Also used : NodeId(org.onosproject.cluster.NodeId) PartitionAdminService(org.onosproject.store.primitives.PartitionAdminService) PartitionClientInfo(org.onosproject.store.service.PartitionClientInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ControllerNode(org.onosproject.cluster.ControllerNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Ordering(com.google.common.collect.Ordering) Service(org.apache.karaf.shell.api.action.lifecycle.Service) PartitionInfo(org.onosproject.store.service.PartitionInfo) ClusterService(org.onosproject.cluster.ClusterService) JsonNode(com.fasterxml.jackson.databind.JsonNode) Option(org.apache.karaf.shell.api.action.Option) ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with PartitionClientInfo

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("-------------------------------------------------------------------");
        }
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) PartitionClientInfo(org.onosproject.store.service.PartitionClientInfo)

Aggregations

ClusterService (org.onosproject.cluster.ClusterService)2 ControllerNode (org.onosproject.cluster.ControllerNode)2 NodeId (org.onosproject.cluster.NodeId)2 PartitionClientInfo (org.onosproject.store.service.PartitionClientInfo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Ordering (com.google.common.collect.Ordering)1 List (java.util.List)1 Command (org.apache.karaf.shell.api.action.Command)1 Option (org.apache.karaf.shell.api.action.Option)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 PartitionAdminService (org.onosproject.store.primitives.PartitionAdminService)1 PartitionInfo (org.onosproject.store.service.PartitionInfo)1