tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import com.google.common.collect.Lists; |
| 4 | import org.apache.karaf.shell.commands.Command; |
tom | 91c7bd0 | 2014-09-25 22:50:44 -0700 | [diff] [blame^] | 5 | import org.onlab.onos.cli.Comparators; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 6 | import org.onlab.onos.net.topology.TopologyCluster; |
| 7 | |
| 8 | import java.util.Collections; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 9 | import 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") |
| 16 | public class ClustersListCommand extends TopologyCommand { |
| 17 | |
| 18 | private static final String FMT = |
tom | d0344a8 | 2014-09-12 00:20:30 -0700 | [diff] [blame] | 19 | "id=%d, devices=%d, links=%d"; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 20 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 21 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 22 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 23 | init(); |
| 24 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 25 | Collections.sort(clusters, Comparators.CLUSTER_COMPARATOR); |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 26 | |
| 27 | for (TopologyCluster cluster : clusters) { |
tom | d0344a8 | 2014-09-12 00:20:30 -0700 | [diff] [blame] | 28 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 29 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | } |