X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fservice%2FPathComputationServiceImpl.java;fp=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fservice%2FPathComputationServiceImpl.java;h=aa598c73160be1438d207c56a28317d1a6bc0308;hb=1b8941461b6f81f6f7b018f6fc6907d1c7d1292d;hp=34595a9706b59d82e8f301e8b4c34ba04192b888;hpb=5e3f7dd89cb088ef4957f5559a82b8c6436afa17;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 34595a970..aa598c731 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 @@ -35,12 +35,8 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev22 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.ResponseType; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.gnpy.gnpy.response.response.type.NoPathCase; 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.PathCase; 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.PathProperties; 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; @@ -86,11 +82,18 @@ public class PathComputationServiceImpl implements PathComputationService { @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) { + private void sendNotifications( + ServicePathNotificationTypes servicePathNotificationTypes, + String serviceName, + RpcStatusEx rpcStatusEx, + String message, + PathDescription pathDescription) { ServicePathRpcResultBuilder servicePathRpcResultBuilder = - new ServicePathRpcResultBuilder().setNotificationType(servicePathNotificationTypes) - .setServiceName(serviceName).setStatus(rpcStatusEx).setStatusMessage(message); + new ServicePathRpcResultBuilder() + .setNotificationType(servicePathNotificationTypes) + .setServiceName(serviceName) + .setStatus(rpcStatusEx) + .setStatusMessage(message); if (pathDescription != null) { servicePathRpcResultBuilder.setPathDescription(pathDescription); } @@ -109,27 +112,33 @@ public class PathComputationServiceImpl implements PathComputationService { @Override public CancelResourceReserveOutput call() throws Exception { - String message = ""; - sendNotifications(ServicePathNotificationTypes.CancelResourceReserve, input.getServiceName(), - RpcStatusEx.Pending, "Service compliant, submitting cancelResourceReserve Request ...", null); + sendNotifications( + ServicePathNotificationTypes.CancelResourceReserve, + input.getServiceName(), + RpcStatusEx.Pending, + "Service compliant, submitting cancelResourceReserve Request ...", + null); PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(gnpyConsumer); sendingPCE.cancelResourceReserve(); - if (Boolean.TRUE.equals(sendingPCE.getSuccess())) { - message = "ResourceReserve cancelled !"; - } else { - message = "Cancelling ResourceReserve failed !"; - } - LOG.info("in PathComputationServiceImpl : {}",message); - sendNotifications(ServicePathNotificationTypes.CancelResourceReserve, input.getServiceName(), - RpcStatusEx.Successful, "cancel Resource Reserve successful!", null); - ConfigurationResponseCommonBuilder configurationResponseCommon = - new ConfigurationResponseCommonBuilder(); - configurationResponseCommon.setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()).setResponseCode("200") - .setResponseMessage(""); - CancelResourceReserveOutputBuilder output = new CancelResourceReserveOutputBuilder(); - output.setConfigurationResponseCommon(configurationResponseCommon.build()); - return output.build(); + LOG.info("in PathComputationServiceImpl : {}", + Boolean.TRUE.equals(sendingPCE.getSuccess()) + ? "ResourceReserve cancelled !" + : "Cancelling ResourceReserve failed !"); + sendNotifications( + ServicePathNotificationTypes.CancelResourceReserve, + input.getServiceName(), + RpcStatusEx.Successful, + "cancel Resource Reserve successful!", + null); + return new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon( + new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode("200") + .setResponseMessage("") + .build()) + .build(); } }); } @@ -147,26 +156,33 @@ public class PathComputationServiceImpl implements PathComputationService { PceComplianceCheckResult check = PceComplianceCheck.check(input); if (!check.hasPassed()) { LOG.error("Path not calculated, service not compliant : {}", check.getMessage()); - sendNotifications(ServicePathNotificationTypes.PathComputationRequest, input.getServiceName(), - RpcStatusEx.Failed, "Path not calculated, service not compliant", null); - configurationResponseCommon.setAckFinalIndicator("Yes") + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Failed, + "Path not calculated, service not compliant", + null); + configurationResponseCommon + .setAckFinalIndicator("Yes") .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode("Path not calculated").setResponseMessage(check.getMessage()); - output.setConfigurationResponseCommon(configurationResponseCommon.build()) - .setResponseParameters(null); - return output.build(); + .setResponseCode("Path not calculated") + .setResponseMessage(check.getMessage()); + return output + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .setResponseParameters(null) + .build(); } - sendNotifications(ServicePathNotificationTypes.PathComputationRequest, input.getServiceName(), - RpcStatusEx.Pending, "Service compliant, submitting pathComputation Request ...", null); - String message = ""; - String responseCode = ""; - PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(input, networkTransactionService, - gnpyConsumer, portMapping); + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Pending, + "Service compliant, submitting pathComputation Request ...", + null); + PceSendingPceRPCs sendingPCE = + new PceSendingPceRPCs(input, networkTransactionService, gnpyConsumer, portMapping); sendingPCE.pathComputation(); - message = sendingPCE.getMessage(); - responseCode = sendingPCE.getResponseCode(); - PathDescriptionBuilder path = null; - path = sendingPCE.getPathDescription(); + String message = sendingPCE.getMessage(); + String responseCode = sendingPCE.getResponseCode(); LOG.info("PCE response: {} {}", message, responseCode); //add the GNPy result @@ -181,41 +197,59 @@ public class PathComputationServiceImpl implements PathComputationService { GnpyResponse respZtoA = generateGnpyResponse(gnpyZtoA.getResponse(),"Z-to-A"); listResponse.add(respZtoA); } - output.setGnpyResponse(listResponse.stream() - .collect(Collectors.toMap(GnpyResponse::key, gnpyResponse -> gnpyResponse))); + output + .setGnpyResponse( + listResponse.stream() + .collect(Collectors.toMap(GnpyResponse::key, gnpyResponse -> gnpyResponse))); + PathDescriptionBuilder path = sendingPCE.getPathDescription(); if (Boolean.FALSE.equals(sendingPCE.getSuccess()) || (path == null)) { - configurationResponseCommon.setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()).setResponseCode(responseCode) - .setResponseMessage(message); - output.setConfigurationResponseCommon(configurationResponseCommon.build()); - sendNotifications(ServicePathNotificationTypes.PathComputationRequest, input.getServiceName(), - RpcStatusEx.Failed, "Path not calculated", null); - return output.build(); + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Failed, + "Path not calculated", + null); + return output + .setConfigurationResponseCommon( + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message) + .build()) + .build(); } // Path calculator returned Success - configurationResponseCommon.setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()).setResponseCode(responseCode) - .setResponseMessage(message); PathDescription pathDescription = - new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.service.path.rpc - .result.PathDescriptionBuilder() + new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118 + .service.path.rpc.result.PathDescriptionBuilder() .setAToZDirection(path.getAToZDirection()) .setZToADirection(path.getZToADirection()) .build(); - sendNotifications(ServicePathNotificationTypes.PathComputationRequest, input.getServiceName(), - RpcStatusEx.Successful, message, pathDescription); - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response - .parameters.sp.response.parameters.PathDescription pathDescription1 = + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Successful, + message, + pathDescription); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118 + .response.parameters.sp.response.parameters.PathDescription pathDescription1 = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118 .response.parameters.sp.response.parameters.PathDescriptionBuilder() .setAToZDirection(path.getAToZDirection()) .setZToADirection(path.getZToADirection()) .build(); - ResponseParametersBuilder rpb = new ResponseParametersBuilder().setPathDescription(pathDescription1); - output.setConfigurationResponseCommon(configurationResponseCommon.build()) - .setResponseParameters(rpb.build()); - + output + .setConfigurationResponseCommon( + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message) + .build()) + .setResponseParameters( + new ResponseParametersBuilder().setPathDescription(pathDescription1).build()); //debug prints AToZDirection atoz = pathDescription.getAToZDirection(); if ((atoz != null) && (atoz.getAToZ() != null)) { @@ -239,44 +273,66 @@ public class PathComputationServiceImpl implements PathComputationService { } public GnpyResponse generateGnpyResponse(Response responseGnpy, String pathDir) { - ResponseType respType = null; - boolean feasible = true; - if (responseGnpy != null) { - if (responseGnpy.getResponseType() instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220221.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 - noPathGnpy = (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.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.rev220221.result - .response.response.type.PathCase) { - LOG.info("GNPy : path is feasible"); - org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase pathCase = - (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase) - responseGnpy.getResponseType(); - List pathMetricList = - new ArrayList<>(pathCase.getPathProperties().getPathMetric().values()); - List gnpyPathMetricList = new ArrayList<>(); - for (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.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.stream() - .collect(Collectors.toMap(PathMetric::key, pathMetric -> pathMetric))) - .build(); - PathCase gnpyPathCase = new PathCaseBuilder().setPathProperties(pathProperties).build(); - respType = gnpyPathCase; - feasible = true; + if (responseGnpy == null) { + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType(null) + .setFeasibility(true) + .build(); + } + if (responseGnpy.getResponseType() + instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220221.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 + noPathGnpy = + (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.NoPathCase) + responseGnpy.getResponseType(); + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType( + new NoPathCaseBuilder() + .setNoPath(noPathGnpy.getNoPath()) + .build()) + .setFeasibility(false) + .build(); + } + if (responseGnpy.getResponseType() + instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase) { + LOG.info("GNPy : path is feasible"); + org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase + pathCase = + (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase) + responseGnpy.getResponseType(); + List + pathMetricList = + new ArrayList<>(pathCase.getPathProperties().getPathMetric().values()); + List gnpyPathMetricList = new ArrayList<>(); + for (org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathMetric + pathMetricGnpy : pathMetricList) { + gnpyPathMetricList.add( + new PathMetricBuilder() + .setMetricType(pathMetricGnpy.getMetricType()) + .setAccumulativeValue(pathMetricGnpy.getAccumulativeValue()) + .build()); } + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType( + new PathCaseBuilder() + .setPathProperties( + new PathPropertiesBuilder() + .setPathMetric(gnpyPathMetricList.stream() + .collect(Collectors.toMap(PathMetric::key, pathMetric -> pathMetric))) + .build()) + .build()) + .setFeasibility(true) + .build(); } - return new GnpyResponseBuilder().setPathDir(pathDir).setResponseType(respType).setFeasibility(feasible).build(); + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType(null) + .setFeasibility(true) + .build(); } }