Committed by
Gerrit Code Review
ONOS-434 - Filter out inactive nodes from the summary information in the CLI
Change-Id: Ifd25005ea2ce2f00555fe6820a7aa2febde2daee
Showing
1 changed file
with
23 additions
and
1 deletions
| ... | @@ -15,8 +15,11 @@ | ... | @@ -15,8 +15,11 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.cli; | 16 | package org.onosproject.cli; |
| 17 | 17 | ||
| 18 | +import java.util.Set; | ||
| 19 | + | ||
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import org.apache.karaf.shell.commands.Command; | 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | +import org.onosproject.cluster.ControllerNode; | ||
| 20 | import org.onosproject.core.CoreService; | 23 | import org.onosproject.core.CoreService; |
| 21 | import org.onosproject.cluster.ClusterService; | 24 | import org.onosproject.cluster.ClusterService; |
| 22 | import org.onosproject.net.device.DeviceService; | 25 | import org.onosproject.net.device.DeviceService; |
| ... | @@ -34,6 +37,25 @@ import org.onosproject.net.topology.TopologyService; | ... | @@ -34,6 +37,25 @@ import org.onosproject.net.topology.TopologyService; |
| 34 | description = "Provides summary of ONOS model") | 37 | description = "Provides summary of ONOS model") |
| 35 | public class SummaryCommand extends AbstractShellCommand { | 38 | public class SummaryCommand extends AbstractShellCommand { |
| 36 | 39 | ||
| 40 | + /** | ||
| 41 | + * Count the active ONOS controller nodes. | ||
| 42 | + * | ||
| 43 | + * @param nodes set of all of the controller nodes in the cluster | ||
| 44 | + * @return count of active nodes | ||
| 45 | + */ | ||
| 46 | + private int activeNodes(Set<ControllerNode> nodes) { | ||
| 47 | + int nodeCount = 0; | ||
| 48 | + | ||
| 49 | + for (final ControllerNode node : nodes) { | ||
| 50 | + final ControllerNode.State nodeState = | ||
| 51 | + get(ClusterService.class).getState(node.id()); | ||
| 52 | + if (nodeState == ControllerNode.State.ACTIVE) { | ||
| 53 | + nodeCount++; | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + return nodeCount; | ||
| 57 | + } | ||
| 58 | + | ||
| 37 | @Override | 59 | @Override |
| 38 | protected void execute() { | 60 | protected void execute() { |
| 39 | TopologyService topologyService = get(TopologyService.class); | 61 | TopologyService topologyService = get(TopologyService.class); |
| ... | @@ -55,7 +77,7 @@ public class SummaryCommand extends AbstractShellCommand { | ... | @@ -55,7 +77,7 @@ public class SummaryCommand extends AbstractShellCommand { |
| 55 | get(ClusterService.class).getLocalNode().ip(), | 77 | get(ClusterService.class).getLocalNode().ip(), |
| 56 | get(CoreService.class).version().toString()); | 78 | get(CoreService.class).version().toString()); |
| 57 | print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, paths=%d, flows=%d, intents=%d", | 79 | print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, paths=%d, flows=%d, intents=%d", |
| 58 | - get(ClusterService.class).getNodes().size(), | 80 | + activeNodes(get(ClusterService.class).getNodes()), |
| 59 | get(DeviceService.class).getDeviceCount(), | 81 | get(DeviceService.class).getDeviceCount(), |
| 60 | get(LinkService.class).getLinkCount(), | 82 | get(LinkService.class).getLinkCount(), |
| 61 | get(HostService.class).getHostCount(), | 83 | get(HostService.class).getHostCount(), | ... | ... |
-
Please register or login to post a comment