tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli; |
| 2 | |
| 3 | import com.google.common.collect.Lists; |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 4 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 5 | import org.apache.karaf.shell.commands.Command; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 6 | import org.onlab.onos.cluster.ClusterService; |
| 7 | import org.onlab.onos.cluster.ControllerNode; |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 8 | import org.onlab.onos.mastership.MastershipService; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 9 | import org.onlab.onos.net.DeviceId; |
| 10 | |
| 11 | import java.util.Collections; |
| 12 | import java.util.List; |
| 13 | |
| 14 | import static com.google.common.collect.Lists.newArrayList; |
| 15 | |
| 16 | /** |
| 17 | * Lists device mastership information. |
| 18 | */ |
| 19 | @Command(scope = "onos", name = "masters", |
| 20 | description = "Lists device mastership information") |
| 21 | public class MastersListCommand extends AbstractShellCommand { |
| 22 | |
| 23 | @Override |
| 24 | protected void execute() { |
| 25 | ClusterService service = get(ClusterService.class); |
| 26 | MastershipService mastershipService = get(MastershipService.class); |
| 27 | List<ControllerNode> nodes = newArrayList(service.getNodes()); |
| 28 | Collections.sort(nodes, Comparators.NODE_COMPARATOR); |
| 29 | ControllerNode self = service.getLocalNode(); |
| 30 | for (ControllerNode node : nodes) { |
| 31 | List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id())); |
| 32 | Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR); |
| 33 | print("%s: %d devices", node.id(), ids.size()); |
| 34 | for (DeviceId deviceId : ids) { |
| 35 | print(" %s", deviceId); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | } |