blob: 355825b59f02f62a6b45f3654f99ee12b4ded160 [file] [log] [blame]
tom13cb4852014-09-11 12:44:17 -07001package org.onlab.onos.cli.net;
2
3import com.google.common.collect.Lists;
4import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.net.topology.TopologyCluster;
6
7import java.util.Collections;
8import java.util.Comparator;
9import java.util.List;
10
11/**
12 * Lists all clusters in the current topology.
13 */
14@Command(scope = "onos", name = "clusters",
15 description = "Lists all clusters in the current topology")
16public class ClustersListCommand extends TopologyCommand {
17
18 private static final String FMT =
19 "id=%s, devices=%d, links=%d";
20
21 protected static final Comparator<TopologyCluster> ID_COMPARATOR =
22 new Comparator<TopologyCluster>() {
23 @Override
24 public int compare(TopologyCluster c1, TopologyCluster c2) {
25 return c1.id().index() - c2.id().index();
26 }
27 };
28
29 @Override
30 protected Object doExecute() throws Exception {
31 init();
32 List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
33 Collections.sort(clusters, ID_COMPARATOR);
34
35 for (TopologyCluster cluster : clusters) {
36 print(FMT, cluster.id(), cluster.deviceCount(), cluster.linkCount());
37 }
38 return null;
39 }
40
41}