2 * Copyright © 2024 Smartoptics and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.renderer.provisiondevice.tasks;
11 import java.util.concurrent.Callable;
12 import java.util.concurrent.Future;
13 import org.opendaylight.mdsal.binding.api.RpcService;
14 import org.opendaylight.transportpce.common.ResponseCodes;
15 import org.opendaylight.transportpce.renderer.ServicePathInputData;
16 import org.opendaylight.transportpce.renderer.provisiondevice.OLMRenderingResult;
17 import org.opendaylight.transportpce.renderer.provisiondevice.notification.Notification;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndown;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.ServicePathNotificationTypes;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class OlmPowerTurnDownTask implements Callable<OLMRenderingResult> {
29 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerTurnDownTask.class);
30 private final String serviceName;
31 private final String path;
32 private final ServicePathInputData servicePathInputData;
33 private final Notification notification;
34 private final RpcService rpcService;
37 * Task used to power down OLM.
40 * Intended to be used for parallel execution.
42 public OlmPowerTurnDownTask(String serviceName, String path, ServicePathInputData servicePathInputData,
43 Notification notification, RpcService rpcService) {
45 this.serviceName = serviceName;
47 this.servicePathInputData = servicePathInputData;
48 this.notification = notification;
49 this.rpcService = rpcService;
53 public OLMRenderingResult call() throws Exception {
55 LOG.debug("Turning down power on {} path for service {}", path, serviceName);
57 Future<RpcResult<ServicePowerTurndownOutput>> fr = rpcService.getRpc(ServicePowerTurndown.class).invoke(
58 new ServicePowerTurndownInputBuilder(
59 servicePathInputData.getServicePathInput()
63 ServicePathNotificationTypes.ServiceDelete,
66 String.format("Turning down power on %s path for service %s", path, serviceName)
69 RpcResult<ServicePowerTurndownOutput> result = fr.get();
71 if (result == null || !ResponseCodes.SUCCESS_RESULT.equals(result.getResult().getResult())) {
73 ServicePathNotificationTypes.ServiceDelete,
76 String.format("Service power turn down failed on %s path for service %s", path, serviceName)
78 return OLMRenderingResult.failed(
79 String.format("Service power turn down failed on %s path for service %s", path, serviceName)
82 LOG.debug("OLM power turn down finished successfully on {} for service {}", path, serviceName);
83 return OLMRenderingResult.ok();