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/net/ClustersListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
index 2b2953b..f41f85e 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
@@ -1,5 +1,8 @@
package org.onlab.onos.cli.net;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.Comparators;
@@ -24,9 +27,26 @@
List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
Collections.sort(clusters, Comparators.CLUSTER_COMPARATOR);
- for (TopologyCluster cluster : clusters) {
- print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
+ if (outputJson()) {
+ print("%s", json(clusters));
+ } else {
+ for (TopologyCluster cluster : clusters) {
+ print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
+ }
}
}
+ // Produces a JSON result.
+ private JsonNode json(Iterable<TopologyCluster> clusters) {
+ ObjectMapper mapper = new ObjectMapper();
+ ArrayNode result = mapper.createArrayNode();
+ for (TopologyCluster cluster : clusters) {
+ result.add(mapper.createObjectNode()
+ .put("id", cluster.id().index())
+ .put("deviceCount", cluster.deviceCount())
+ .put("linkCount", cluster.linkCount()));
+ }
+ return result;
+ }
+
}