Jonathan Hart
Committed by Gerrit Code Review

Make text and JSON versions of summary command pull data from the same place

Change-Id: I5519fbf9c1b73dd417e12b6fd32d1a5d02f15dcc
...@@ -15,21 +15,22 @@ ...@@ -15,21 +15,22 @@
15 */ 15 */
16 package org.onosproject.cli; 16 package org.onosproject.cli;
17 17
18 -import java.util.Set;
19 -
20 import com.fasterxml.jackson.databind.ObjectMapper; 18 import com.fasterxml.jackson.databind.ObjectMapper;
21 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 +import org.onlab.packet.IpAddress;
21 +import org.onosproject.cluster.ClusterService;
22 import org.onosproject.cluster.ControllerNode; 22 import org.onosproject.cluster.ControllerNode;
23 import org.onosproject.core.CoreService; 23 import org.onosproject.core.CoreService;
24 -import org.onosproject.cluster.ClusterService; 24 +import org.onosproject.core.Version;
25 import org.onosproject.net.device.DeviceService; 25 import org.onosproject.net.device.DeviceService;
26 import org.onosproject.net.flow.FlowRuleService; 26 import org.onosproject.net.flow.FlowRuleService;
27 import org.onosproject.net.host.HostService; 27 import org.onosproject.net.host.HostService;
28 import org.onosproject.net.intent.IntentService; 28 import org.onosproject.net.intent.IntentService;
29 import org.onosproject.net.link.LinkService; 29 import org.onosproject.net.link.LinkService;
30 -import org.onosproject.net.topology.Topology;
31 import org.onosproject.net.topology.TopologyService; 30 import org.onosproject.net.topology.TopologyService;
32 31
32 +import java.util.Set;
33 +
33 /** 34 /**
34 * Provides summary of ONOS model. 35 * Provides summary of ONOS model.
35 */ 36 */
...@@ -43,46 +44,42 @@ public class SummaryCommand extends AbstractShellCommand { ...@@ -43,46 +44,42 @@ public class SummaryCommand extends AbstractShellCommand {
43 * @param nodes set of all of the controller nodes in the cluster 44 * @param nodes set of all of the controller nodes in the cluster
44 * @return count of active nodes 45 * @return count of active nodes
45 */ 46 */
46 - private int activeNodes(Set<ControllerNode> nodes) { 47 + private long activeNodes(Set<ControllerNode> nodes) {
47 - int nodeCount = 0; 48 + ClusterService clusterService = get(ClusterService.class);
48 49
49 - for (final ControllerNode node : nodes) { 50 + return nodes.stream()
50 - final ControllerNode.State nodeState = 51 + .map(node -> clusterService.getState(node.id()))
51 - get(ClusterService.class).getState(node.id()); 52 + .filter(nodeState -> nodeState.isActive())
52 - if (nodeState.isActive()) { 53 + .count();
53 - nodeCount++;
54 - }
55 - }
56 - return nodeCount;
57 } 54 }
58 55
59 @Override 56 @Override
60 protected void execute() { 57 protected void execute() {
61 - TopologyService topologyService = get(TopologyService.class); 58 + IpAddress nodeIp = get(ClusterService.class).getLocalNode().ip();
62 - Topology topology = topologyService.currentTopology(); 59 + Version version = get(CoreService.class).version();
60 + long numNodes = activeNodes(get(ClusterService.class).getNodes());
61 + int numDevices = get(DeviceService.class).getDeviceCount();
62 + int numLinks = get(LinkService.class).getLinkCount();
63 + int numHosts = get(HostService.class).getHostCount();
64 + int numScc = get(TopologyService.class).currentTopology().clusterCount();
65 + int numFlows = get(FlowRuleService.class).getFlowRuleCount();
66 + long numIntents = get(IntentService.class).getIntentCount();
67 +
63 if (outputJson()) { 68 if (outputJson()) {
64 print("%s", new ObjectMapper().createObjectNode() 69 print("%s", new ObjectMapper().createObjectNode()
65 - .put("node", get(ClusterService.class).getLocalNode().ip().toString()) 70 + .put("node", nodeIp.toString())
66 - .put("version", get(CoreService.class).version().toString()) 71 + .put("version", version.toString())
67 - .put("nodes", get(ClusterService.class).getNodes().size()) 72 + .put("nodes", numNodes)
68 - .put("devices", topology.deviceCount()) 73 + .put("devices", numDevices)
69 - .put("links", topology.linkCount()) 74 + .put("links", numLinks)
70 - .put("hosts", get(HostService.class).getHostCount()) 75 + .put("hosts", numHosts)
71 - .put("SCC(s)", topology.clusterCount()) 76 + .put("SCC(s)", numScc)
72 - .put("flows", get(FlowRuleService.class).getFlowRuleCount()) 77 + .put("flows", numFlows)
73 - .put("intents", get(IntentService.class).getIntentCount())); 78 + .put("intents", numIntents));
74 } else { 79 } else {
75 - print("node=%s, version=%s", 80 + print("node=%s, version=%s", nodeIp, version);
76 - get(ClusterService.class).getLocalNode().ip(),
77 - get(CoreService.class).version().toString());
78 print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, flows=%d, intents=%d", 81 print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, flows=%d, intents=%d",
79 - activeNodes(get(ClusterService.class).getNodes()), 82 + numNodes, numDevices, numLinks, numHosts, numScc, numFlows, numIntents);
80 - get(DeviceService.class).getDeviceCount(),
81 - get(LinkService.class).getLinkCount(),
82 - get(HostService.class).getHostCount(),
83 - topologyService.getClusters(topology).size(),
84 - get(FlowRuleService.class).getFlowRuleCount(),
85 - get(IntentService.class).getIntentCount());
86 } 83 }
87 } 84 }
88 85
......