X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Flisteners%2FPceListenerImpl.java;h=65e199b4fa0470d0b762b9c0ecc807f6700ab9da;hb=a07392226a2e30930323959a5f6925812f5192ae;hp=2a4b5a43ccb0c54ea592ef7e59212ccaa345c684;hpb=b115d446ae97ff4e7def0ad5c96beaa13191e5b0;p=transportpce.git diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java index 2a4b5a43c..65e199b4f 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java @@ -7,7 +7,8 @@ */ package org.opendaylight.transportpce.servicehandler.listeners; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.pce.service.PathComputationService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; @@ -15,16 +16,16 @@ import org.opendaylight.transportpce.servicehandler.ModelMappingUtils; import org.opendaylight.transportpce.servicehandler.ServiceInput; import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.ServicePathRpcResult; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.TransportpcePceListener; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.service.path.rpc.result.PathDescription; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.service.path.rpc.result.PathDescriptionBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder; +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.TransportpcePceListener; +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.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceImplementationRequestInput; +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.response.parameters.sp.ResponseParameters; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,109 +58,125 @@ public class PceListenerImpl implements TransportpcePceListener { public void onServicePathRpcResult(ServicePathRpcResult notification) { if (!compareServicePathRpcResult(notification)) { servicePathRpcResult = notification; - PathDescription pathDescription = null; switch (servicePathRpcResult.getNotificationType().getIntValue()) { /* path-computation-request. */ case 1: - LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(), - notification); - if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) { - LOG.info("PCE calculation done OK !"); - if (servicePathRpcResult.getPathDescription() != null) { - pathDescription = new PathDescriptionBuilder() - .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection()) - .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build(); - LOG.info("PathDescription gets : {}", pathDescription); - if (!serviceFeasiblity) { - if (input == null) { - LOG.error("Input is null !"); - return; - } - OperationResult operationResult = null; - if (tempService) { - operationResult = this.serviceDataStoreOperations - .createTempService(input.getTempServiceCreateInput()); - if (!operationResult.isSuccess()) { - LOG.error("Temp Service not created in datastore !"); - } - } else { - operationResult = this.serviceDataStoreOperations - .createService(input.getServiceCreateInput()); - if (!operationResult.isSuccess()) { - LOG.error("Service not created in datastore !"); - } - } - ResponseParameters responseParameters = new ResponseParametersBuilder() - .setPathDescription(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c - ._interface.service.types.rev171016.response.parameters.sp.response - .parameters.PathDescriptionBuilder(pathDescription).build()) - .build(); - PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder() - .setResponseParameters(responseParameters).build(); - OperationResult operationServicePathSaveResult = - this.serviceDataStoreOperations.createServicePath(input, pceResponse); - if (!operationServicePathSaveResult.isSuccess()) { - LOG.error("Service Path not created in datastore !"); - } - ServiceImplementationRequestInput serviceImplementationRequest = - ModelMappingUtils.createServiceImplementationRequest(input, pathDescription); - LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest); - this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest); - } else { - LOG.warn("service-feasibility-check RPC "); - } - } else { - LOG.error("'PathDescription' parameter is null "); - return; - } - } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) { - LOG.error("PCE path computation failed !"); - return; - } + onPathComputationResult(notification); break; /* cancel-resource-reserve. */ case 2: - if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) { - LOG.info("PCE cancel resource done OK !"); - OperationResult deleteServicePathOperationResult = - this.serviceDataStoreOperations.deleteServicePath(input.getServiceName()); - if (!deleteServicePathOperationResult.isSuccess()) { - LOG.warn("Service path was not removed from datastore!"); - } - OperationResult deleteServiceOperationResult = null; + onCancelResourceResult(); + break; + default: + break; + } + } else { + LOG.warn("ServicePathRpcResult already wired !"); + } + } + + /** + * Process path computation request result. + * @param notification the result notification. + */ + private void onPathComputationResult(ServicePathRpcResult notification) { + LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(), + notification); + if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) { + LOG.info("PCE calculation done OK !"); + if (servicePathRpcResult.getPathDescription() != null) { + PathDescription pathDescription = new PathDescriptionBuilder() + .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection()) + .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build(); + LOG.info("PathDescription gets : {}", pathDescription); + if (!serviceFeasiblity) { + if (input == null) { + LOG.error("Input is null !"); + } else { + OperationResult operationResult = null; if (tempService) { - deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteTempService(input.getServiceName()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); + operationResult = this.serviceDataStoreOperations + .createTempService(input.getTempServiceCreateInput()); + if (!operationResult.isSuccess()) { + LOG.error("Temp Service not created in datastore !"); } } else { - deleteServiceOperationResult = - this.serviceDataStoreOperations.deleteService(input.getServiceName()); - if (!deleteServiceOperationResult.isSuccess()) { - LOG.warn("Service was not removed from datastore!"); + operationResult = this.serviceDataStoreOperations + .createService(input.getServiceCreateInput()); + if (!operationResult.isSuccess()) { + LOG.error("Service not created in datastore !"); } } - /** - * if it was an RPC serviceReconfigure, re-launch PCR. - */ - if (this.serviceReconfigure) { - LOG.info("cancel resource reserve done, relaunching PCE path computation ..."); - this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true); - this.serviceReconfigure = false; + ResponseParameters responseParameters = new ResponseParametersBuilder() + .setPathDescription(new org.opendaylight.yang.gen.v1.http.org + .transportpce.b.c._interface.service.types.rev200128 + .response.parameters.sp.response.parameters + .PathDescriptionBuilder(pathDescription).build()) + .build(); + PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder() + .setResponseParameters(responseParameters).build(); + OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations + .createServicePath(input, pceResponse); + if (!operationServicePathSaveResult.isSuccess()) { + LOG.error("Service Path not created in datastore !"); } - } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) { - LOG.info("PCE cancel resource failed !"); + ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils + .createServiceImplementationRequest(input, pathDescription); + LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest); + this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest); } - break; - default: - break; + } else { + LOG.warn("service-feasibility-check RPC "); + } + } else { + LOG.error("'PathDescription' parameter is null "); } - } else { - LOG.warn("ServicePathRpcResult already wired !"); + } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) { + LOG.error("PCE path computation failed !"); + } + } + + /** + * Process cancel resource result. + */ + private void onCancelResourceResult() { + if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) { + LOG.info("PCE cancel resource done OK !"); + OperationResult deleteServicePathOperationResult = + this.serviceDataStoreOperations.deleteServicePath(input.getServiceName()); + if (!deleteServicePathOperationResult.isSuccess()) { + LOG.warn("Service path was not removed from datastore!"); + } + OperationResult deleteServiceOperationResult = null; + if (tempService) { + deleteServiceOperationResult = + this.serviceDataStoreOperations.deleteTempService(input.getServiceName()); + if (!deleteServiceOperationResult.isSuccess()) { + LOG.warn("Service was not removed from datastore!"); + } + } else { + deleteServiceOperationResult = + this.serviceDataStoreOperations.deleteService(input.getServiceName()); + if (!deleteServiceOperationResult.isSuccess()) { + LOG.warn("Service was not removed from datastore!"); + } + } + /** + * if it was an RPC serviceReconfigure, re-launch PCR. + */ + if (this.serviceReconfigure) { + LOG.info("cancel resource reserve done, relaunching PCE path computation ..."); + this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true); + this.serviceReconfigure = false; + } + } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) { + LOG.info("PCE cancel resource failed !"); } } + @SuppressFBWarnings( + value = "ES_COMPARING_STRINGS_WITH_EQ", + justification = "false positives, not strings but real object references comparisons") private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) { Boolean result = true; if (servicePathRpcResult == null) { @@ -168,13 +185,13 @@ public class PceListenerImpl implements TransportpcePceListener { if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) { result = false; } - if (!servicePathRpcResult.getServiceName().equals(notification.getServiceName())) { + if (servicePathRpcResult.getServiceName() != notification.getServiceName()) { result = false; } if (servicePathRpcResult.getStatus() != notification.getStatus()) { result = false; } - if (!servicePathRpcResult.getStatusMessage().equals(notification.getStatusMessage())) { + if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) { result = false; } }