Renderer and OLM update
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / OlmPowerSetupRollbackTask.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.Future;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.OlmService;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerSetupInput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownInputBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownOutput;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class OlmPowerSetupRollbackTask extends RollbackTask {
21
22     private static final Logger LOG = LoggerFactory.getLogger(OlmPowerSetupRollbackTask.class);
23     private static final String FAILED = "Failed";
24     private final boolean isRollbackNecessary;
25     private final OlmService olmService;
26     private final ServicePowerSetupInput powerSetupInput;
27
28     public OlmPowerSetupRollbackTask(String id, boolean isRollbackNecessary, OlmService olmService,
29             ServicePowerSetupInput powerSetupInput) {
30         super(id);
31         this.isRollbackNecessary = isRollbackNecessary;
32         this.olmService = olmService;
33         this.powerSetupInput = powerSetupInput;
34     }
35
36     @Override
37     public boolean isRollbackNecessary() {
38         return isRollbackNecessary;
39     }
40
41     @Override
42     public Void call() throws Exception {
43         ServicePowerTurndownInput powerTurndownInput = new ServicePowerTurndownInputBuilder()
44                 .setNodes(this.powerSetupInput.getNodes())
45                 .setServiceName(this.powerSetupInput.getServiceName())
46                 .setWaveNumber(this.powerSetupInput.getWaveNumber())
47                 .build();
48
49         Future<RpcResult<ServicePowerTurndownOutput>> powerTurndownResultFuture =
50                 this.olmService.servicePowerTurndown(powerTurndownInput);
51         RpcResult<ServicePowerTurndownOutput> powerTurndownResult = powerTurndownResultFuture.get();
52         if (FAILED.equals(powerTurndownResult.getResult().getResult())) {
53             LOG.warn("Olmp power setup rollback for {} was not successful!", this.getId());
54         } else {
55             LOG.info("Olm power setup rollback for {} was successful.");
56         }
57         return null;
58     }
59 }