blob: fe67348cc081747bfaa3551cbc398eb8d9166c16 [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 =
tomd0344a82014-09-12 00:20:30 -070019 "id=%d, devices=%d, links=%d";
tom13cb4852014-09-11 12:44:17 -070020
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
tom0872a172014-09-23 11:24:26 -070030 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070031 init();
32 List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
33 Collections.sort(clusters, ID_COMPARATOR);
34
35 for (TopologyCluster cluster : clusters) {
tomd0344a82014-09-12 00:20:30 -070036 print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
tom13cb4852014-09-11 12:44:17 -070037 }
tom13cb4852014-09-11 12:44:17 -070038 }
39
40}