Merge "Fix bug for temp-service-delete"
authorGilles Thouenon <gilles.thouenon@orange.com>
Thu, 21 Sep 2023 12:12:24 +0000 (12:12 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 21 Sep 2023 12:12:24 +0000 (12:12 +0000)
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/PceListenerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/listeners/RendererListenerImpl.java
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapper.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/RendererServiceWrapperTest.java

index d502e818e98ddd051b7da54c6841023eb1bcbe58..0051deb332a2aa6a8fef6a0e1de85c520ee6567e 100644 (file)
@@ -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<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list.Services>
-                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(
index 7d92eb067055588eec221b7dcca84bd9ed4cb773..8aeaa66fdfee16da1ef7f9087e693b4d1aa5d118 100644 (file)
@@ -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.
          */
index e5214069dcbf8ec4b16c9e8604e7dbd7e580b1fc..1de11948fb34a071101fa130a08754552175a1d9 100644 (file)
@@ -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);
                 }
             }
index 0f9d908d8b04678317ac3d7c6d052992f44b8d9e..4bfaa6ebabef0b3d92c591f9a50beded7439bb8b 100644 (file)
@@ -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<ServiceDeleteOutput> rendererCallback =
+                new ServiceDeleteOutputFutureCallback(notifType, commonId);
+        ServiceDeleteInput serviceDeleteInput = createRendererRequestInput(commonId, serviceHandlerHeader);
+        // Here build the regular service-list container from the temp-service-list
+        ListenableFuture<ServiceDeleteOutput> 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,
index 1d2d78b3faf05a5f17fa11ce092bf4fa2d7d0afc..f2e4f8db0aa2c588229225c6f98991276cf95378 100644 (file)
@@ -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());