Add method to get available resources filtered by its type
Change-Id: I034bdcf4e9a399af6c68c7ed7f53185bba9b2e27
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
index 71ae925..28b8a04 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
@@ -17,7 +17,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
-
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -27,7 +26,6 @@
import org.onlab.packet.Ethernet;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
-import org.onlab.util.Tools;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
@@ -158,9 +156,9 @@
}
private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
- return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).id()).stream()
- .flatMap(x -> Tools.stream(x.valueAs(MplsLabel.class)))
- .collect(Collectors.toSet());
+ return resourceService.getAvailableResourceValues(
+ Resources.discrete(cp.deviceId(), cp.port()).id(),
+ MplsLabel.class);
}
private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) {
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index b113b07..0430f99 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -24,7 +24,6 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.util.Frequency;
-import org.onlab.util.Tools;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.ConnectPoint;
@@ -217,9 +216,7 @@
Resources.discrete(x.src().deviceId(), x.src().port()).id(),
Resources.discrete(x.dst().deviceId(), x.dst().port()).id()
))
- .map(resourceService::getAvailableResources)
- .map(x -> x.stream()
- .flatMap(r -> Tools.stream(r.valueAs(OchSignal.class))).collect(Collectors.toList()))
+ .map(x -> resourceService.getAvailableResourceValues(x, OchSignal.class))
.map(x -> (Set<OchSignal>) ImmutableSet.copyOf(x))
.reduce(Sets::intersection)
.orElse(Collections.emptySet());
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
index a86138a..7d6edcb 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
@@ -23,7 +23,6 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.VlanId;
-import org.onlab.util.Tools;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
@@ -299,9 +298,9 @@
}
private Set<VlanId> findVlanId(ConnectPoint cp) {
- return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).id()).stream()
- .flatMap(x -> Tools.stream(x.valueAs(VlanId.class)))
- .collect(Collectors.toSet());
+ return resourceService.getAvailableResourceValues(
+ Resources.discrete(cp.deviceId(), cp.port()).id(),
+ VlanId.class);
}
private boolean isLast(List<Link> links, int i) {
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
index 1138fd6..88c3ab6 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
@@ -24,6 +24,7 @@
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.GuavaCollectors;
+import org.onlab.util.Tools;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.net.newresource.DiscreteResourceId;
import org.onosproject.net.newresource.ResourceAdminService;
@@ -150,6 +151,28 @@
}
@Override
+ public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) {
+ checkNotNull(parent);
+ checkNotNull(cls);
+
+ // naive implementation
+ return getAvailableResources(parent).stream()
+ .filter(resource -> resource.isTypeOf(cls))
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) {
+ checkNotNull(parent);
+ checkNotNull(cls);
+
+ // naive implementation
+ return getAvailableResources(parent).stream()
+ .flatMap(resource -> Tools.stream(resource.valueAs(cls)))
+ .collect(Collectors.toSet());
+ }
+
+ @Override
public Set<Resource> getRegisteredResources(DiscreteResourceId parent) {
checkNotNull(parent);