Sho SHIMIZU
Committed by Gerrit Code Review

Remove use of org.onosproject.net.resource.ResourceAllocation

The name will conflict with the primitive in new resource API during
future refactoring. This commit is to avoid the conflict.

Change-Id: I47928ba6fa56c00aea7c0f85d7be8593b4862cba
...@@ -40,7 +40,6 @@ import org.onosproject.net.intent.IntentExtensionService; ...@@ -40,7 +40,6 @@ import org.onosproject.net.intent.IntentExtensionService;
40 import org.onosproject.net.intent.OpticalConnectivityIntent; 40 import org.onosproject.net.intent.OpticalConnectivityIntent;
41 import org.onosproject.net.intent.OpticalPathIntent; 41 import org.onosproject.net.intent.OpticalPathIntent;
42 import org.onosproject.net.intent.impl.IntentCompilationException; 42 import org.onosproject.net.intent.impl.IntentCompilationException;
43 -import org.onosproject.net.resource.ResourceAllocation;
44 import org.onosproject.net.resource.ResourceType; 43 import org.onosproject.net.resource.ResourceType;
45 import org.onosproject.net.resource.device.DeviceResourceService; 44 import org.onosproject.net.resource.device.DeviceResourceService;
46 import org.onosproject.net.resource.link.DefaultLinkResourceRequest; 45 import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
...@@ -57,6 +56,7 @@ import org.slf4j.LoggerFactory; ...@@ -57,6 +56,7 @@ import org.slf4j.LoggerFactory;
57 56
58 import java.util.List; 57 import java.util.List;
59 import java.util.Set; 58 import java.util.Set;
59 +import java.util.stream.Collectors;
60 60
61 import static com.google.common.base.Preconditions.checkArgument; 61 import static com.google.common.base.Preconditions.checkArgument;
62 62
...@@ -174,15 +174,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -174,15 +174,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
174 * @return lambda allocated to the given path 174 * @return lambda allocated to the given path
175 */ 175 */
176 private LambdaResourceAllocation getWavelength(Path path, LinkResourceAllocations linkAllocs) { 176 private LambdaResourceAllocation getWavelength(Path path, LinkResourceAllocations linkAllocs) {
177 - for (Link link : path.links()) { 177 + return path.links().stream()
178 - for (ResourceAllocation alloc : linkAllocs.getResourceAllocation(link)) { 178 + .flatMap(x -> linkAllocs.getResourceAllocation(x).stream())
179 - if (alloc.type() == ResourceType.LAMBDA) { 179 + .filter(x -> x.type() == ResourceType.LAMBDA)
180 - return (LambdaResourceAllocation) alloc; 180 + .findFirst()
181 - } 181 + .map(x -> (LambdaResourceAllocation) x)
182 - } 182 + .orElse(null);
183 - }
184 -
185 - return null;
186 } 183 }
187 184
188 /** 185 /**
...@@ -215,23 +212,23 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -215,23 +212,23 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
215 return false; 212 return false;
216 } 213 }
217 214
218 - LambdaResource lambda = null; 215 + List<LambdaResource> lambdas = path.links().stream()
216 + .flatMap(x -> allocations.getResourceAllocation(x).stream())
217 + .filter(x -> x.type() == ResourceType.LAMBDA)
218 + .map(x -> ((LambdaResourceAllocation) x).lambda())
219 + .collect(Collectors.toList());
219 220
220 - for (Link link : path.links()) { 221 + LambdaResource lambda = null;
221 - for (ResourceAllocation alloc : allocations.getResourceAllocation(link)) { 222 + for (LambdaResource nextLambda: lambdas) {
222 - if (alloc.type() == ResourceType.LAMBDA) { 223 + if (nextLambda == null) {
223 - LambdaResource nextLambda = ((LambdaResourceAllocation) alloc).lambda(); 224 + return false;
224 - if (nextLambda == null) { 225 + }
225 - return false; 226 + if (lambda == null) {
226 - } 227 + lambda = nextLambda;
227 - if (lambda == null) { 228 + continue;
228 - lambda = nextLambda; 229 + }
229 - continue; 230 + if (!lambda.equals(nextLambda)) {
230 - } 231 + return false;
231 - if (!lambda.equals(nextLambda)) {
232 - return false;
233 - }
234 - }
235 } 232 }
236 } 233 }
237 234
......