Olm Power Down Task 57/110257/8
authorJoakim Törnqvist <joakim.tornqvist@smartoptics.com>
Fri, 16 Feb 2024 12:15:13 +0000 (12:15 +0000)
committerJoakim Törnqvist <joakim.tornqvist@smartoptics.com>
Tue, 27 Feb 2024 15:28:56 +0000 (15:28 +0000)
A task capable of running in parallel powering down OLM power.
The package also contains an Interface left open to be implemented
at a later time.

Pseudo code example usage:

ListenableFuture<OLMRenderingResult> futureAtoZ =
    this.executor.submit(
        new OlmPowerTurnDownTask(...)
    );

ListenableFuture<OLMRenderingResult> futureZtoA =
    this.executor.submit(
        new OlmPowerTurnDownTask(...)
    );

ListenableFuture<List<OLMRenderingResult>> futures =
    Futures.allAsList(futureAtoZ, futureZtoA);

List<OLMRenderingResult> results;

try{
    results = futures.get(Timeouts.OLM_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
    LOG.error("Error while turning down power!");
}

if (results.get(0).isSuccess() && results.get(1).isSuccess()) {
    LOG.info("OLM power successfully turned down");
}

JIRA: TRNSPRTPCE-616
Change-Id: I6839ad8bdd5feeec5bcd63700efe55c8aed01085
Signed-off-by: Joakim Törnqvist <joakim.tornqvist@smartoptics.com>
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/tasks/OlmPowerTurnDownTask.java [new file with mode: 0644]

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/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();
+        }
+    }
+}