Yuta HIGUCHI
Committed by Gerrit Code Review

Print Port allocations

Change-Id: I590cdcef5d338294e6468e2c4bceb8fa2614b3ab
...@@ -20,7 +20,9 @@ import static org.onosproject.net.DeviceId.deviceId; ...@@ -20,7 +20,9 @@ import static org.onosproject.net.DeviceId.deviceId;
20 import java.util.Arrays; 20 import java.util.Arrays;
21 import java.util.Collections; 21 import java.util.Collections;
22 import java.util.HashSet; 22 import java.util.HashSet;
23 +import java.util.List;
23 import java.util.Set; 24 import java.util.Set;
25 +import java.util.stream.Collectors;
24 import java.util.stream.StreamSupport; 26 import java.util.stream.StreamSupport;
25 27
26 import com.google.common.base.Strings; 28 import com.google.common.base.Strings;
...@@ -53,13 +55,15 @@ import org.onosproject.net.resource.ResourceService; ...@@ -53,13 +55,15 @@ import org.onosproject.net.resource.ResourceService;
53 description = "Lists allocated resources") 55 description = "Lists allocated resources")
54 public class AllocationsCommand extends AbstractShellCommand { 56 public class AllocationsCommand extends AbstractShellCommand {
55 57
56 - @Option(name = "-t", aliases = "--type", description = "List of resource types", 58 + @Option(name = "-t", aliases = "--type",
59 + description = "resource types to include in the list",
57 required = false, multiValued = true) 60 required = false, multiValued = true)
58 String[] typeStrings = null; 61 String[] typeStrings = null;
59 62
60 Set<String> typesToPrint; 63 Set<String> typesToPrint;
61 64
62 - @Option(name = "-i", aliases = "--intentId", description = "Intent ID", 65 + @Option(name = "-i", aliases = "--intentId",
66 + description = "Intent ID to include in the list",
63 required = false, multiValued = true) 67 required = false, multiValued = true)
64 String[] intentStrings; 68 String[] intentStrings;
65 69
...@@ -129,7 +133,21 @@ public class AllocationsCommand extends AbstractShellCommand { ...@@ -129,7 +133,21 @@ public class AllocationsCommand extends AbstractShellCommand {
129 // print DeviceId when Port was directly specified. 133 // print DeviceId when Port was directly specified.
130 print("%s", did); 134 print("%s", did);
131 } 135 }
132 - print("%s%s", Strings.repeat(" ", level), asVerboseString(num)); 136 +
137 + DiscreteResourceId resourceId = Resources.discrete(did, num).id();
138 +
139 + List<String> portConsumers = resourceService.getResourceAllocations(resourceId)
140 + .stream()
141 + .filter(this::isSubjectToPrint)
142 + .map(ResourceAllocation::consumerId)
143 + .map(AllocationsCommand::asVerboseString)
144 + .collect(Collectors.toList());
145 + if (portConsumers.isEmpty()) {
146 + print("%s%s", Strings.repeat(" ", level), asVerboseString(num));
147 + } else {
148 + print("%s%s allocated by %s", Strings.repeat(" ", level), asVerboseString(num),
149 + portConsumers);
150 + }
133 151
134 // FIXME: This workaround induces a lot of distributed store access. 152 // FIXME: This workaround induces a lot of distributed store access.
135 // ResourceService should have an API to get all allocations under a parent resource. 153 // ResourceService should have an API to get all allocations under a parent resource.
...@@ -141,7 +159,6 @@ public class AllocationsCommand extends AbstractShellCommand { ...@@ -141,7 +159,6 @@ public class AllocationsCommand extends AbstractShellCommand {
141 .add(TributarySlot.class) 159 .add(TributarySlot.class)
142 .build(); 160 .build();
143 161
144 - DiscreteResourceId resourceId = Resources.discrete(did, num).id();
145 for (Class<?> t : subResourceTypes) { 162 for (Class<?> t : subResourceTypes) {
146 resourceService.getResourceAllocations(resourceId, t).stream() 163 resourceService.getResourceAllocations(resourceId, t).stream()
147 .filter(a -> isSubjectToPrint(a)) 164 .filter(a -> isSubjectToPrint(a))
......