Bump upstream dependencies to Ca
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / OlmPowerSetupTask.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.renderer.provisiondevice.tasks;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.concurrent.Callable;
13 import java.util.concurrent.Future;
14 import org.opendaylight.transportpce.common.ResponseCodes;
15 import org.opendaylight.transportpce.renderer.provisiondevice.OLMRenderingResult;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetup;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class OlmPowerSetupTask implements Callable<OLMRenderingResult> {
24
25     private static final Logger LOG = LoggerFactory.getLogger(OlmPowerSetupTask.class);
26
27     private final ServicePowerSetup servicePowerSetup;
28     private final ServicePowerSetupInput input;
29
30     public OlmPowerSetupTask(ServicePowerSetup servicePowerSetup, ServicePowerSetupInput input) {
31         this.servicePowerSetup = requireNonNull(servicePowerSetup);
32         this.input = input;
33     }
34
35     @Override
36     public OLMRenderingResult call() throws Exception {
37         Future<RpcResult<ServicePowerSetupOutput>> fr = servicePowerSetup.invoke(this.input);
38         RpcResult<ServicePowerSetupOutput> result = fr.get();
39         if (result == null) {
40             LOG.warn("Result is NULL");
41             return OLMRenderingResult.failed("Operation Failed");
42         }
43
44         LOG.debug("Result: {}", result.getResult());
45         if (ResponseCodes.SUCCESS_RESULT.equals(result.getResult().getResult())) {
46             LOG.info("OLM power setup finished successfully");
47             return OLMRenderingResult.ok();
48         } else {
49             LOG.warn("OLM power setup not successfully finished");
50             return OLMRenderingResult.failed("Operation Failed");
51         }
52     }
53
54 }