From e992d2f2b981e634e8bb865dbf72fafc06d91c2e Mon Sep 17 00:00:00 2001 From: "Balagangadhar (Bala) Bathula" Date: Mon, 31 Jul 2023 12:19:42 -0400 Subject: [PATCH] Fix bug for temp-service-delete - Currently, temp-service-delete does not work and creates a null-pointer exception, when used. The code uses service-list instead of temp-service-list to retrieve data for the delete operations. - Add additional code to retrieve the data from the temp-service-list - Update transport-pce-service-list after the temp-service is deleted - Update temp-service-list after the temp-service-delete JIRA: TRNSPRTPCE-750 Signed-off-by: Balagangadhar (Bala) Bathula Change-Id: Ia12d67c8bfdc81b934ae2fa292d941e1ce775e3a --- .../impl/ServicehandlerImpl.java | 13 ++-- .../listeners/PceListenerImpl.java | 46 +++++++++---- .../listeners/RendererListenerImpl.java | 2 + .../service/RendererServiceWrapper.java | 66 ++++++++++++++++--- .../service/RendererServiceWrapperTest.java | 5 +- 5 files changed, 104 insertions(+), 28 deletions(-) diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java index d502e818e..0051deb33 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java @@ -320,7 +320,9 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { LOG.debug("serviceDelete: Service '{}' found in datastore", serviceName); this.pceListenerImpl.setInput(new ServiceInput(input)); this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setTempService(false); this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); + this.rendererListenerImpl.setTempService(false); this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); @@ -629,25 +631,28 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { //Check presence of service to be deleted LOG.debug("service common-id '{}' is compliant", commonId); Optional - service = + serviceOpt = this.serviceDataStoreOperations.getTempService(commonId); - if (service.isEmpty()) { + if (serviceOpt.isEmpty()) { LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(commonId)); return ModelMappingUtils.createDeleteServiceReply( input, ResponseCodes.FINAL_ACK_YES, LogMessages.serviceNotInDS(commonId), ResponseCodes.RESPONSE_FAILED); } - LOG.info("Service '{}' present in datastore !", commonId); this.pceListenerImpl.setInput(new ServiceInput(input)); this.pceListenerImpl.setServiceReconfigure(false); + this.pceListenerImpl.setTempService(true); this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations); this.rendererListenerImpl.setServiceInput(new ServiceInput(input)); this.rendererListenerImpl.setTempService(true); this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations); + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services service = serviceOpt.orElseThrow(); org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput output = - this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult, + service); if (output == null) { LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED); return ModelMappingUtils.createDeleteServiceReply( 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 7d92eb067..8aeaa66fd 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 @@ -223,26 +223,45 @@ public class PceListenerImpl implements TransportpcePceListener, PceListener { LOG.error("PCE cancel returned an unknown RpcStatusEx code !"); return; } - Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow(); - PublishNotificationProcessServiceBuilder nbiNotificationBuilder = - new PublishNotificationProcessServiceBuilder() - .setServiceName(service.getServiceName()) - .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build()) - .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build()) - .setCommonId(service.getCommonId()) - .setConnectionType(service.getConnectionType()) - .setPublisherName(PUBLISHER); + PublishNotificationProcessServiceBuilder nbiNotificationBuilder; + State serviceOpState; + if (tempService) { + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list.Services + tempServiceList = serviceDataStoreOperations.getTempService(input.getServiceName()).orElseThrow(); + serviceOpState = tempServiceList.getOperationalState(); + nbiNotificationBuilder = + new PublishNotificationProcessServiceBuilder() + .setServiceAEnd(new ServiceAEndBuilder(tempServiceList.getServiceAEnd()).build()) + .setServiceZEnd(new ServiceZEndBuilder(tempServiceList.getServiceZEnd()).build()) + .setCommonId(tempServiceList.getCommonId()) + .setConnectionType(tempServiceList.getConnectionType()) + .setPublisherName(PUBLISHER); + } else { + Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow(); + serviceOpState = service.getOperationalState(); + nbiNotificationBuilder = + new PublishNotificationProcessServiceBuilder() + .setServiceName(service.getServiceName()) + .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build()) + .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build()) + .setCommonId(service.getCommonId()) + .setConnectionType(service.getConnectionType()) + .setPublisherName(PUBLISHER); + + } + if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) { LOG.info("PCE cancel resource failed !"); sendNbiNotification( nbiNotificationBuilder .setResponseFailed("PCE cancel resource failed !") .setMessage("ServiceDelete request failed ...") - .setOperationalState(service.getOperationalState()) + .setOperationalState(serviceOpState) .build()); return; } LOG.info("PCE cancel resource done OK !"); + // Here the input refers to the transportPCE API and the serviceName will be commonId for temp-service OperationResult deleteServicePathOperationResult = this.serviceDataStoreOperations.deleteServicePath(input.getServiceName()); if (!deleteServicePathOperationResult.isSuccess()) { @@ -260,18 +279,19 @@ public class PceListenerImpl implements TransportpcePceListener, PceListener { sendNbiNotification( nbiNotificationBuilder .setResponseFailed("") - .setMessage("Service deleted !") + .setMessage("{} Service deleted !") .setOperationalState(State.Degraded) .build()); } else { - LOG.warn("{}Service was not removed from datastore !", serviceType); + LOG.warn("{} Service was not removed from datastore !", serviceType); sendNbiNotification( nbiNotificationBuilder .setResponseFailed(serviceType + "Service was not removed from datastore !") .setMessage("ServiceDelete request failed ...") - .setOperationalState(service.getOperationalState()) + .setOperationalState(serviceOpState) .build()); } + // TODO: should we re-initialize the temp-service boolean to false? /** * if it was an RPC serviceReconfigure, re-launch PCR. */ diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java index e5214069d..1de11948f 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java @@ -205,6 +205,8 @@ public class RendererListenerImpl implements TransportpceRendererListener, Rende LOG.info("Temp-service exists with the common-Id {}", commonId); // Delete the common-id from this temp-service-list here OperationResult tempServiceListDelete = serviceDataStoreOperations.deleteTempService(commonId); + //TODO: Also need to delete the service-path from the transportpce-service-path list + this.serviceDataStoreOperations.deleteServicePath(commonId); LOG.info("Result for temp-service-list with {} is {}", commonId, tempServiceListDelete); } } diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java index 0f9d908d8..4bfaa6eba 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java @@ -25,8 +25,11 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.serviceha import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.ServiceAEndBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.ServiceZEndBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.ServicesBuilder; 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.service.handler.header.ServiceHandlerHeader; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.handler.header.ServiceHandlerHeaderBuilder; @@ -72,16 +75,61 @@ public class RendererServiceWrapper { } } - public ServiceDeleteOutput performRenderer(TempServiceDeleteInput tempServiceDeleteInput, - ServiceNotificationTypes notifType) { + + // TODO: Here is where the we are sending null values for the service and that is causing issues + // We are performing renderer using null values + public ServiceDeleteOutput performRenderer( + TempServiceDeleteInput tempServiceDeleteInput, + ServiceNotificationTypes notifType, + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services tempService) { String commonId = tempServiceDeleteInput.getCommonId(); - if (validateParams(commonId, null, true)) { - ServiceHandlerHeader serviceHandler = new ServiceHandlerHeaderBuilder().setRequestId(commonId).build(); - return performRenderer(tempServiceDeleteInput.getCommonId(), serviceHandler, - ServiceNotificationTypes.ServiceDeleteResult, null); - } else { - return returnRendererFailed(); - } + return validateParams(commonId, null, true) + ? performRenderer(tempServiceDeleteInput, + new ServiceHandlerHeaderBuilder().setRequestId(commonId).build(), + ServiceNotificationTypes.ServiceDeleteResult, + tempService) + : returnRendererFailed(); + } + + private ServiceDeleteOutput performRenderer( + TempServiceDeleteInput tempServiceDeleteInput, + ServiceHandlerHeader serviceHandlerHeader, + ServiceNotificationTypes notifType, + org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526 + .temp.service.list.Services tempService) { + String commonId = tempServiceDeleteInput.getCommonId(); + notification = new ServiceRpcResultShBuilder() + .setNotificationType(notifType) + .setServiceName(commonId) + .setStatus(RpcStatusEx.Pending) + .setStatusMessage("Service compliant, submitting temp service delete Request ...") + .build(); + sendNotifications(notification); + FutureCallback rendererCallback = + new ServiceDeleteOutputFutureCallback(notifType, commonId); + ServiceDeleteInput serviceDeleteInput = createRendererRequestInput(commonId, serviceHandlerHeader); + // Here build the regular service-list container from the temp-service-list + ListenableFuture renderer = + this.rendererServiceOperations.serviceDelete(serviceDeleteInput, + new ServicesBuilder() + .setServiceName(commonId) + .setServiceAEnd(new ServiceAEndBuilder(tempService.getServiceAEnd()).build()) + .setServiceZEnd(new ServiceZEndBuilder(tempService.getServiceZEnd()).build()) + .setCommonId(commonId) + .build()); + Futures.addCallback(renderer, rendererCallback, executor); + return new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon( + new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO) + .setRequestId(serviceDeleteInput + .getServiceHandlerHeader() + .getRequestId()) + .setResponseCode(ResponseCodes.RESPONSE_OK) + .setResponseMessage("Renderer temp-service delete in progress") + .build()) + .build(); } private ServiceDeleteOutput performRenderer(String serviceName, ServiceHandlerHeader serviceHandlerHeader, diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java index 1d2d78b3f..f2e4f8db0 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java @@ -83,7 +83,7 @@ public class RendererServiceWrapperTest extends AbstractTest { TempServiceDeleteInput input = new TempServiceDeleteInputBuilder(ServiceDataUtils.buildTempServiceDeleteInput()) .setCommonId(null).build(); ServiceDeleteOutput response = this.rendererServiceWrapperMock - .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult, null); assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator()); assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode()); verifyNoInteractions(this.rendererServiceOperationsMock); @@ -132,8 +132,9 @@ public class RendererServiceWrapperTest extends AbstractTest { .class), any())) .thenReturn(response); TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); + var tempServiceDeleteInput = ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input)); ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock - .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult); + .performRenderer(tempServiceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null); assertEquals( ResponseCodes.FINAL_ACK_NO, rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator()); -- 2.36.6