Move otn link update from renderer to SH
[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.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.Callable;
13 import org.opendaylight.transportpce.renderer.ServicePathInputData;
14 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
15 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRenderingResult;
16 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutput;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class DeviceRenderingTask implements Callable<DeviceRenderingResult> {
23
24     private static final Logger LOG = LoggerFactory.getLogger(DeviceRenderingTask.class);
25
26     private final DeviceRendererService deviceRenderer;
27     private final ServicePathInputData servicePathInputData;
28     private final ServicePathDirection direction;
29
30     public DeviceRenderingTask(DeviceRendererService deviceRenderer, ServicePathInputData servicePathInputData,
31             ServicePathDirection direction) {
32         this.deviceRenderer = deviceRenderer;
33         this.servicePathInputData = servicePathInputData;
34         this.direction = direction;
35     }
36
37     @Override
38     public DeviceRenderingResult call() throws Exception {
39         ServicePathOutput output;
40         switch (this.servicePathInputData.getServicePathInput().getOperation()) {
41             case Create:
42                 output = this.deviceRenderer.setupServicePath(this.servicePathInputData.getServicePathInput(),
43                     this.direction);
44                 if (!output.getSuccess()) {
45                     LOG.error("Device rendering setup service path failed.");
46                     return DeviceRenderingResult.failed("Operation Failed");
47                 }
48                 List<Nodes> olmList = this.servicePathInputData.getNodeLists().getOlmNodeList();
49                 LOG.info("Device rendering setup service path finished successfully.");
50                 return DeviceRenderingResult.ok(olmList, new ArrayList<>(output.nonnullNodeInterface().values()),
51                     new ArrayList<>(output.nonnullLinkTp()));
52             case Delete:
53                 output = this.deviceRenderer.deleteServicePath(this.servicePathInputData.getServicePathInput());
54                 if (!output.getSuccess()) {
55                     LOG.error("Device rendering delete service path failed.");
56                     return DeviceRenderingResult.failed("Operation Failed");
57                 }
58                 LOG.info("Device rendering delete service path finished successfully.");
59                 return DeviceRenderingResult.ok(null, new ArrayList<>(output.nonnullNodeInterface().values()),
60                     new ArrayList<>(output.nonnullLinkTp()));
61             default:
62                 return DeviceRenderingResult.failed("Device rendering failed - unknwon operation");
63         }
64     }
65
66 }