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