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