Upgrade to Service Path 1.7
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / DeviceRenderingTask.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.List;
11 import java.util.concurrent.Callable;
12 import org.opendaylight.transportpce.renderer.ServicePathInputData;
13 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
14 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRenderingResult;
15 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutput;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.olm.renderer.input.Nodes;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class DeviceRenderingTask implements Callable<DeviceRenderingResult> {
22
23     private static final Logger LOG = LoggerFactory.getLogger(DeviceRenderingTask.class);
24
25     private final DeviceRendererService deviceRenderer;
26     private final ServicePathInputData servicePathInputData;
27     private final ServicePathDirection direction;
28
29     public DeviceRenderingTask(DeviceRendererService deviceRenderer, ServicePathInputData servicePathInputData,
30             ServicePathDirection direction) {
31         this.deviceRenderer = deviceRenderer;
32         this.servicePathInputData = servicePathInputData;
33         this.direction = direction;
34     }
35
36     @Override
37     public DeviceRenderingResult call() throws Exception {
38         ServicePathOutput output = this.deviceRenderer.setupServicePath(this.servicePathInputData.getServicePathInput(),
39                 this.direction);
40         if (! output.isSuccess()) {
41             LOG.warn("Device rendering not successfully finished.");
42             return DeviceRenderingResult.failed("Operation Failed");
43         }
44         List<Nodes> olmList = this.servicePathInputData.getNodeLists().getOlmList();
45         LOG.info("Device rendering finished successfully.");
46         return DeviceRenderingResult.ok(olmList, output.getNodeInterface());
47     }
48
49 }