blob: d2d452f18ed7f87955df0dcc5703ac28f81eb879 [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;
tom13cb4852014-09-11 12:44:17 -07008import java.util.List;
9
10/**
11 * Lists all clusters in the current topology.
12 */
13@Command(scope = "onos", name = "clusters",
14 description = "Lists all clusters in the current topology")
15public class ClustersListCommand extends TopologyCommand {
16
17 private static final String FMT =
tomd0344a82014-09-12 00:20:30 -070018 "id=%d, devices=%d, links=%d";
tom13cb4852014-09-11 12:44:17 -070019
tom13cb4852014-09-11 12:44:17 -070020 @Override
tom0872a172014-09-23 11:24:26 -070021 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070022 init();
23 List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
tom1380eee2014-09-24 09:22:02 -070024 Collections.sort(clusters, Comparators.CLUSTER_COMPARATOR);
tom13cb4852014-09-11 12:44:17 -070025
26 for (TopologyCluster cluster : clusters) {
tomd0344a82014-09-12 00:20:30 -070027 print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount());
tom13cb4852014-09-11 12:44:17 -070028 }
tom13cb4852014-09-11 12:44:17 -070029 }
30
31}