Fix PCE PathComputationServiceImpl useless NS
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / service / PathComputationServiceImpl.java
index aa598c73160be1438d207c56a28317d1a6bc0308..32942c2bd12d9a92de028e557cc51b7335d7009f 100644 (file)
@@ -24,30 +24,37 @@ import org.opendaylight.transportpce.pce.PceComplianceCheckResult;
 import org.opendaylight.transportpce.pce.PceSendingPceRPCs;
 import org.opendaylight.transportpce.pce.gnpy.GnpyResult;
 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.Response;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.CancelResourceReserveInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.CancelResourceReserveOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.CancelResourceReserveOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.PathComputationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.PathComputationRequestOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.PathComputationRequestOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.ServicePathRpcResult;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.ServicePathRpcResultBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.gnpy.GnpyResponse;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.gnpy.GnpyResponseBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.gnpy.gnpy.response.response.type.NoPathCaseBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.gnpy.gnpy.response.response.type.PathCaseBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.path.performance.PathPropertiesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.path.performance.path.properties.PathMetric;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.path.performance.path.properties.PathMetricBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.service.path.rpc.result.PathDescription;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.service.path.rpc.result.PathDescriptionBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.ServicePathRpcResult;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.ServicePathRpcResultBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.GnpyResponse;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.GnpyResponseBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.gnpy.response.response.type.NoPathCaseBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.gnpy.response.response.type.PathCaseBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.computation.request.input.ServiceAEndBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.computation.request.input.ServiceZEndBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.performance.PathPropertiesBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.performance.path.properties.PathMetric;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.performance.path.properties.PathMetricBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescription;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescriptionBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.ServicePathNotificationTypes;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.handler.header.ServiceHandlerHeaderBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -145,7 +152,7 @@ public class PathComputationServiceImpl implements PathComputationService {
 
     @Override
     public ListenableFuture<PathComputationRequestOutput> pathComputationRequest(PathComputationRequestInput input) {
-        LOG.info("pathComputationRequest");
+        LOG.debug("input parameters are : input = {}", input.toString());
         return executor.submit(new Callable<PathComputationRequestOutput>() {
 
             @Override
@@ -222,8 +229,7 @@ public class PathComputationServiceImpl implements PathComputationService {
                 }
                 // Path calculator returned Success
                 PathDescription pathDescription =
-                    new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118
-                            .service.path.rpc.result.PathDescriptionBuilder()
+                    new PathDescriptionBuilder()
                         .setAToZDirection(path.getAToZDirection())
                         .setZToADirection(path.getZToADirection())
                         .build();
@@ -272,6 +278,52 @@ public class PathComputationServiceImpl implements PathComputationService {
         });
     }
 
+    @Override
+    public ListenableFuture<PathComputationRerouteRequestOutput> pathComputationRerouteRequest(
+            PathComputationRerouteRequestInput input) {
+        return executor.submit(() -> {
+            PathComputationRerouteRequestOutputBuilder output = new PathComputationRerouteRequestOutputBuilder();
+            ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder()
+                    .setRequestId("none");
+            PceComplianceCheckResult check = PceComplianceCheck.check(input);
+            if (!check.hasPassed()) {
+                LOG.error("Path not calculated, path computation reroute request not compliant : {}",
+                        check.getMessage());
+                configurationResponseCommon
+                        .setAckFinalIndicator("Yes")
+                        .setResponseCode("Path not calculated")
+                        .setResponseMessage(check.getMessage());
+                return output
+                        .setConfigurationResponseCommon(configurationResponseCommon.build())
+                        .build();
+            }
+            PathComputationRequestInput pathComputationInput = new PathComputationRequestInputBuilder()
+                    .setServiceName("no_name")
+                    .setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("none").build())
+                    .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
+                    .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
+                    .setHardConstraints(input.getHardConstraints())
+                    .setPceRoutingMetric(input.getPceRoutingMetric())
+                    .setResourceReserve(false)
+                    .setSoftConstraints(input.getSoftConstraints())
+                    .setRoutingMetric(input.getRoutingMetric())
+                    .build();
+            PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(pathComputationInput, networkTransactionService,
+                    gnpyConsumer, portMapping, input.getEndpoints());
+            sendingPCE.pathComputation();
+            String message = sendingPCE.getMessage();
+            String responseCode = sendingPCE.getResponseCode();
+            LOG.info("PCE response: {} {}", message, responseCode);
+            return output.setConfigurationResponseCommon(
+                    configurationResponseCommon
+                            .setAckFinalIndicator("Yes")
+                            .setResponseCode(responseCode)
+                            .setResponseMessage(message)
+                            .build())
+                    .build();
+        });
+    }
+
     public GnpyResponse generateGnpyResponse(Response responseGnpy, String pathDir) {
         if (responseGnpy == null) {
             return new GnpyResponseBuilder()
@@ -281,11 +333,11 @@ public class PathComputationServiceImpl implements PathComputationService {
                 .build();
         }
         if (responseGnpy.getResponseType()
-                instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.NoPathCase) {
+                instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase) {
             LOG.info("GNPy : path is not feasible");
-            org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.NoPathCase
+            org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase
                     noPathGnpy =
-                (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.NoPathCase)
+                (org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase)
                     responseGnpy.getResponseType();
             return new GnpyResponseBuilder()
                 .setPathDir(pathDir)
@@ -297,17 +349,17 @@ public class PathComputationServiceImpl implements PathComputationService {
                 .build();
         }
         if (responseGnpy.getResponseType()
-                instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase) {
+                instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase) {
             LOG.info("GNPy : path is feasible");
-            org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase
+            org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase
                     pathCase =
-                (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase)
+                (org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase)
                     responseGnpy.getResponseType();
-            List<org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathMetric>
+            List<org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric>
                     pathMetricList =
                 new ArrayList<>(pathCase.getPathProperties().getPathMetric().values());
             List<PathMetric> gnpyPathMetricList = new ArrayList<>();
-            for (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathMetric
+            for (org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric
                     pathMetricGnpy : pathMetricList) {
                 gnpyPathMetricList.add(
                     new PathMetricBuilder()