SH-Renderer API code to handle OTN Step 1
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / OtnDeviceRenderingTask.java
1 /*
2  * Copyright © 2020 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
9 package org.opendaylight.transportpce.renderer.provisiondevice.tasks;
10
11 import java.util.concurrent.Callable;
12 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
13 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRenderingResult;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathInput;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutput;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class OtnDeviceRenderingTask implements Callable<OtnDeviceRenderingResult> {
20     private static final Logger LOG = LoggerFactory.getLogger(OtnDeviceRenderingTask.class);
21
22     private final OtnDeviceRendererService otnDeviceRenderer;
23     private final OtnServicePathInput otnServicePathInput;
24
25     public OtnDeviceRenderingTask(OtnDeviceRendererService otnDeviceRendererService,
26         OtnServicePathInput otnServicePathInput) {
27         this.otnDeviceRenderer = otnDeviceRendererService;
28         this.otnServicePathInput = otnServicePathInput;
29
30     }
31
32     @Override
33     public OtnDeviceRenderingResult call() throws Exception {
34         OtnServicePathOutput output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput);
35         if (Boolean.TRUE.equals(output.isSuccess())) {
36             LOG.info("Device rendering finished successfully.");
37             return OtnDeviceRenderingResult.ok(output.getNodeInterface());
38
39         } else { //false or null case
40             LOG.warn("Device rendering not successfully finished.");
41             return OtnDeviceRenderingResult.failed("Operation Failed");
42         }
43     }
44
45 }