Replace method call of DeviceResourceService with that of ResourceService
Change-Id: I7a0400652cd43831a3fff4c0dc73fbe79d4eb633
diff --git a/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java b/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
index 5981e08..d72dab9 100644
--- a/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
+++ b/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
@@ -45,6 +45,7 @@
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.device.DeviceResourceService;
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.onosproject.net.resource.link.LinkResourceService;
@@ -102,6 +103,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkResourceService linkResourceService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ResourceService resourceService;
+
private ApplicationId appId;
private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
@@ -375,12 +379,12 @@
private void releaseResources(Intent intent) {
LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id());
if (intent instanceof OpticalConnectivityIntent) {
- deviceResourceService.releasePorts(intent.id());
+ resourceService.release(intent.id());
if (lra != null) {
linkResourceService.releaseResources(lra);
}
} else if (intent instanceof OpticalCircuitIntent) {
- deviceResourceService.releasePorts(intent.id());
+ resourceService.release(intent.id());
deviceResourceService.releaseMapping(intent.id());
if (lra != null) {
linkResourceService.releaseResources(lra);
diff --git a/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceService.java b/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceService.java
index 5468dfb..0fdaa15 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceService.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceService.java
@@ -16,8 +16,6 @@
package org.onosproject.net.resource.device;
import com.google.common.annotations.Beta;
-import org.onosproject.net.Port;
-import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentId;
import java.util.Set;
@@ -27,30 +25,6 @@
*/
@Beta
public interface DeviceResourceService {
- /**
- * Request a set of ports needed to satisfy the intent.
- *
- * @param ports set of ports to allocate
- * @param intent the intent
- * @return true if ports were successfully allocated, false otherwise
- */
- boolean requestPorts(Set<Port> ports, Intent intent);
-
- /**
- * Returns the set of ports allocated for an intent.
- *
- * @param intentId the intent ID
- * @return set of allocated ports
- */
- Set<Port> getAllocations(IntentId intentId);
-
- /**
- * Returns the intent allocated to a port.
- *
- * @param port the port
- * @return intent ID allocated to the port
- */
- IntentId getAllocations(Port port);
/**
* Request a mapping between the given intents.
@@ -75,11 +49,4 @@
* @param intentId intent ID
*/
void releaseMapping(IntentId intentId);
-
- /**
- * Release ports associated with given intent ID.
- *
- * @param intentId intent ID
- */
- void releasePorts(IntentId intentId);
}
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;
}
}
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 60db797..b2403c6 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
@@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -40,6 +39,8 @@
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalPathIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
+import org.onosproject.net.newresource.ResourcePath;
+import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.ResourceType;
import org.onosproject.net.resource.device.DeviceResourceService;
import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
@@ -78,6 +79,9 @@
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ResourceService resourceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkResourceService linkResourceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -108,7 +112,11 @@
log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
// Reserve OCh ports
- if (!deviceResourceService.requestPorts(ImmutableSet.of(srcPort, dstPort), intent)) {
+ ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port());
+ ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port());
+ List<org.onosproject.net.newresource.ResourceAllocation> allocation =
+ resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
+ if (allocation.isEmpty()) {
throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
}
@@ -161,7 +169,7 @@
}
// Release port allocations if unsuccessful
- deviceResourceService.releasePorts(intent.id());
+ resourceService.release(intent.id());
throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
diff --git a/core/net/src/main/java/org/onosproject/net/resource/impl/DeviceResourceManager.java b/core/net/src/main/java/org/onosproject/net/resource/impl/DeviceResourceManager.java
index 52c39f2..f6dbc60 100644
--- a/core/net/src/main/java/org/onosproject/net/resource/impl/DeviceResourceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/resource/impl/DeviceResourceManager.java
@@ -21,8 +21,6 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
-import org.onosproject.net.Port;
-import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.resource.device.DeviceResourceService;
import org.onosproject.net.resource.device.DeviceResourceStore;
@@ -30,7 +28,6 @@
import java.util.Set;
-import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -56,23 +53,6 @@
}
@Override
- public boolean requestPorts(Set<Port> ports, Intent intent) {
- checkNotNull(intent);
-
- return store.allocatePorts(ports, intent.id());
- }
-
- @Override
- public Set<Port> getAllocations(IntentId intentId) {
- return store.getAllocations(intentId);
- }
-
- @Override
- public IntentId getAllocations(Port port) {
- return store.getAllocations(port);
- }
-
- @Override
public void releaseMapping(IntentId intentId) {
store.releaseMapping(intentId);
}
@@ -86,9 +66,4 @@
public Set<IntentId> getMapping(IntentId intentId) {
return store.getMapping(intentId);
}
-
- @Override
- public void releasePorts(IntentId intentId) {
- store.releasePorts(intentId);
- }
}