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; ...@@ -45,6 +45,7 @@ import org.onosproject.net.intent.IntentState;
45 import org.onosproject.net.intent.OpticalCircuitIntent; 45 import org.onosproject.net.intent.OpticalCircuitIntent;
46 import org.onosproject.net.intent.OpticalConnectivityIntent; 46 import org.onosproject.net.intent.OpticalConnectivityIntent;
47 import org.onosproject.net.intent.PointToPointIntent; 47 import org.onosproject.net.intent.PointToPointIntent;
48 +import org.onosproject.net.newresource.ResourceService;
48 import org.onosproject.net.resource.device.DeviceResourceService; 49 import org.onosproject.net.resource.device.DeviceResourceService;
49 import org.onosproject.net.resource.link.LinkResourceAllocations; 50 import org.onosproject.net.resource.link.LinkResourceAllocations;
50 import org.onosproject.net.resource.link.LinkResourceService; 51 import org.onosproject.net.resource.link.LinkResourceService;
...@@ -102,6 +103,9 @@ public class OpticalPathProvisioner { ...@@ -102,6 +103,9 @@ public class OpticalPathProvisioner {
102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 103 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 protected LinkResourceService linkResourceService; 104 protected LinkResourceService linkResourceService;
104 105
106 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 + protected ResourceService resourceService;
108 +
105 private ApplicationId appId; 109 private ApplicationId appId;
106 110
107 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); 111 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
...@@ -375,12 +379,12 @@ public class OpticalPathProvisioner { ...@@ -375,12 +379,12 @@ public class OpticalPathProvisioner {
375 private void releaseResources(Intent intent) { 379 private void releaseResources(Intent intent) {
376 LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id()); 380 LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id());
377 if (intent instanceof OpticalConnectivityIntent) { 381 if (intent instanceof OpticalConnectivityIntent) {
378 - deviceResourceService.releasePorts(intent.id()); 382 + resourceService.release(intent.id());
379 if (lra != null) { 383 if (lra != null) {
380 linkResourceService.releaseResources(lra); 384 linkResourceService.releaseResources(lra);
381 } 385 }
382 } else if (intent instanceof OpticalCircuitIntent) { 386 } else if (intent instanceof OpticalCircuitIntent) {
383 - deviceResourceService.releasePorts(intent.id()); 387 + resourceService.release(intent.id());
384 deviceResourceService.releaseMapping(intent.id()); 388 deviceResourceService.releaseMapping(intent.id());
385 if (lra != null) { 389 if (lra != null) {
386 linkResourceService.releaseResources(lra); 390 linkResourceService.releaseResources(lra);
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
16 package org.onosproject.net.resource.device; 16 package org.onosproject.net.resource.device;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 -import org.onosproject.net.Port;
20 -import org.onosproject.net.intent.Intent;
21 import org.onosproject.net.intent.IntentId; 19 import org.onosproject.net.intent.IntentId;
22 20
23 import java.util.Set; 21 import java.util.Set;
...@@ -27,30 +25,6 @@ import java.util.Set; ...@@ -27,30 +25,6 @@ import java.util.Set;
27 */ 25 */
28 @Beta 26 @Beta
29 public interface DeviceResourceService { 27 public interface DeviceResourceService {
30 - /**
31 - * Request a set of ports needed to satisfy the intent.
32 - *
33 - * @param ports set of ports to allocate
34 - * @param intent the intent
35 - * @return true if ports were successfully allocated, false otherwise
36 - */
37 - boolean requestPorts(Set<Port> ports, Intent intent);
38 -
39 - /**
40 - * Returns the set of ports allocated for an intent.
41 - *
42 - * @param intentId the intent ID
43 - * @return set of allocated ports
44 - */
45 - Set<Port> getAllocations(IntentId intentId);
46 -
47 - /**
48 - * Returns the intent allocated to a port.
49 - *
50 - * @param port the port
51 - * @return intent ID allocated to the port
52 - */
53 - IntentId getAllocations(Port port);
54 28
55 /** 29 /**
56 * Request a mapping between the given intents. 30 * Request a mapping between the given intents.
...@@ -75,11 +49,4 @@ public interface DeviceResourceService { ...@@ -75,11 +49,4 @@ public interface DeviceResourceService {
75 * @param intentId intent ID 49 * @param intentId intent ID
76 */ 50 */
77 void releaseMapping(IntentId intentId); 51 void releaseMapping(IntentId intentId);
78 -
79 - /**
80 - * Release ports associated with given intent ID.
81 - *
82 - * @param intentId intent ID
83 - */
84 - void releasePorts(IntentId intentId);
85 } 52 }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 -import com.google.common.collect.Sets;
19 import org.apache.commons.lang3.tuple.Pair; 18 import org.apache.commons.lang3.tuple.Pair;
20 import org.apache.felix.scr.annotations.Activate; 19 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 20 import org.apache.felix.scr.annotations.Component;
...@@ -50,6 +49,9 @@ import org.onosproject.net.intent.IntentService; ...@@ -50,6 +49,9 @@ import org.onosproject.net.intent.IntentService;
50 import org.onosproject.net.intent.OpticalCircuitIntent; 49 import org.onosproject.net.intent.OpticalCircuitIntent;
51 import org.onosproject.net.intent.OpticalConnectivityIntent; 50 import org.onosproject.net.intent.OpticalConnectivityIntent;
52 import org.onosproject.net.intent.impl.IntentCompilationException; 51 import org.onosproject.net.intent.impl.IntentCompilationException;
52 +import org.onosproject.net.newresource.ResourceAllocation;
53 +import org.onosproject.net.newresource.ResourcePath;
54 +import org.onosproject.net.newresource.ResourceService;
53 import org.onosproject.net.resource.device.DeviceResourceService; 55 import org.onosproject.net.resource.device.DeviceResourceService;
54 import org.onosproject.net.resource.link.LinkResourceAllocations; 56 import org.onosproject.net.resource.link.LinkResourceAllocations;
55 import org.osgi.service.component.ComponentContext; 57 import org.osgi.service.component.ComponentContext;
...@@ -60,6 +62,7 @@ import java.util.Collections; ...@@ -60,6 +62,7 @@ import java.util.Collections;
60 import java.util.Dictionary; 62 import java.util.Dictionary;
61 import java.util.LinkedList; 63 import java.util.LinkedList;
62 import java.util.List; 64 import java.util.List;
65 +import java.util.Optional;
63 import java.util.Set; 66 import java.util.Set;
64 67
65 import static com.google.common.base.Preconditions.checkArgument; 68 import static com.google.common.base.Preconditions.checkArgument;
...@@ -92,6 +95,9 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -92,6 +95,9 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
92 protected DeviceService deviceService; 95 protected DeviceService deviceService;
93 96
94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 + protected ResourceService resourceService;
99 +
100 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
95 protected DeviceResourceService deviceResourceService; 101 protected DeviceResourceService deviceResourceService;
96 102
97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 103 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -153,7 +159,10 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -153,7 +159,10 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
153 log.debug("Compiling optical circuit intent between {} and {}", src, dst); 159 log.debug("Compiling optical circuit intent between {} and {}", src, dst);
154 160
155 // Reserve OduClt ports 161 // Reserve OduClt ports
156 - if (!deviceResourceService.requestPorts(Sets.newHashSet(srcPort, dstPort), intent)) { 162 + ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port());
163 + ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port());
164 + List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
165 + if (allocation.isEmpty()) {
157 throw new IntentCompilationException("Unable to reserve ports for intent " + intent); 166 throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
158 } 167 }
159 168
...@@ -301,8 +310,13 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -301,8 +310,13 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
301 310
302 if (ochCP != null) { 311 if (ochCP != null) {
303 OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); 312 OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
304 - IntentId intentId = deviceResourceService.getAllocations(ochPort); 313 + Optional<IntentId> intentId =
305 - if (isAvailable(intentId)) { 314 + resourceService.getResourceAllocation(new ResourcePath(ochCP.deviceId(), ochCP.port()))
315 + .map(ResourceAllocation::consumer)
316 + .filter(x -> x instanceof IntentId)
317 + .map(x -> (IntentId) x);
318 +
319 + if (isAvailable(intentId.orElse(null))) {
306 return ochPort; 320 return ochPort;
307 } 321 }
308 } 322 }
...@@ -315,8 +329,12 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -315,8 +329,12 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
315 continue; 329 continue;
316 } 330 }
317 331
318 - IntentId intentId = deviceResourceService.getAllocations(port); 332 + Optional<IntentId> intentId =
319 - if (isAvailable(intentId)) { 333 + resourceService.getResourceAllocation(new ResourcePath(oduPort.deviceId(), port.number()))
334 + .map(ResourceAllocation::consumer)
335 + .filter(x -> x instanceof IntentId)
336 + .map(x -> (IntentId) x);
337 + if (isAvailable(intentId.orElse(null))) {
320 return (OchPort) port; 338 return (OchPort) port;
321 } 339 }
322 } 340 }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 -import com.google.common.collect.ImmutableSet;
20 import org.apache.felix.scr.annotations.Activate; 19 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 20 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 21 import org.apache.felix.scr.annotations.Deactivate;
...@@ -40,6 +39,8 @@ import org.onosproject.net.intent.IntentExtensionService; ...@@ -40,6 +39,8 @@ import org.onosproject.net.intent.IntentExtensionService;
40 import org.onosproject.net.intent.OpticalConnectivityIntent; 39 import org.onosproject.net.intent.OpticalConnectivityIntent;
41 import org.onosproject.net.intent.OpticalPathIntent; 40 import org.onosproject.net.intent.OpticalPathIntent;
42 import org.onosproject.net.intent.impl.IntentCompilationException; 41 import org.onosproject.net.intent.impl.IntentCompilationException;
42 +import org.onosproject.net.newresource.ResourcePath;
43 +import org.onosproject.net.newresource.ResourceService;
43 import org.onosproject.net.resource.ResourceType; 44 import org.onosproject.net.resource.ResourceType;
44 import org.onosproject.net.resource.device.DeviceResourceService; 45 import org.onosproject.net.resource.device.DeviceResourceService;
45 import org.onosproject.net.resource.link.DefaultLinkResourceRequest; 46 import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
...@@ -78,6 +79,9 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -78,6 +79,9 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
78 protected DeviceService deviceService; 79 protected DeviceService deviceService;
79 80
80 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 + protected ResourceService resourceService;
83 +
84 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
81 protected LinkResourceService linkResourceService; 85 protected LinkResourceService linkResourceService;
82 86
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -108,7 +112,11 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -108,7 +112,11 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
108 log.debug("Compiling optical connectivity intent between {} and {}", src, dst); 112 log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
109 113
110 // Reserve OCh ports 114 // Reserve OCh ports
111 - if (!deviceResourceService.requestPorts(ImmutableSet.of(srcPort, dstPort), intent)) { 115 + ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port());
116 + ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port());
117 + List<org.onosproject.net.newresource.ResourceAllocation> allocation =
118 + resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
119 + if (allocation.isEmpty()) {
112 throw new IntentCompilationException("Unable to reserve ports for intent " + intent); 120 throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
113 } 121 }
114 122
...@@ -161,7 +169,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -161,7 +169,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
161 } 169 }
162 170
163 // Release port allocations if unsuccessful 171 // Release port allocations if unsuccessful
164 - deviceResourceService.releasePorts(intent.id()); 172 + resourceService.release(intent.id());
165 173
166 throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent); 174 throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
167 } 175 }
......
...@@ -21,8 +21,6 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -21,8 +21,6 @@ import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
24 -import org.onosproject.net.Port;
25 -import org.onosproject.net.intent.Intent;
26 import org.onosproject.net.intent.IntentId; 24 import org.onosproject.net.intent.IntentId;
27 import org.onosproject.net.resource.device.DeviceResourceService; 25 import org.onosproject.net.resource.device.DeviceResourceService;
28 import org.onosproject.net.resource.device.DeviceResourceStore; 26 import org.onosproject.net.resource.device.DeviceResourceStore;
...@@ -30,7 +28,6 @@ import org.slf4j.Logger; ...@@ -30,7 +28,6 @@ import org.slf4j.Logger;
30 28
31 import java.util.Set; 29 import java.util.Set;
32 30
33 -import static com.google.common.base.Preconditions.checkNotNull;
34 import static org.slf4j.LoggerFactory.getLogger; 31 import static org.slf4j.LoggerFactory.getLogger;
35 32
36 /** 33 /**
...@@ -56,23 +53,6 @@ public class DeviceResourceManager implements DeviceResourceService { ...@@ -56,23 +53,6 @@ public class DeviceResourceManager implements DeviceResourceService {
56 } 53 }
57 54
58 @Override 55 @Override
59 - public boolean requestPorts(Set<Port> ports, Intent intent) {
60 - checkNotNull(intent);
61 -
62 - return store.allocatePorts(ports, intent.id());
63 - }
64 -
65 - @Override
66 - public Set<Port> getAllocations(IntentId intentId) {
67 - return store.getAllocations(intentId);
68 - }
69 -
70 - @Override
71 - public IntentId getAllocations(Port port) {
72 - return store.getAllocations(port);
73 - }
74 -
75 - @Override
76 public void releaseMapping(IntentId intentId) { 56 public void releaseMapping(IntentId intentId) {
77 store.releaseMapping(intentId); 57 store.releaseMapping(intentId);
78 } 58 }
...@@ -86,9 +66,4 @@ public class DeviceResourceManager implements DeviceResourceService { ...@@ -86,9 +66,4 @@ public class DeviceResourceManager implements DeviceResourceService {
86 public Set<IntentId> getMapping(IntentId intentId) { 66 public Set<IntentId> getMapping(IntentId intentId) {
87 return store.getMapping(intentId); 67 return store.getMapping(intentId);
88 } 68 }
89 -
90 - @Override
91 - public void releasePorts(IntentId intentId) {
92 - store.releasePorts(intentId);
93 - }
94 } 69 }
......