blob: 2b2953b32180d8894632f18b08f9ec1d38ab4aee [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;
tom91c7bd02014-09-25 22:50:44 -07005import org.onlab.onos.cli.Comparators;
tom13cb4852014-09-11 12:44:17 -07006import org.onlab.onos.net.topology.TopologyCluster;
7
8import java.util.Collections;
tom13cb4852014-09-11 12:44:17 -07009import 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
tom13cb4852014-09-11 12:44:17 -070021 @Override
tom0872a172014-09-23 11:24:26 -070022 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070023 init();
24 List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
tom1380eee2014-09-24 09:22:02 -070025 Collections.sort(clusters, Comparators.CLUSTER_COMPARATOR);
tom13cb4852014-09-11 12:44:17 -070026
27 for (TopologyCluster cluster : clusters) {
tomd0344a82014-09-12 00:20:30 -070028 print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
tom13cb4852014-09-11 12:44:17 -070029 }
tom13cb4852014-09-11 12:44:17 -070030 }
31
32}