Rimon Ashkenazy
Committed by Gerrit Code Review

OpticalCircuitIntentCompiler - fix resource allocation failure (bug ONOS-4184)

Change-Id: I0e86bd8d309423ea835a4fa1988dc0971b84ef02
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 import com.google.common.base.Strings; 18 import com.google.common.base.Strings;
19 +
19 import org.apache.commons.lang3.tuple.Pair; 20 import org.apache.commons.lang3.tuple.Pair;
20 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
...@@ -78,6 +79,7 @@ import java.util.List; ...@@ -78,6 +79,7 @@ import java.util.List;
78 import java.util.Optional; 79 import java.util.Optional;
79 import java.util.Set; 80 import java.util.Set;
80 import java.util.stream.Collectors; 81 import java.util.stream.Collectors;
82 +import java.util.stream.Stream;
81 83
82 import static com.google.common.base.Preconditions.checkArgument; 84 import static com.google.common.base.Preconditions.checkArgument;
83 85
...@@ -184,21 +186,19 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -184,21 +186,19 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
184 // TODO: try to release intent resources in IntentManager. 186 // TODO: try to release intent resources in IntentManager.
185 resourceService.release(intent.id()); 187 resourceService.release(intent.id());
186 188
187 - // Reserve OduClt ports 189 + // Check OduClt ports availability
188 Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource(); 190 Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
189 Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource(); 191 Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
190 - List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource); 192 + // If ports are not available, compilation fails
191 - if (allocation.isEmpty()) { 193 + if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
192 - throw new IntentCompilationException("Unable to reserve ports for intent " + intent); 194 + throw new IntentCompilationException("Ports for the intent are not available. Intent: " + intent);
193 } 195 }
196 + List<Resource> ports = ImmutableList.of(srcPortResource, dstPortResource);
194 197
195 // Check if both devices support multiplexing (usage of TributarySlots) 198 // Check if both devices support multiplexing (usage of TributarySlots)
196 boolean multiplexingSupported = isMultiplexingSupported(intent.getSrc()) 199 boolean multiplexingSupported = isMultiplexingSupported(intent.getSrc())
197 && isMultiplexingSupported(intent.getDst()); 200 && isMultiplexingSupported(intent.getDst());
198 201
199 - // slots are used only for devices supporting multiplexing
200 - List<Resource> ports = ImmutableList.of(srcPortResource, dstPortResource);
201 -
202 OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent.getSrc(), intent.getDst(), 202 OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent.getSrc(), intent.getDst(),
203 intent.getSignalType(), multiplexingSupported); 203 intent.getSignalType(), multiplexingSupported);
204 204
......