X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fservice%2FPathComputationServiceImpl.java;h=01bfc3024859b39cca07f61ea7792d1918a99e2b;hb=2a29f9ab006d8806f77b1a1e073b478e5351cc5f;hp=9d860f8a3a8b804acdce8d28a124e84643f6e12a;hpb=f5a8fe61d265bce36b2fca393d82685a22ac326a;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java index 9d860f8a3..01bfc3024 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java @@ -10,41 +10,45 @@ package org.opendaylight.transportpce.pce.service; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Executors; +import java.util.stream.Collectors; import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.mapping.PortMapping; import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.pce.PceComplianceCheck; import org.opendaylight.transportpce.pce.PceComplianceCheckResult; import org.opendaylight.transportpce.pce.PceSendingPceRPCs; import org.opendaylight.transportpce.pce.gnpy.GnpyResult; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result.Response; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.ServicePathRpcResult; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.ServicePathRpcResultBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.GnpyResponse; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.GnpyResponseBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.gnpy.response.ResponseType; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.gnpy.response.response.type.NoPathCase; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.gnpy.response.response.type.NoPathCaseBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.gnpy.response.response.type.PathCase; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.gnpy.gnpy.response.response.type.PathCaseBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.path.performance.PathProperties; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.path.performance.PathPropertiesBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.path.performance.path.properties.PathMetric; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.path.performance.path.properties.PathMetricBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescription; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescriptionBuilder; +import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer; +import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.Response; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.CancelResourceReserveInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.CancelResourceReserveOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.CancelResourceReserveOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.ServicePathRpcResult; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.ServicePathRpcResultBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.GnpyResponse; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.GnpyResponseBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.gnpy.response.ResponseType; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.gnpy.response.response.type.NoPathCase; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.gnpy.response.response.type.NoPathCaseBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.gnpy.response.response.type.PathCase; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.gnpy.gnpy.response.response.type.PathCaseBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.path.performance.PathProperties; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.path.performance.PathPropertiesBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.path.performance.path.properties.PathMetric; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.path.performance.path.properties.PathMetricBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.service.path.rpc.result.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.service.path.rpc.result.PathDescriptionBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.AToZDirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ZToADirection; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.ServicePathNotificationTypes; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder; @@ -57,13 +61,18 @@ public class PathComputationServiceImpl implements PathComputationService { private final NotificationPublishService notificationPublishService; private NetworkTransactionService networkTransactionService; private final ListeningExecutorService executor; - ServicePathRpcResult notification = null; + private ServicePathRpcResult notification = null; + private final GnpyConsumer gnpyConsumer; + private PortMapping portMapping; public PathComputationServiceImpl(NetworkTransactionService networkTransactionService, - NotificationPublishService notificationPublishService) { + NotificationPublishService notificationPublishService, + GnpyConsumer gnpyConsumer, PortMapping portMapping) { this.notificationPublishService = notificationPublishService; this.networkTransactionService = networkTransactionService; this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5)); + this.gnpyConsumer = gnpyConsumer; + this.portMapping = portMapping; } public void init() { @@ -74,6 +83,9 @@ public class PathComputationServiceImpl implements PathComputationService { LOG.info("close."); } + @SuppressFBWarnings( + value = "UPM_UNCALLED_PRIVATE_METHOD", + justification = "false positive, this method is used by public method cancelResourceReserve") private void sendNotifications(ServicePathNotificationTypes servicePathNotificationTypes, String serviceName, RpcStatusEx rpcStatusEx, String message, PathDescription pathDescription) { ServicePathRpcResultBuilder servicePathRpcResultBuilder = @@ -100,7 +112,7 @@ public class PathComputationServiceImpl implements PathComputationService { String message = ""; sendNotifications(ServicePathNotificationTypes.CancelResourceReserve, input.getServiceName(), RpcStatusEx.Pending, "Service compliant, submitting cancelResourceReserve Request ...", null); - PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(); + PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(gnpyConsumer); sendingPCE.cancelResourceReserve(); if (Boolean.TRUE.equals(sendingPCE.getSuccess())) { message = "ResourceReserve cancelled !"; @@ -148,7 +160,8 @@ public class PathComputationServiceImpl implements PathComputationService { RpcStatusEx.Pending, "Service compliant, submitting pathComputation Request ...", null); String message = ""; String responseCode = ""; - PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(input, networkTransactionService); + PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(input, networkTransactionService, + gnpyConsumer, portMapping); sendingPCE.pathComputation(); message = sendingPCE.getMessage(); responseCode = sendingPCE.getResponseCode(); @@ -168,7 +181,8 @@ public class PathComputationServiceImpl implements PathComputationService { GnpyResponse respZtoA = generateGnpyResponse(gnpyZtoA.getResponse(),"Z-to-A"); listResponse.add(respZtoA); } - output.setGnpyResponse(listResponse); + output.setGnpyResponse(listResponse.stream() + .collect(Collectors.toMap(GnpyResponse::key, gnpyResponse -> gnpyResponse))); if (Boolean.FALSE.equals(sendingPCE.getSuccess()) || (path == null)) { configurationResponseCommon.setAckFinalIndicator("Yes") @@ -184,7 +198,7 @@ public class PathComputationServiceImpl implements PathComputationService { .setRequestId(input.getServiceHandlerHeader().getRequestId()).setResponseCode(responseCode) .setResponseMessage(message); PathDescription pathDescription = new org.opendaylight.yang.gen.v1.http.org.opendaylight - .transportpce.pce.rev200128.service.path.rpc.result.PathDescriptionBuilder() + .transportpce.pce.rev210701.service.path.rpc.result.PathDescriptionBuilder() .setAToZDirection(path.getAToZDirection()).setZToADirection(path.getZToADirection()) .build(); sendNotifications(ServicePathNotificationTypes.PathComputationRequest, input.getServiceName(), @@ -203,15 +217,17 @@ public class PathComputationServiceImpl implements PathComputationService { AToZDirection atoz = pathDescription.getAToZDirection(); if ((atoz != null) && (atoz.getAToZ() != null)) { LOG.debug("Impl AtoZ Notification: [{}] elements in description", atoz.getAToZ().size()); - for (int i = 0; i < atoz.getAToZ().size(); i++) { - LOG.debug("Impl AtoZ Notification: [{}] {}", i, atoz.getAToZ().get(i)); + for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210 + .path.description.atoz.direction.AToZKey key : atoz.getAToZ().keySet()) { + LOG.debug("Impl AtoZ Notification: [{}] {}", key, atoz.getAToZ().get(key)); } } ZToADirection ztoa = pathDescription.getZToADirection(); if ((ztoa != null) && (ztoa.getZToA() != null)) { LOG.debug("Impl ZtoA Notification: [{}] elements in description", ztoa.getZToA().size()); - for (int i = 0; i < ztoa.getZToA().size(); i++) { - LOG.debug("Impl ZtoA Notification: [{}] {}", i, ztoa.getZToA().get(i)); + for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210 + .path.description.ztoa.direction.ZToAKey key : ztoa.getZToA().keySet()) { + LOG.debug("Impl ZtoA Notification: [{}] {}", key, ztoa.getZToA().get(key)); } } return output.build(); @@ -223,31 +239,35 @@ public class PathComputationServiceImpl implements PathComputationService { ResponseType respType = null; boolean feasible = true; if (responseGnpy != null) { - if (responseGnpy.getResponseType() instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result + if (responseGnpy.getResponseType() instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result .response.response.type.NoPathCase) { LOG.info("GNPy : path is not feasible"); - org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result.response.response.type.NoPathCase - noPathGnpy = (org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result.response.response.type + org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.NoPathCase + noPathGnpy = (org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type .NoPathCase) responseGnpy.getResponseType(); NoPathCase noPathCase = new NoPathCaseBuilder().setNoPath(noPathGnpy.getNoPath()).build(); respType = noPathCase; feasible = false; - } else if (responseGnpy.getResponseType() instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result + } else if (responseGnpy.getResponseType() instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result .response.response.type.PathCase) { LOG.info("GNPy : path is feasible"); - org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result.response.response.type.PathCase pathCase = - (org.opendaylight.yang.gen.v1.gnpy.path.rev200202.result.response.response.type.PathCase) + org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.PathCase pathCase = + (org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.PathCase) responseGnpy.getResponseType(); - List pathMetricList = pathCase.getPathProperties().getPathMetric(); + List pathMetricList = + new ArrayList<>(pathCase.getPathProperties().getPathMetric().values()); List gnpyPathMetricList = new ArrayList<>(); - for (org.opendaylight.yang.gen.v1.gnpy.path.rev200202.generic.path.properties.path.properties.PathMetric + for (org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetric pathMetricGnpy : pathMetricList) { PathMetric pathMetric = new PathMetricBuilder().setMetricType(pathMetricGnpy.getMetricType()) .setAccumulativeValue(pathMetricGnpy.getAccumulativeValue()).build(); gnpyPathMetricList.add(pathMetric); } - PathProperties pathProperties = new PathPropertiesBuilder().setPathMetric(gnpyPathMetricList).build(); + PathProperties pathProperties = new PathPropertiesBuilder() + .setPathMetric(gnpyPathMetricList.stream() + .collect(Collectors.toMap(PathMetric::key, pathMetric -> pathMetric))) + .build(); PathCase gnpyPathCase = new PathCaseBuilder().setPathProperties(pathProperties).build(); respType = gnpyPathCase; feasible = true;