blob: 2da76fd60e516f34154ef41220626d41c4d8bd71 [file] [log] [blame]
tom1380eee2014-09-24 09:22:02 -07001package org.onlab.onos.cli;
2
3import com.google.common.collect.Lists;
4import org.apache.karaf.shell.commands.Command;
tom1380eee2014-09-24 09:22:02 -07005import org.onlab.onos.cluster.ClusterService;
6import org.onlab.onos.cluster.ControllerNode;
Yuta HIGUCHIfa891c92014-10-09 15:21:40 -07007import org.onlab.onos.cluster.MastershipService;
tom1380eee2014-09-24 09:22:02 -07008import org.onlab.onos.net.DeviceId;
9
10import java.util.Collections;
11import java.util.List;
12
13import 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")
20public class MastersListCommand extends AbstractShellCommand {
21
22 @Override
23 protected void execute() {
24 ClusterService service = get(ClusterService.class);
Yuta HIGUCHIfa891c92014-10-09 15:21:40 -070025 MastershipService mastershipService = get(MastershipService.class);
tom1380eee2014-09-24 09:22:02 -070026 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}