diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java index 1e24cb90bd..b17f944077 100644 --- a/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java +++ b/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java @@ -172,10 +172,18 @@ public class ResourcesCommand extends AbstractShellCommand { List nonAggregatable = new ArrayList<>(); for (Resource r : children) { - if (!isPrintTarget(r)) { + if (!isPrintTarget(r)) { // A continue; } + if (r instanceof DiscreteResource) { + + if (resourceService.getRegisteredResources(((DiscreteResource) r).id()).isEmpty()) { + // resource which has children should be printed + continue; + } + } + if (r instanceof ContinuousResource) { // non-aggregatable terminal node nonAggregatable.add(r); @@ -188,6 +196,7 @@ public class ResourcesCommand extends AbstractShellCommand { } } + // print aggregated (terminal) aggregatables.asMap().entrySet() .forEach(e -> { @@ -236,12 +245,7 @@ public class ResourcesCommand extends AbstractShellCommand { String resourceName = resource.simpleTypeName(); if (resource instanceof DiscreteResource) { - // TODO This distributed store access incurs overhead. - // This should be merged with the one in printResource() - if (!resourceService.getRegisteredResources(((DiscreteResource) resource).id()).isEmpty()) { - // resource which has children should be printed - return true; - } + if (availablesOnly && !resourceService.isAvailable(resource)) { // don't print unavailable discrete resource return false; @@ -250,7 +254,6 @@ public class ResourcesCommand extends AbstractShellCommand { log.warn("Unexpected resource class: {}", resource.getClass().getSimpleName()); return false; } - return typesToPrint.contains(resourceName); } }