Merge changes Ib0dab687,Ia7e45116,I6839ad8b
authorGuillaume Lambert <guillaume.lambert@orange.com>
Tue, 12 Mar 2024 10:23:12 +0000 (10:23 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 12 Mar 2024 10:23:12 +0000 (10:23 +0000)
* changes:
  Turn down OLM power AtoZ and ZtoA in parallel
  Refactor RendererServiceOperationsImpl notify
  Olm Power Down Task

lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImpl.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/notification/Notification.java [new file with mode: 0644]
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/notification/NotificationSender.java [new file with mode: 0644]
renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/tasks/OlmPowerTurnDownTask.java [new file with mode: 0644]
renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplDeleteTest.java
renderer/src/test/java/org/opendaylight/transportpce/renderer/provisiondevice/RendererServiceOperationsImplTest.java

index d6e44ad9a80c9e26135e5101e5ef44e0a049791f..333236f4cb93bea026e24b1e1ee9daa26703a594 100644 (file)
@@ -55,6 +55,7 @@ import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererS
 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererServiceImpl;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperationsImpl;
+import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
 import org.opendaylight.transportpce.renderer.rpcs.DeviceRendererRPCImpl;
 import org.opendaylight.transportpce.renderer.rpcs.TransportPCEServicePathRPCImpl;
 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperationsImpl;
@@ -165,8 +166,9 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
         RendererServiceOperations rendererServiceOperations = new RendererServiceOperationsImpl(
                 deviceRendererService, otnDeviceRendererService, olmPowerServiceRpc,
                 lgServBDB,
-                lgServBNPS,
-                portMapping);
+                new NotificationSender(lgServBNPS),
+                portMapping
+            );
         ServiceDataStoreOperations serviceDataStoreOperations =
             new ServiceDataStoreOperationsImpl(lgServBDB);
         RendererNotificationHandler rendererNotificationHandler =
@@ -275,8 +277,11 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP
                             otnDeviceRendererService,
                             olmPowerServiceRpc,
                             lightyServices.getBindingDataBroker(),
-                            lightyServices.getBindingNotificationPublishService(),
-                            portMapping),
+                            new NotificationSender(
+                                lightyServices.getBindingNotificationPublishService()
+                            ),
+                            portMapping
+                        ),
                     lightyServices.getRpcProviderService())
                 .getRegisteredRpc());
     }
index cca076fa691a1650fea5b79820bfeba20706afea..a4053de0fe45d665c529fa0682e0b34f2277cf0b 100644 (file)
@@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
@@ -33,12 +32,14 @@ import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.service.ServiceTypes;
 import org.opendaylight.transportpce.renderer.ModelMappingUtils;
 import org.opendaylight.transportpce.renderer.ServicePathInputData;
+import org.opendaylight.transportpce.renderer.provisiondevice.notification.Notification;
 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.DeviceRenderingRollbackTask;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.DeviceRenderingTask;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.NetworkDeviceRenderingRollbackTask;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.OlmPowerSetupRollbackTask;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.OlmPowerSetupTask;
+import org.opendaylight.transportpce.renderer.provisiondevice.tasks.OlmPowerTurnDownTask;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.OtnDeviceRenderingTask;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.RollbackProcessor;
 import org.opendaylight.transportpce.renderer.provisiondevice.tasks.RollbackResultMessage;
@@ -50,12 +51,8 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkut
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSpBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
@@ -79,7 +76,6 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.Nodes;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -98,8 +94,8 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             "OLM power setup was not successful! Rendering and OLM will be rolled back.";
     private static final String RENDERING_DEVICES_A_Z_MSG = "Rendering devices A-Z";
     private static final String RENDERING_DEVICES_Z_A_MSG = "Rendering device Z-A";
-    private static final String TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG = "Turning down power on A-to-Z path";
-    private static final String FAILED = "Failed";
+    private static final String ATOZPATH = "A-to-Z";
+    private static final String ZTOAPATH = "Z-to-A";
     private static final String OPERATION_FAILED = "Operation Failed";
     private static final String OPERATION_SUCCESSFUL = "Operation Successful";
     private static final int NUMBER_OF_THREADS = 4;
