blob: 020179e55f369e25891378a29056bc3137b1c09f [file] [log] [blame]
tome4729872014-09-23 00:37:37 -07001package org.onlab.onos.cli;
2
3import org.apache.karaf.shell.commands.Command;
tom1380eee2014-09-24 09:22:02 -07004import org.onlab.onos.cli.net.Comparators;
tome4729872014-09-23 00:37:37 -07005import org.onlab.onos.cluster.ClusterService;
6import org.onlab.onos.cluster.ControllerNode;
7
8import java.util.Collections;
tome4729872014-09-23 00:37:37 -07009import java.util.List;
10
11import static com.google.common.collect.Lists.newArrayList;
12
13/**
14 * Lists all controller cluster nodes.
15 */
16@Command(scope = "onos", name = "nodes",
17 description = "Lists all controller cluster nodes")
18public class NodesListCommand extends AbstractShellCommand {
19
20 private static final String FMT =
21 "id=%s, ip=%s, state=%s %s";
22
tome4729872014-09-23 00:37:37 -070023 @Override
tom0872a172014-09-23 11:24:26 -070024 protected void execute() {
25 ClusterService service = get(ClusterService.class);
tome4729872014-09-23 00:37:37 -070026 List<ControllerNode> nodes = newArrayList(service.getNodes());
tom1380eee2014-09-24 09:22:02 -070027 Collections.sort(nodes, Comparators.NODE_COMPARATOR);
tome4729872014-09-23 00:37:37 -070028 ControllerNode self = service.getLocalNode();
29 for (ControllerNode node : nodes) {
30 print(FMT, node.id(), node.ip(),
31 service.getState(node.id()),
32 node.equals(self) ? "*" : "");
33 }
tome4729872014-09-23 00:37:37 -070034 }
35
36}