Sho SHIMIZU
Committed by Gerrit Code Review

Replace method call of DeviceResourceService with that of ResourceService

Change-Id: I7a0400652cd43831a3fff4c0dc73fbe79d4eb633
......@@ -45,6 +45,7 @@ import org.onosproject.net.intent.IntentState;
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 @@ public class OpticalPathProvisioner {
@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 @@ public class OpticalPathProvisioner {
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);
......
......@@ -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 @@ import java.util.Set;
*/
@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 @@ public interface DeviceResourceService {
* @param intentId intent ID
*/
void releaseMapping(IntentId intentId);
/**
* Release ports associated with given intent ID.
*
* @param intentId intent ID
*/
void releasePorts(IntentId intentId);
}
......
......@@ -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.IntentService;
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.Collections;
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 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
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 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
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 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
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 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
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;
}
}
......
......@@ -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.IntentExtensionService;
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 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
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 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
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 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
}
// Release port allocations if unsuccessful
deviceResourceService.releasePorts(intent.id());
resourceService.release(intent.id());
throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
......
......@@ -21,8 +21,6 @@ import org.apache.felix.scr.annotations.Deactivate;
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 org.slf4j.Logger;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -56,23 +53,6 @@ public class DeviceResourceManager implements DeviceResourceService {
}
@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 class DeviceResourceManager implements DeviceResourceService {
public Set<IntentId> getMapping(IntentId intentId) {
return store.getMapping(intentId);
}
@Override
public void releasePorts(IntentId intentId) {
store.releasePorts(intentId);
}
}
......