@@ -108,7 +104,7 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
     private final OtnDeviceRendererService otnDeviceRenderer;
     private final TransportpceOlmService olmService;
     private final DataBroker dataBroker;
-    private final NotificationPublishService notificationPublishService;
+    private final Notification notification;
     private final PortMapping portMapping;
     private ListeningExecutorService executor;
 
@@ -117,13 +113,13 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             @Reference OtnDeviceRendererService otnDeviceRenderer,
             @Reference TransportpceOlmService olmService,
             @Reference DataBroker dataBroker,
-            @Reference NotificationPublishService notificationPublishService,
+            @Reference Notification notification,
             @Reference PortMapping portMapping) {
         this.deviceRenderer = deviceRenderer;
         this.otnDeviceRenderer = otnDeviceRenderer;
         this.olmService = olmService;
         this.dataBroker = dataBroker;
-        this.notificationPublishService = notificationPublishService;
+        this.notification = notification;
         this.portMapping = portMapping;
         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
         LOG.debug("RendererServiceOperationsImpl instantiated");
@@ -322,19 +318,6 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             .get(serviceName);
     }
 
-    @SuppressFBWarnings(
-            value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "call in call() method")
-    private ServicePowerTurndownOutput olmPowerTurndown(ServicePathInputData servicePathInputData)
-            throws InterruptedException, ExecutionException, TimeoutException {
-        LOG.debug(TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
-        return this.olmService
-            .servicePowerTurndown(
-                new ServicePowerTurndownInputBuilder(servicePathInputData.getServicePathInput()).build())
-            .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS)
-            .getResult();
-    }
-
     @SuppressFBWarnings(
             value = "UPM_UNCALLED_PRIVATE_METHOD",
             justification = "call in call() method")
@@ -720,48 +703,48 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             ModelMappingUtils.rendererCreateServiceInputAToZ(serviceName, pathDescription, Action.Delete);
         ServicePathInputData servicePathInputDataZtoA =
             ModelMappingUtils.rendererCreateServiceInputZToA(serviceName, pathDescription, Action.Delete);
