Replace method call of DeviceResourceService with that of ResourceService
Change-Id: I7a0400652cd43831a3fff4c0dc73fbe79d4eb633
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
index 5aa143a..de41acf 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.net.intent.impl.compiler;
-import com.google.common.collect.Sets;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -50,6 +49,9 @@
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
+import org.onosproject.net.newresource.ResourceAllocation;
+import org.onosproject.net.newresource.ResourcePath;
+import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.device.DeviceResourceService;
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.osgi.service.component.ComponentContext;
@@ -60,6 +62,7 @@
import java.util.Dictionary;
import java.util.LinkedList;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
@@ -92,6 +95,9 @@
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ResourceService resourceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceResourceService deviceResourceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -153,7 +159,10 @@
log.debug("Compiling optical circuit intent between {} and {}", src, dst);
// Reserve OduClt ports
- if (!deviceResourceService.requestPorts(Sets.newHashSet(srcPort, dstPort), intent)) {
+ ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port());
+ ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port());
+ List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
+ if (allocation.isEmpty()) {
throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
}
@@ -301,8 +310,13 @@
if (ochCP != null) {
OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
- IntentId intentId = deviceResourceService.getAllocations(ochPort);
- if (isAvailable(intentId)) {
+ Optional<IntentId> intentId =
+ resourceService.getResourceAllocation(new ResourcePath(ochCP.deviceId(), ochCP.port()))
+ .map(ResourceAllocation::consumer)
+ .filter(x -> x instanceof IntentId)
+ .map(x -> (IntentId) x);
+
+ if (isAvailable(intentId.orElse(null))) {
return ochPort;
}
}
@@ -315,8 +329,12 @@
continue;
}
- IntentId intentId = deviceResourceService.getAllocations(port);
- if (isAvailable(intentId)) {
+ Optional<IntentId> intentId =
+ resourceService.getResourceAllocation(new ResourcePath(oduPort.deviceId(), port.number()))
+ .map(ResourceAllocation::consumer)
+ .filter(x -> x instanceof IntentId)
+ .map(x -> (IntentId) x);
+ if (isAvailable(intentId.orElse(null))) {
return (OchPort) port;
}
}