Adding JSON format to the CLI. Intents and flows still need to be done.
diff --git a/cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java b/cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
index 1597b55..180405b 100644
--- a/cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
@@ -1,5 +1,6 @@
package org.onlab.onos.cli;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.CoreService;
import org.onlab.onos.cluster.ClusterService;
@@ -22,18 +23,32 @@
protected void execute() {
TopologyService topologyService = get(TopologyService.class);
Topology topology = topologyService.currentTopology();
- print("node=%s, version=%s",
- get(ClusterService.class).getLocalNode().ip(),
- get(CoreService.class).version().toString());
- print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d",
- get(ClusterService.class).getNodes().size(),
- get(DeviceService.class).getDeviceCount(),
- get(LinkService.class).getLinkCount(),
- get(HostService.class).getHostCount(),
- topologyService.getClusters(topology).size(),
- topology.pathCount(),
- get(FlowRuleService.class).getFlowRuleCount(),
- get(IntentService.class).getIntentCount());
+ if (outputJson()) {
+ print("%s", new ObjectMapper().createObjectNode()
+ .put("node", get(ClusterService.class).getLocalNode().ip().toString())
+ .put("version", get(CoreService.class).version().toString())
+ .put("nodes", get(ClusterService.class).getNodes().size())
+ .put("devices", get(DeviceService.class).getDeviceCount())
+ .put("links", get(LinkService.class).getLinkCount())
+ .put("hosts", get(HostService.class).getHostCount())
+ .put("clusters", topologyService.getClusters(topology).size())
+ .put("paths", topology.pathCount())
+ .put("flows", get(FlowRuleService.class).getFlowRuleCount())
+ .put("intents", get(IntentService.class).getIntentCount()));
+ } else {
+ print("node=%s, version=%s",
+ get(ClusterService.class).getLocalNode().ip(),
+ get(CoreService.class).version().toString());
+ print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d",
+ get(ClusterService.class).getNodes().size(),
+ get(DeviceService.class).getDeviceCount(),
+ get(LinkService.class).getLinkCount(),
+ get(HostService.class).getHostCount(),
+ topologyService.getClusters(topology).size(),
+ topology.pathCount(),
+ get(FlowRuleService.class).getFlowRuleCount(),
+ get(IntentService.class).getIntentCount());
+ }
}
}