-        // OLM turn down power
-        try {
-            LOG.debug(TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
-            sendNotifications(
-                ServicePathNotificationTypes.ServiceDelete,
-                serviceName,
-                RpcStatusEx.Pending,
-                TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
-            // TODO add some flag rather than string
-            if (FAILED.equals(
-                    olmPowerTurndown(servicePathInputDataAtoZ)
-                        .getResult())) {
-                LOG.error("Service power turndown failed on A-to-Z path for service {}!", serviceName);
-                sendNotifications(
-                    ServicePathNotificationTypes.ServiceDelete,
+
+        ListenableFuture<OLMRenderingResult> olmPowerTurnDownFutureAtoZ =
+            this.executor.submit(
+                new OlmPowerTurnDownTask(
                     serviceName,
-                    RpcStatusEx.Failed,
-                    "Service power turndown failed on A-to-Z path for service");
-                return false;
-            }
-            LOG.debug("Turning down power on Z-to-A path");
-            sendNotifications(
-                ServicePathNotificationTypes.ServiceDelete,
-                serviceName,
-                RpcStatusEx.Pending,
-                "Turning down power on Z-to-A path");
-            // TODO add some flag rather than string
-            if (FAILED.equals(
-                    olmPowerTurndown(servicePathInputDataZtoA)
-                        .getResult())) {
-                LOG.error("Service power turndown failed on Z-to-A path for service {}!", serviceName);
-                sendNotifications(
-                    ServicePathNotificationTypes.ServiceDelete,
+                    ATOZPATH,
+                    olmService,
+                    servicePathInputDataAtoZ,
+                    notification
+                )
+            );
+
+        ListenableFuture<OLMRenderingResult> olmPowerTurnDownFutureZtoA =
+            this.executor.submit(
+                new OlmPowerTurnDownTask(
                     serviceName,
-                    RpcStatusEx.Failed,
-                    "Service power turndown failed on Z-to-A path for service");
-                return false;
-            }
+                    ZTOAPATH,
+                    olmService,
+                    servicePathInputDataZtoA,
+                    notification
+                )
+            );
+
+        ListenableFuture<List<OLMRenderingResult>> olmPowerTurnDownFutures =
+            Futures.allAsList(olmPowerTurnDownFutureAtoZ, olmPowerTurnDownFutureZtoA);
+
+        List<OLMRenderingResult> olmRenderingResults;
+        // OLM turn down power
+        try {
+            LOG.info("Waiting for A-Z and Z-A OLM power turn down ...");
+            olmRenderingResults = olmPowerTurnDownFutures.get(
+                Timeouts.OLM_TIMEOUT, TimeUnit.MILLISECONDS
+            );
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.error("Error while turning down power!", e);
             return false;
         }
+        if (!olmRenderingResults.get(0).isSuccess() || !olmRenderingResults.get(1).isSuccess()) {
+            LOG.error("Error while turning down power!");
+            return false;
+        }
+        LOG.info("OLM power successfully turned down!");
         // delete service path with renderer
         LOG.info("Deleting service path via renderer");
         sendNotifications(
@@ -909,9 +892,13 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             String serviceName,
             RpcStatusEx rpcStatusEx,
             String message) {
-        send(
-            buildNotification(servicePathNotificationTypes, serviceName, rpcStatusEx, message,
-                null, null, null, null));
+
+        notification.send(
+            servicePathNotificationTypes,
+            serviceName,
+            rpcStatusEx,
+            message
+        );
     }
 
     /**
@@ -931,60 +918,19 @@ public class RendererServiceOperationsImpl implements RendererServiceOperations
             Link notifLink,
             Set<String> supportedLinks,
             String serviceType) {
-        send(
-            buildNotification(servicePathNotificationTypes, serviceName, rpcStatusEx, message,
-                pathDescription, notifLink, supportedLinks, serviceType));
-    }
 
-    /**
-     * Build notification containing path description information.
-     * @param servicePathNotificationTypes ServicePathNotificationTypes
-     * @param serviceName String
-     * @param rpcStatusEx RpcStatusEx
-     * @param message String
-     * @param pathDescription PathDescription
-     * @return notification with RendererRpcResultSp type.
-     */
-    private RendererRpcResultSp buildNotification(
-            ServicePathNotificationTypes servicePathNotificationTypes,
-            String serviceName,
-            RpcStatusEx rpcStatusEx,
-            String message,
-            PathDescription pathDescription,
-            Link notifLink,
-            Set<String> supportedLinks,
-            String serviceType) {
-        RendererRpcResultSpBuilder builder =
-            new RendererRpcResultSpBuilder()
-                .setNotificationType(servicePathNotificationTypes).setServiceName(serviceName).setStatus(rpcStatusEx)
-                .setStatusMessage(message)
-                .setServiceType(serviceType);
-        if (pathDescription != null) {
-            builder
-                .setAToZDirection(pathDescription.getAToZDirection())
-                .setZToADirection(pathDescription.getZToADirection());
-        }
-        if (notifLink != null) {
-            builder.setLink(notifLink);
-        }
-        if (supportedLinks != null) {
-            builder.setLinkId(supportedLinks);
-        }
-        return builder.build();
-    }
-
-    /**
-     * Send renderer notification.
-     * @param notification Notification
-     */
-    private void send(Notification<?> notification) {
-        try {
-            LOG.info("Sending notification {}", notification);
-            notificationPublishService.putNotification(notification);
-        } catch (InterruptedException e) {
-            LOG.info("notification offer rejected: ", e);
-            Thread.currentThread().interrupt();
-        }
+        notification.send(
+            notification.buildNotification(
+                servicePathNotificationTypes,
+                serviceName,
+                rpcStatusEx,
+                message,
+                pathDescription,
+                notifLink,
+                supportedLinks,
+                serviceType
+            )
+        );
     }
 
     private Link createLinkForNotif(List<LinkTp> otnLinkTerminationPoints) {
diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/notification/Notification.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/notification/Notification.java
new file mode 100644 (file)
index 0000000..422e351
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2024 Smartoptics and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.renderer.provisiondevice.notification;
+
+import java.util.Set;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
+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;
+
+public interface Notification {
+
+    /**
+     * Send renderer notification.
+     */
+    void send(ServicePathNotificationTypes servicePathNotificationTypes,
+              String serviceName,
+              RpcStatusEx rpcStatusEx,
+              String message);
+
+    /**
+     * Send renderer notification.
+     */
+    void send(org.opendaylight.yangtools.yang.binding.Notification notification);
+
+    /**
+     * Build notification containing path description information.
+     *
+     * @param servicePathNotificationTypes ServicePathNotificationTypes
+     * @param serviceName String
+     * @param rpcStatusEx RpcStatusEx
+     * @param message String
+     * @param pathDescription PathDescription
+     * @return notification with RendererRpcResultSp type.
+     */
+    RendererRpcResultSp buildNotification(
+            ServicePathNotificationTypes servicePathNotificationTypes,
+            String serviceName,
+            RpcStatusEx rpcStatusEx,
+            String message,
+            PathDescription pathDescription,
+            Link notifLink,
+            Set<String> supportedLinks,
+            String serviceType);
+
+}
diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/notification/NotificationSender.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/notification/NotificationSender.java
new file mode 100644 (file)
index 0000000..2856df7
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright © 2024 Smartoptics and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.renderer.provisiondevice.notification;
+
+import java.util.Set;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSpBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
+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.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+public class NotificationSender implements Notification {
+
+    private final NotificationPublishService notificationPublishService;
+
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationSender.class);
+
+    @Activate
+    public NotificationSender(@Reference NotificationPublishService notificationPublishService) {
+        this.notificationPublishService = notificationPublishService;
+    }
+
+    /**
+     * Send renderer notification.
+     */
+    public void send(ServicePathNotificationTypes servicePathNotificationTypes,
+                     String serviceName,
+                     RpcStatusEx rpcStatusEx,
+                     String message) {
+
+        send(
+            buildNotification(
+                servicePathNotificationTypes,
+                serviceName,
+                rpcStatusEx,
+                message,
+                null,
+                null,
+                null,
+                null
+            )
+        );
+    }
+
+    /**
+     * Send renderer notification.
+     * @param notification Notification
+     */
+    public void send(org.opendaylight.yangtools.yang.binding.Notification notification) {
+        try {
+            LOG.info("Sending notification {}", notification);
+            notificationPublishService.putNotification(notification);
+        } catch (InterruptedException e) {
+            LOG.info("notification offer rejected: ", e);
+            Thread.currentThread().interrupt();
+        }
+    }
+
+    /**
+     * Build notification containing path description information.
+     * @param servicePathNotificationTypes ServicePathNotificationTypes
+     * @param serviceName String
+     * @param rpcStatusEx RpcStatusEx
+     * @param message String
+     * @param pathDescription PathDescription
+     * @return notification with RendererRpcResultSp type.
+     */
+    @Override
+    public RendererRpcResultSp buildNotification(ServicePathNotificationTypes servicePathNotificationTypes,
+                                                 String serviceName,
+                                                 RpcStatusEx rpcStatusEx,
+                                                 String message,
+                                                 PathDescription pathDescription,
+                                                 Link notifLink,
+                                                 Set<String> supportedLinks,
+                                                 String serviceType) {
+
+        RendererRpcResultSpBuilder builder =
+            new RendererRpcResultSpBuilder()
+                .setNotificationType(servicePathNotificationTypes).setServiceName(serviceName).setStatus(rpcStatusEx)
+                .setStatusMessage(message)
+                .setServiceType(serviceType);
+        if (pathDescription != null) {
+            builder
+                .setAToZDirection(pathDescription.getAToZDirection())
+                .setZToADirection(pathDescription.getZToADirection());
+        }
+        if (notifLink != null) {
+            builder.setLink(notifLink);
+        }
+        if (supportedLinks != null) {
+            builder.setLinkId(supportedLinks);
+        }
+        return builder.build();
+    }
+}
diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/tasks/OlmPowerTurnDownTask.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/tasks/OlmPowerTurnDownTask.java
new file mode 100644 (file)
index 0000000..5308cc2
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2024 Smartoptics and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.renderer.provisiondevice.tasks;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+import org.opendaylight.transportpce.common.ResponseCodes;
+import org.opendaylight.transportpce.renderer.ServicePathInputData;
+import org.opendaylight.transportpce.renderer.provisiondevice.OLMRenderingResult;
+import org.opendaylight.transportpce.renderer.provisiondevice.notification.Notification;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
+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.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OlmPowerTurnDownTask implements Callable<OLMRenderingResult> {
+
+    private final String serviceName;
+
+    private final String path;
+
+    private final TransportpceOlmService olmService;
+
+    private final ServicePathInputData servicePathInputData;
+
+    private final Notification notification;
+
+    private static final Logger LOG = LoggerFactory.getLogger(OlmPowerTurnDownTask.class);
+
+    /**
+     * Task used to power down OLM.
+     *
+     * <p>
+     * Intended to be used for parallel execution.
+     */
+    public OlmPowerTurnDownTask(String serviceName,
+                                String path,
+                                TransportpceOlmService olmService,
+                                ServicePathInputData servicePathInputData,
+                                Notification notification) {
+
+        this.serviceName = serviceName;
+        this.path = path;
+        this.olmService = olmService;
+        this.servicePathInputData = servicePathInputData;
+        this.notification = notification;
+    }
+
+    @Override
+    public OLMRenderingResult call() throws Exception {
+
+        LOG.debug("Turning down power on {} path for service {}", path, serviceName);
+
+        Future<RpcResult<ServicePowerTurndownOutput>> fr = this.olmService.servicePowerTurndown(
+            new ServicePowerTurndownInputBuilder(
+                servicePathInputData.getServicePathInput()
+            ).build());
+
+        notification.send(
+            ServicePathNotificationTypes.ServiceDelete,
+            serviceName,
+            RpcStatusEx.Pending,
+            String.format("Turning down power on %s path for service %s", path, serviceName)
+        );
+
+        RpcResult<ServicePowerTurndownOutput> result = fr.get();
+
+        if (result == null || !ResponseCodes.SUCCESS_RESULT.equals(result.getResult().getResult())) {
+            notification.send(
+                ServicePathNotificationTypes.ServiceDelete,
+                serviceName,
+                RpcStatusEx.Failed,
+                String.format("Service power turn down failed on %s path for service %s", path, serviceName)
+            );
+            return OLMRenderingResult.failed(
+                String.format("Service power turn down failed on %s path for service %s", path, serviceName)
+            );
+        } else {
+            LOG.debug("OLM power turn down finished successfully on {} for service {}", path, serviceName);
+            return OLMRenderingResult.ok();
+        }
+    }
+}
index 0a20bde92f6f7d6930a0f3f69b0e7a815454b687..cf8eb6345ac910c38a85f5b1e217576edcaa8e02 100644 (file)
@@ -37,6 +37,7 @@ import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
@@ -91,7 +92,8 @@ public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
         this.olmService = spy(this.olmService);
         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
         this.rendererServiceOperations =  new RendererServiceOperationsImpl(deviceRenderer,
-            otnDeviceRendererService, olmService, getDataBroker(), notificationPublishService, portMapping);
+            otnDeviceRendererService, olmService, getDataBroker(), new NotificationSender(notificationPublishService),
+            portMapping);
     }
 
 
index fe1973618c1953c37a4386b1d65ac46f92c51d9b..6df33027a2248a124ebac183c2096b70d6489513 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfa
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
+import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
@@ -92,7 +93,7 @@ public class RendererServiceOperationsImplTest extends AbstractTest {
         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
         this.olmService = spy(this.olmService);
         this.rendererServiceOperations =  new RendererServiceOperationsImpl(deviceRenderer, otnDeviceRendererService,
-                this.olmService, getDataBroker(), notificationPublishService, portMapping);
+                this.olmService, getDataBroker(), new NotificationSender(notificationPublishService), portMapping);
     }
 
     @Test