Committed by
Gerrit Code Review
Add method to get available resources filtered by its type
Change-Id: I034bdcf4e9a399af6c68c7ed7f53185bba9b2e27
Showing
6 changed files
with
67 additions
and
13 deletions
... | @@ -163,6 +163,27 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource | ... | @@ -163,6 +163,27 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource |
163 | Set<Resource> getAvailableResources(DiscreteResourceId parent); | 163 | Set<Resource> getAvailableResources(DiscreteResourceId parent); |
164 | 164 | ||
165 | /** | 165 | /** |
166 | + * Returns available resources which are child resources of the specified parent and | ||
167 | + * whose type is the specified type. | ||
168 | + * | ||
169 | + * @param parent parent resource ID | ||
170 | + * @param cls class to specify a type of resource | ||
171 | + * @param <T> type of the resource | ||
172 | + * @return available resources of the specified type under the specified parent resource | ||
173 | + */ | ||
174 | + <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls); | ||
175 | + | ||
176 | + /** | ||
177 | + * Returns available resource values which are the values of the child resource of | ||
178 | + * the specified parent and whose type is the specified type. | ||
179 | + * | ||
180 | + * @param parent parent resource ID | ||
181 | + * @param cls class to specify a type of resource | ||
182 | + * @param <T> type of the resource | ||
183 | + * @return available resource value of the specified type under the specified parent resource | ||
184 | + */ | ||
185 | + <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls); | ||
186 | + /** | ||
166 | * Returns resources registered under the specified resource. | 187 | * Returns resources registered under the specified resource. |
167 | * | 188 | * |
168 | * @param parent parent resource ID | 189 | * @param parent parent resource ID | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onosproject.net.intent.impl.compiler; | ... | @@ -17,7 +17,6 @@ package org.onosproject.net.intent.impl.compiler; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
20 | - | ||
21 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
23 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -27,7 +26,6 @@ import org.onlab.packet.EthType; | ... | @@ -27,7 +26,6 @@ import org.onlab.packet.EthType; |
27 | import org.onlab.packet.Ethernet; | 26 | import org.onlab.packet.Ethernet; |
28 | import org.onlab.packet.MplsLabel; | 27 | import org.onlab.packet.MplsLabel; |
29 | import org.onlab.packet.VlanId; | 28 | import org.onlab.packet.VlanId; |
30 | -import org.onlab.util.Tools; | ||
31 | import org.onosproject.core.ApplicationId; | 29 | import org.onosproject.core.ApplicationId; |
32 | import org.onosproject.core.CoreService; | 30 | import org.onosproject.core.CoreService; |
33 | import org.onosproject.net.ConnectPoint; | 31 | import org.onosproject.net.ConnectPoint; |
... | @@ -158,9 +156,9 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -158,9 +156,9 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
158 | } | 156 | } |
159 | 157 | ||
160 | private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { | 158 | private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { |
161 | - return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).id()).stream() | 159 | + return resourceService.getAvailableResourceValues( |
162 | - .flatMap(x -> Tools.stream(x.valueAs(MplsLabel.class))) | 160 | + Resources.discrete(cp.deviceId(), cp.port()).id(), |
163 | - .collect(Collectors.toSet()); | 161 | + MplsLabel.class); |
164 | } | 162 | } |
165 | 163 | ||
166 | private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) { | 164 | private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) { | ... | ... |
... | @@ -24,7 +24,6 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -24,7 +24,6 @@ import org.apache.felix.scr.annotations.Deactivate; |
24 | import org.apache.felix.scr.annotations.Reference; | 24 | import org.apache.felix.scr.annotations.Reference; |
25 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
26 | import org.onlab.util.Frequency; | 26 | import org.onlab.util.Frequency; |
27 | -import org.onlab.util.Tools; | ||
28 | import org.onosproject.net.AnnotationKeys; | 27 | import org.onosproject.net.AnnotationKeys; |
29 | import org.onosproject.net.ChannelSpacing; | 28 | import org.onosproject.net.ChannelSpacing; |
30 | import org.onosproject.net.ConnectPoint; | 29 | import org.onosproject.net.ConnectPoint; |
... | @@ -217,9 +216,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -217,9 +216,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
217 | Resources.discrete(x.src().deviceId(), x.src().port()).id(), | 216 | Resources.discrete(x.src().deviceId(), x.src().port()).id(), |
218 | Resources.discrete(x.dst().deviceId(), x.dst().port()).id() | 217 | Resources.discrete(x.dst().deviceId(), x.dst().port()).id() |
219 | )) | 218 | )) |
220 | - .map(resourceService::getAvailableResources) | 219 | + .map(x -> resourceService.getAvailableResourceValues(x, OchSignal.class)) |
221 | - .map(x -> x.stream() | ||
222 | - .flatMap(r -> Tools.stream(r.valueAs(OchSignal.class))).collect(Collectors.toList())) | ||
223 | .map(x -> (Set<OchSignal>) ImmutableSet.copyOf(x)) | 220 | .map(x -> (Set<OchSignal>) ImmutableSet.copyOf(x)) |
224 | .reduce(Sets::intersection) | 221 | .reduce(Sets::intersection) |
225 | .orElse(Collections.emptySet()); | 222 | .orElse(Collections.emptySet()); | ... | ... |
... | @@ -23,7 +23,6 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -23,7 +23,6 @@ import org.apache.felix.scr.annotations.Deactivate; |
23 | import org.apache.felix.scr.annotations.Reference; | 23 | import org.apache.felix.scr.annotations.Reference; |
24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.onlab.packet.VlanId; | 25 | import org.onlab.packet.VlanId; |
26 | -import org.onlab.util.Tools; | ||
27 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
28 | import org.onosproject.core.CoreService; | 27 | import org.onosproject.core.CoreService; |
29 | import org.onosproject.net.ConnectPoint; | 28 | import org.onosproject.net.ConnectPoint; |
... | @@ -299,9 +298,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { | ... | @@ -299,9 +298,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { |
299 | } | 298 | } |
300 | 299 | ||
301 | private Set<VlanId> findVlanId(ConnectPoint cp) { | 300 | private Set<VlanId> findVlanId(ConnectPoint cp) { |
302 | - return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).id()).stream() | 301 | + return resourceService.getAvailableResourceValues( |
303 | - .flatMap(x -> Tools.stream(x.valueAs(VlanId.class))) | 302 | + Resources.discrete(cp.deviceId(), cp.port()).id(), |
304 | - .collect(Collectors.toSet()); | 303 | + VlanId.class); |
305 | } | 304 | } |
306 | 305 | ||
307 | private boolean isLast(List<Link> links, int i) { | 306 | private boolean isLast(List<Link> links, int i) { | ... | ... |
... | @@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Reference; |
24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.apache.felix.scr.annotations.Service; | 25 | import org.apache.felix.scr.annotations.Service; |
26 | import org.onlab.util.GuavaCollectors; | 26 | import org.onlab.util.GuavaCollectors; |
27 | +import org.onlab.util.Tools; | ||
27 | import org.onosproject.event.AbstractListenerManager; | 28 | import org.onosproject.event.AbstractListenerManager; |
28 | import org.onosproject.net.newresource.DiscreteResourceId; | 29 | import org.onosproject.net.newresource.DiscreteResourceId; |
29 | import org.onosproject.net.newresource.ResourceAdminService; | 30 | import org.onosproject.net.newresource.ResourceAdminService; |
... | @@ -150,6 +151,28 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent | ... | @@ -150,6 +151,28 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent |
150 | } | 151 | } |
151 | 152 | ||
152 | @Override | 153 | @Override |
154 | + public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) { | ||
155 | + checkNotNull(parent); | ||
156 | + checkNotNull(cls); | ||
157 | + | ||
158 | + // naive implementation | ||
159 | + return getAvailableResources(parent).stream() | ||
160 | + .filter(resource -> resource.isTypeOf(cls)) | ||
161 | + .collect(Collectors.toSet()); | ||
162 | + } | ||
163 | + | ||
164 | + @Override | ||
165 | + public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) { | ||
166 | + checkNotNull(parent); | ||
167 | + checkNotNull(cls); | ||
168 | + | ||
169 | + // naive implementation | ||
170 | + return getAvailableResources(parent).stream() | ||
171 | + .flatMap(resource -> Tools.stream(resource.valueAs(cls))) | ||
172 | + .collect(Collectors.toSet()); | ||
173 | + } | ||
174 | + | ||
175 | + @Override | ||
153 | public Set<Resource> getRegisteredResources(DiscreteResourceId parent) { | 176 | public Set<Resource> getRegisteredResources(DiscreteResourceId parent) { |
154 | checkNotNull(parent); | 177 | checkNotNull(parent); |
155 | 178 | ... | ... |
... | @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; | ... | @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; |
19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
20 | import org.onlab.packet.MplsLabel; | 20 | import org.onlab.packet.MplsLabel; |
21 | import org.onlab.packet.VlanId; | 21 | import org.onlab.packet.VlanId; |
22 | +import org.onlab.util.Tools; | ||
22 | import org.onosproject.net.newresource.ContinuousResourceId; | 23 | import org.onosproject.net.newresource.ContinuousResourceId; |
23 | import org.onosproject.net.newresource.DiscreteResource; | 24 | import org.onosproject.net.newresource.DiscreteResource; |
24 | import org.onosproject.net.newresource.DiscreteResourceId; | 25 | import org.onosproject.net.newresource.DiscreteResourceId; |
... | @@ -111,6 +112,21 @@ class MockResourceService implements ResourceService { | ... | @@ -111,6 +112,21 @@ class MockResourceService implements ResourceService { |
111 | } | 112 | } |
112 | 113 | ||
113 | @Override | 114 | @Override |
115 | + public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) { | ||
116 | + return getAvailableResources(parent).stream() | ||
117 | + .filter(x -> x.isTypeOf(cls)) | ||
118 | + .collect(Collectors.toSet()); | ||
119 | + } | ||
120 | + | ||
121 | + @Override | ||
122 | + public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) { | ||
123 | + return getAvailableResources(parent).stream() | ||
124 | + .filter(x -> x.isTypeOf(cls)) | ||
125 | + .flatMap(x -> Tools.stream(x.valueAs(cls))) | ||
126 | + .collect(Collectors.toSet()); | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
114 | public Set<Resource> getRegisteredResources(DiscreteResourceId parent) { | 130 | public Set<Resource> getRegisteredResources(DiscreteResourceId parent) { |
115 | return getAvailableResources(parent); | 131 | return getAvailableResources(parent); |
116 | } | 132 | } | ... | ... |
-
Please register or login to post a comment