Merge "ROADM To ROADM Path Calculation"
[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 java.util.concurrent.Callable;
11 import java.util.concurrent.Future;
12 import org.opendaylight.transportpce.renderer.provisiondevice.OLMRenderingResult;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutput;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class OlmPowerSetupTask implements Callable<OLMRenderingResult> {
21
22     private static final Logger LOG = LoggerFactory.getLogger(OlmPowerSetupTask.class);
23
24     private final TransportpceOlmService olmService;
25     private final ServicePowerSetupInput input;
26
27     public OlmPowerSetupTask(TransportpceOlmService olmService, ServicePowerSetupInput input) {
28         this.olmService = olmService;
29         this.input = input;
30     }
31
32     @Override
33     public OLMRenderingResult call() throws Exception {
34         Future<RpcResult<ServicePowerSetupOutput>> fr = this.olmService.servicePowerSetup(this.input);
35         RpcResult<ServicePowerSetupOutput> result = fr.get();
36         if (result == null) {
37             LOG.warn("Result is NULL");
38             return OLMRenderingResult.failed("Operation Failed");
39         }
40
41         LOG.debug("Result: {}", result.getResult());
42         if (result.isSuccessful()) {
43             LOG.info("OLM power setup finished successfully");
44             return OLMRenderingResult.ok();
45         } else {
46             LOG.warn("OLM power setup not successfully finished");
47             return OLMRenderingResult.failed("Operation Failed");
48         }
49     }
50
51 }