Brian O'Connor

PathIntentInstaller: avoiding calls to Resource Store when unnecessary

Change-Id: I846ca543f922063ddc67a06353f43c590bd57d96
...@@ -114,10 +114,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -114,10 +114,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
114 114
115 @Override 115 @Override
116 public List<FlowRuleBatchOperation> uninstall(PathIntent intent) { 116 public List<FlowRuleBatchOperation> uninstall(PathIntent intent) {
117 - LinkResourceAllocations allocatedResources = resourceService.getAllocations(intent.id()); 117 + deallocateResources(intent);
118 - if (allocatedResources != null) { 118 +
119 - resourceService.releaseResources(allocatedResources);
120 - }
121 TrafficSelector.Builder builder = 119 TrafficSelector.Builder builder =
122 DefaultTrafficSelector.builder(intent.selector()); 120 DefaultTrafficSelector.builder(intent.selector());
123 Iterator<Link> links = intent.path().links().iterator(); 121 Iterator<Link> links = intent.path().links().iterator();
...@@ -167,4 +165,20 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -167,4 +165,20 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
167 LinkResourceRequest request = builder.build(); 165 LinkResourceRequest request = builder.build();
168 return request.resources().isEmpty() ? null : resourceService.requestResources(request); 166 return request.resources().isEmpty() ? null : resourceService.requestResources(request);
169 } 167 }
168 +
169 + /**
170 + * Deallocate resources held by an intent.
171 + *
172 + * @param intent intent to deallocate resources for
173 + */
174 + private void deallocateResources(PathIntent intent) {
175 + if (intent.constraints().isEmpty()) {
176 + return;
177 + }
178 +
179 + LinkResourceAllocations allocatedResources = resourceService.getAllocations(intent.id());
180 + if (allocatedResources != null) {
181 + resourceService.releaseResources(allocatedResources);
182 + }
183 + }
170 } 184 }
......