Search in sources :

Example 1 with ClusterAdminService

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

the class StorageNodesListCommand method doExecute.

@Override
protected void doExecute() {
    ClusterAdminService service = get(ClusterAdminService.class);
    List<Node> nodes = newArrayList(service.getConsensusNodes());
    Collections.sort(nodes, Comparator.comparing(Node::id));
    if (outputJson()) {
        print("%s", json(nodes));
    } else {
        for (Node node : nodes) {
            print(FMT, node.id(), node.host(), node.tcpPort());
        }
    }
}
Also used : ClusterAdminService(org.onosproject.cluster.ClusterAdminService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Node(org.onosproject.cluster.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with ClusterAdminService

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

the class MembershipsListCommand method doExecute.

@Override
protected void doExecute() {
    MembershipService service = get(MembershipService.class);
    ClusterAdminService clusterService = get(ClusterAdminService.class);
    if (outputJson()) {
        print("%s", json(service));
    } else {
        service.getGroups().forEach(group -> {
            List<Member> members = newArrayList(group.members());
            print("-------------------------------------------------------------------");
            print("Version: %s, Members: %d", group.version(), members.size());
            members.sort(MEMBERSHIP_COMPARATOR);
            members.forEach(member -> {
                Optional<ControllerNode> controllerNode = Optional.ofNullable(clusterService.getNode(member.nodeId()));
                if (!controllerNode.isPresent()) {
                    print(" id=%s, version=%s, self=%s", member.nodeId(), member.version(), member.equals(service.getLocalMember()) ? "*" : "");
                } else {
                    ControllerNode node = controllerNode.get();
                    print(" id=%s, ip=%s, tcpPort=%s, state=%s, self=%s", member.nodeId(), node.ip(), node.tcpPort(), clusterService.getState(node.id()), member.equals(service.getLocalMember()) ? "*" : "");
                }
            });
            print("-------------------------------------------------------------------");
        });
    }
}
Also used : ClusterAdminService(org.onosproject.cluster.ClusterAdminService) MembershipService(org.onosproject.cluster.MembershipService) ControllerNode(org.onosproject.cluster.ControllerNode) Member(org.onosproject.cluster.Member)

Example 3 with ClusterAdminService

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

the class NodesListCommand method doExecute.

@Override
protected void doExecute() {
    ClusterAdminService service = get(ClusterAdminService.class);
    List<ControllerNode> nodes = newArrayList(service.getNodes());
    Collections.sort(nodes, Comparators.NODE_COMPARATOR);
    if (outputJson()) {
        print("%s", json(service, nodes));
    } else {
        ControllerNode self = service.getLocalNode();
        for (ControllerNode node : nodes) {
            String timeAgo = service.localStatus(node.id());
            Version version = service.getVersion(node.id());
            print(FMT, node.id(), node.ip(), node.tcpPort(), service.getState(node.id()), version == null ? "unknown" : version, timeAgo, node.equals(self) ? "*" : "");
        }
    }
}
Also used : Version(org.onosproject.core.Version) ClusterAdminService(org.onosproject.cluster.ClusterAdminService) ControllerNode(org.onosproject.cluster.ControllerNode)

Aggregations

ClusterAdminService (org.onosproject.cluster.ClusterAdminService)3 ControllerNode (org.onosproject.cluster.ControllerNode)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Member (org.onosproject.cluster.Member)1 MembershipService (org.onosproject.cluster.MembershipService)1 Node (org.onosproject.cluster.Node)1 Version (org.onosproject.core.Version)1