Naoki Shiota
Committed by Gerrit Code Review

bug fix: resources CLI command with -t(type) option didn't work for ContinuousResource.

Change-Id: Ib1443e2a5395c7f75ef3da583019978aab4a742a
...@@ -36,6 +36,7 @@ import org.onosproject.net.TributarySlot; ...@@ -36,6 +36,7 @@ import org.onosproject.net.TributarySlot;
36 import org.onosproject.net.newresource.ContinuousResource; 36 import org.onosproject.net.newresource.ContinuousResource;
37 import org.onosproject.net.newresource.DiscreteResource; 37 import org.onosproject.net.newresource.DiscreteResource;
38 import org.onosproject.net.newresource.Resource; 38 import org.onosproject.net.newresource.Resource;
39 +import org.onosproject.net.newresource.Resources;
39 import org.onosproject.net.newresource.ResourceService; 40 import org.onosproject.net.newresource.ResourceService;
40 41
41 import com.google.common.base.Strings; 42 import com.google.common.base.Strings;
...@@ -46,7 +47,6 @@ import com.google.common.collect.Multimap; ...@@ -46,7 +47,6 @@ import com.google.common.collect.Multimap;
46 import com.google.common.collect.Range; 47 import com.google.common.collect.Range;
47 import com.google.common.collect.RangeSet; 48 import com.google.common.collect.RangeSet;
48 import com.google.common.collect.TreeRangeSet; 49 import com.google.common.collect.TreeRangeSet;
49 -import org.onosproject.net.newresource.Resources;
50 50
51 /** 51 /**
52 * Lists available resources. 52 * Lists available resources.
...@@ -113,14 +113,6 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -113,14 +113,6 @@ public class ResourcesCommand extends AbstractShellCommand {
113 if (resource.equals(Resource.ROOT)) { 113 if (resource.equals(Resource.ROOT)) {
114 print("ROOT"); 114 print("ROOT");
115 } else { 115 } else {
116 - String resourceName = resource.last().getClass().getSimpleName();
117 -
118 - if (children.isEmpty() && !typesToPrint.isEmpty() && !typesToPrint.contains(resourceName)) {
119 - // This resource is target of filtering
120 - return;
121 - }
122 -
123 -
124 if (resource instanceof ContinuousResource) { 116 if (resource instanceof ContinuousResource) {
125 String s = ((String) resource.last()); 117 String s = ((String) resource.last());
126 String simpleName = s.substring(s.lastIndexOf('.') + 1); 118 String simpleName = s.substring(s.lastIndexOf('.') + 1);
...@@ -133,6 +125,7 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -133,6 +125,7 @@ public class ResourcesCommand extends AbstractShellCommand {
133 // Continuous resource is terminal node, stop here 125 // Continuous resource is terminal node, stop here
134 return; 126 return;
135 } else { 127 } else {
128 + String resourceName = resource.last().getClass().getSimpleName();
136 129
137 String toString = String.valueOf(resource.last()); 130 String toString = String.valueOf(resource.last());
138 if (toString.startsWith(resourceName)) { 131 if (toString.startsWith(resourceName)) {
...@@ -158,15 +151,17 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -158,15 +151,17 @@ public class ResourcesCommand extends AbstractShellCommand {
158 List<Resource> nonAggregatable = new ArrayList<>(); 151 List<Resource> nonAggregatable = new ArrayList<>();
159 152
160 for (Resource r : children) { 153 for (Resource r : children) {
154 + if (!isPrintTarget(r)) {
155 + continue;
156 + }
157 +
161 if (r instanceof ContinuousResource) { 158 if (r instanceof ContinuousResource) {
162 // non-aggregatable terminal node 159 // non-aggregatable terminal node
163 nonAggregatable.add(r); 160 nonAggregatable.add(r);
164 } else if (aggregatableTypes.contains(r.last().getClass())) { 161 } else if (aggregatableTypes.contains(r.last().getClass())) {
165 // aggregatable & terminal node 162 // aggregatable & terminal node
166 String className = r.last().getClass().getSimpleName(); 163 String className = r.last().getClass().getSimpleName();
167 - if (typesToPrint.isEmpty() || typesToPrint.contains(className)) {
168 aggregatables.put(className, r); 164 aggregatables.put(className, r);
169 - }
170 } else { 165 } else {
171 nonAggregatable.add(r); 166 nonAggregatable.add(r);
172 } 167 }
...@@ -213,4 +208,29 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -213,4 +208,29 @@ public class ResourcesCommand extends AbstractShellCommand {
213 nonAggregatable.forEach(r -> printResource(r, level + 1)); 208 nonAggregatable.forEach(r -> printResource(r, level + 1));
214 } 209 }
215 } 210 }
211 +
212 + private boolean isPrintTarget(Resource resource) {
213 + if (typesToPrint.isEmpty()) {
214 + return true;
215 + }
216 +
217 + String resourceName;
218 + if (resource instanceof ContinuousResource) {
219 + String s = (String) resource.last();
220 + resourceName = s.substring(s.lastIndexOf('.') + 1);
221 + } else if (resource instanceof DiscreteResource) {
222 + // TODO This distributed store access incurs overhead.
223 + // This should be merged with the one in printResource()
224 + if (!resourceService.getRegisteredResources(((DiscreteResource) resource).id()).isEmpty()) {
225 + // resource which has children should be printed
226 + return true;
227 + }
228 + resourceName = resource.last().getClass().getSimpleName();
229 + } else {
230 + log.warn("Unexpected resource class: {}", resource.getClass().getSimpleName());
231 + return false;
232 + }
233 +
234 + return typesToPrint.contains(resourceName);
235 + }
216 } 236 }
......