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; |
| 5 | import org.onlab.onos.net.topology.TopologyCluster; |
| 6 | |
| 7 | import java.util.Collections; |
| 8 | import java.util.Comparator; |
| 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 | |
| 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 |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 30 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 31 | init(); |
| 32 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); |
| 33 | Collections.sort(clusters, ID_COMPARATOR); |
| 34 | |
| 35 | for (TopologyCluster cluster : clusters) { |
tom | d0344a8 | 2014-09-12 00:20:30 -0700 | [diff] [blame] | 36 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 37 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | } |