Change the APIs to instantiate Resource and ResourceId
Now, DiscreteResource/DiscreteResourceId is provided by DiscreteFactory.
Similarly, ContinuousResource/ContinuousResourceId is provided by
ContinuousFactory. These factory instances can be obtained by static
factory method such as Resource.discrete(...) or Resource.continuous(...).
Change-Id: Ic94f7336c0e1f74cf2dddcac899de300362aff3e
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 a9bf1b7..511c0c2 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
@@ -125,8 +125,10 @@
// TODO: introduce the concept of Tx and Rx resources of a port
Set<Resource> resources = labels.entrySet().stream()
.flatMap(x -> Stream.of(
- Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
+ Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
+ .resource(),
Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
+ .resource()
))
.collect(Collectors.toSet());
List<org.onosproject.net.newresource.ResourceAllocation> allocations =
@@ -154,7 +156,7 @@
}
private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
- return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port())).stream()
+ return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port()).resource()).stream()
.filter(x -> x.last() instanceof MplsLabel)
.map(x -> (MplsLabel) x.last())
.collect(Collectors.toSet());
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 5d47658..a08b843 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
@@ -160,8 +160,8 @@
log.debug("Compiling optical circuit intent between {} and {}", src, dst);
// Reserve OduClt ports
- Resource srcPortResource = Resource.discrete(src.deviceId(), src.port());
- Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port());
+ Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()).resource();
+ Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()).resource();
List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource);
if (allocation.isEmpty()) {
throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
@@ -312,7 +312,7 @@
if (ochCP != null) {
OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
Optional<IntentId> intentId =
- resourceService.getResourceAllocations(Resource.discrete(ochCP.deviceId(), ochCP.port()))
+ resourceService.getResourceAllocations(Resource.discrete(ochCP.deviceId(), ochCP.port()).resource())
.stream()
.map(ResourceAllocation::consumer)
.filter(x -> x instanceof IntentId)
@@ -333,7 +333,8 @@
}
Optional<IntentId> intentId =
- resourceService.getResourceAllocations(Resource.discrete(oduPort.deviceId(), port.number()))
+ resourceService.getResourceAllocations(
+ Resource.discrete(oduPort.deviceId(), port.number()).resource())
.stream()
.map(ResourceAllocation::consumer)
.filter(x -> x instanceof IntentId)
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 98df5f3..3becdb8 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
@@ -109,8 +109,8 @@
log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
// Reserve OCh ports
- Resource srcPortResource = Resource.discrete(src.deviceId(), src.port());
- Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port());
+ Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()).resource();
+ Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()).resource();
List<org.onosproject.net.newresource.ResourceAllocation> allocation =
resourceService.allocate(intent.id(), srcPortResource, dstPortResource);
if (allocation.isEmpty()) {
@@ -184,8 +184,8 @@
List<OchSignal> minLambda = findFirstLambda(lambdas, slotCount());
List<Resource> lambdaResources = path.links().stream()
.flatMap(x -> Stream.of(
- Resource.discrete(x.src().deviceId(), x.src().port()),
- Resource.discrete(x.dst().deviceId(), x.dst().port())
+ Resource.discrete(x.src().deviceId(), x.src().port()).resource(),
+ Resource.discrete(x.dst().deviceId(), x.dst().port()).resource()
))
.flatMap(x -> minLambda.stream().map(l -> x.child(l)))
.collect(Collectors.toList());
@@ -214,8 +214,8 @@
private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) {
return links.stream()
.flatMap(x -> Stream.of(
- Resource.discrete(x.src().deviceId(), x.src().port()),
- Resource.discrete(x.dst().deviceId(), x.dst().port())
+ Resource.discrete(x.src().deviceId(), x.src().port()).resource(),
+ Resource.discrete(x.dst().deviceId(), x.dst().port()).resource()
))
.map(resourceService::getAvailableResources)
.map(x -> Iterables.filter(x, r -> r.last() instanceof OchSignal))
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 ec7cfd7..842e5e0 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
@@ -252,8 +252,10 @@
//same VLANID is used for both directions
Set<Resource> resources = vlanIds.entrySet().stream()
.flatMap(x -> Stream.of(
- Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
+ Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
+ .resource(),
Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
+ .resource()
))
.collect(Collectors.toSet());
List<org.onosproject.net.newresource.ResourceAllocation> allocations =
@@ -280,7 +282,7 @@
}
private Set<VlanId> findVlanId(ConnectPoint cp) {
- return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port())).stream()
+ return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port()).resource()).stream()
.filter(x -> x.last() instanceof VlanId)
.map(x -> (VlanId) x.last())
.collect(Collectors.toSet());
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java
index e3e42ac..2a85fbb 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java
@@ -118,15 +118,15 @@
}
private void registerDeviceResource(Device device) {
- executor.submit(() -> adminService.registerResources(Resource.discrete(device.id())));
+ executor.submit(() -> adminService.registerResources(Resource.discrete(device.id()).resource()));
}
private void unregisterDeviceResource(Device device) {
- executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id())));
+ executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id()).resource()));
}
private void registerPortResource(Device device, Port port) {
- Resource portPath = Resource.discrete(device.id(), port.number());
+ Resource portPath = Resource.discrete(device.id(), port.number()).resource();
executor.submit(() -> {
adminService.registerResources(portPath);
@@ -174,7 +174,7 @@
}
private void unregisterPortResource(Device device, Port port) {
- Resource resource = Resource.discrete(device.id(), port.number());
+ Resource resource = Resource.discrete(device.id(), port.number()).resource();
executor.submit(() -> adminService.unregisterResources(resource));
}
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceNetworkConfigListener.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceNetworkConfigListener.java
index 88d8bc6..b8d373b 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceNetworkConfigListener.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceNetworkConfigListener.java
@@ -93,9 +93,9 @@
switch (event.type()) {
case CONFIG_ADDED:
- if (!adminService.registerResources(continuous(bwCapacity.capacity().bps(),
- cp.deviceId(),
- cp.port(), Bandwidth.class))) {
+ if (!adminService.registerResources(continuous(cp.deviceId(),
+ cp.port(), Bandwidth.class)
+ .resource(bwCapacity.capacity().bps()))) {
log.info("Failed to register Bandwidth for {}, attempting update", cp);
// Bandwidth based on port speed, was probably already registered.
@@ -115,10 +115,9 @@
case CONFIG_REMOVED:
// FIXME Following should be an update to the value based on port speed
- if (!adminService.unregisterResources(continuous(0,
- cp.deviceId(),
+ if (!adminService.unregisterResources(continuous(cp.deviceId(),
cp.port(),
- Bandwidth.class))) {
+ Bandwidth.class).resource(0))) {
log.warn("Failed to unregister Bandwidth for {}", cp);
}
break;
@@ -148,13 +147,12 @@
// but both unregisterResources(..) and registerResources(..)
// returns true (success)
- if (!adminService.unregisterResources(continuous(0, cp.deviceId(), cp.port(), Bandwidth.class))) {
+ if (!adminService.unregisterResources(continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(0))) {
log.warn("unregisterResources for {} failed", cp);
}
- return adminService.registerResources(continuous(bwCapacity.capacity().bps(),
- cp.deviceId(),
+ return adminService.registerResources(continuous(cp.deviceId(),
cp.port(),
- Bandwidth.class));
+ Bandwidth.class).resource(bwCapacity.capacity().bps()));
}
}