Naoki Shiota
Committed by Gerrit Code Review

Fixed a bug that optical intent compilers never release resources reserved during compilation.

Removed tempoary code from optical app (ONOS-2129).

Change-Id: Iee0343964f886196922469eaabe4a72c3f404888
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.optical; 16 package org.onosproject.optical;
17 17
18 -import com.google.common.collect.ImmutableList;
19 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
...@@ -47,16 +46,12 @@ import org.onosproject.net.intent.IntentState; ...@@ -47,16 +46,12 @@ import org.onosproject.net.intent.IntentState;
47 import org.onosproject.net.intent.OpticalCircuitIntent; 46 import org.onosproject.net.intent.OpticalCircuitIntent;
48 import org.onosproject.net.intent.OpticalConnectivityIntent; 47 import org.onosproject.net.intent.OpticalConnectivityIntent;
49 import org.onosproject.net.intent.PointToPointIntent; 48 import org.onosproject.net.intent.PointToPointIntent;
50 -import org.onosproject.net.newresource.ResourceAllocation;
51 -import org.onosproject.net.newresource.ResourceService;
52 -import org.onosproject.net.resource.device.IntentSetMultimap;
53 import org.onosproject.net.topology.LinkWeight; 49 import org.onosproject.net.topology.LinkWeight;
54 import org.onosproject.net.topology.PathService; 50 import org.onosproject.net.topology.PathService;
55 import org.onosproject.net.topology.TopologyEdge; 51 import org.onosproject.net.topology.TopologyEdge;
56 import org.slf4j.Logger; 52 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory; 53 import org.slf4j.LoggerFactory;
58 54
59 -import java.util.Collection;
60 import java.util.Collections; 55 import java.util.Collections;
61 import java.util.Iterator; 56 import java.util.Iterator;
62 import java.util.LinkedList; 57 import java.util.LinkedList;
...@@ -99,12 +94,6 @@ public class OpticalPathProvisioner { ...@@ -99,12 +94,6 @@ public class OpticalPathProvisioner {
99 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
100 protected DeviceService deviceService; 95 protected DeviceService deviceService;
101 96
102 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 - protected IntentSetMultimap intentSetMultimap;
104 -
105 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
106 - protected ResourceService resourceService;
107 -
108 private ApplicationId appId; 97 private ApplicationId appId;
109 98
110 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); 99 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
...@@ -143,10 +132,6 @@ public class OpticalPathProvisioner { ...@@ -143,10 +132,6 @@ public class OpticalPathProvisioner {
143 log.info("Intent {} failed, calling optical path provisioning app.", event.subject()); 132 log.info("Intent {} failed, calling optical path provisioning app.", event.subject());
144 setupLightpath(event.subject()); 133 setupLightpath(event.subject());
145 break; 134 break;
146 - case WITHDRAWN:
147 - log.info("Intent {} withdrawn.", event.subject());
148 - releaseResources(event.subject());
149 - break;
150 default: 135 default:
151 break; 136 break;
152 } 137 }
...@@ -371,26 +356,6 @@ public class OpticalPathProvisioner { ...@@ -371,26 +356,6 @@ public class OpticalPathProvisioner {
371 } 356 }
372 } 357 }
373 358
374 - /**
375 - * Release resources associated to the given intent.
376 - *
377 - * @param intent the intent
378 - */
379 - private void releaseResources(Intent intent) {
380 - Collection<ResourceAllocation> allocations = resourceService.getResourceAllocations(intent.id());
381 - if (intent instanceof OpticalConnectivityIntent) {
382 - resourceService.release(intent.id());
383 - if (!allocations.isEmpty()) {
384 - resourceService.release(ImmutableList.copyOf(allocations));
385 - }
386 - } else if (intent instanceof OpticalCircuitIntent) {
387 - resourceService.release(intent.id());
388 - intentSetMultimap.releaseMapping(intent.id());
389 - if (!allocations.isEmpty()) {
390 - resourceService.release(ImmutableList.copyOf(allocations));
391 - }
392 - }
393 - }
394 } 359 }
395 360
396 /** 361 /**
......
...@@ -44,6 +44,7 @@ import org.onosproject.net.intent.IntentStoreDelegate; ...@@ -44,6 +44,7 @@ import org.onosproject.net.intent.IntentStoreDelegate;
44 import org.onosproject.net.intent.Key; 44 import org.onosproject.net.intent.Key;
45 import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase; 45 import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase;
46 import org.onosproject.net.intent.impl.phase.IntentProcessPhase; 46 import org.onosproject.net.intent.impl.phase.IntentProcessPhase;
47 +import org.onosproject.net.newresource.ResourceService;
47 import org.slf4j.Logger; 48 import org.slf4j.Logger;
48 49
49 import java.util.Collection; 50 import java.util.Collection;
...@@ -108,6 +109,9 @@ public class IntentManager ...@@ -108,6 +109,9 @@ public class IntentManager
108 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 109 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
109 protected FlowRuleService flowRuleService; 110 protected FlowRuleService flowRuleService;
110 111
112 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
113 + protected ResourceService resourceService;
114 +
111 private ExecutorService batchExecutor; 115 private ExecutorService batchExecutor;
112 private ExecutorService workerExecutor; 116 private ExecutorService workerExecutor;
113 117
...@@ -238,6 +242,16 @@ public class IntentManager ...@@ -238,6 +242,16 @@ public class IntentManager
238 @Override 242 @Override
239 public void notify(IntentEvent event) { 243 public void notify(IntentEvent event) {
240 post(event); 244 post(event);
245 + switch (event.type()) {
246 + case WITHDRAWN:
247 + // release resources allocated to withdrawn intent
248 + if (!resourceService.release(event.subject().id())) {
249 + log.error("Failed to release resources allocated to {}", event.subject().id());
250 + }
251 + break;
252 + default:
253 + break;
254 + }
241 } 255 }
242 256
243 @Override 257 @Override
......