Move otn link update from renderer to SH
[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.ArrayList;
12 import java.util.concurrent.Callable;
13 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
14 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRenderingResult;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathOutput;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class OtnDeviceRenderingTask implements Callable<OtnDeviceRenderingResult> {
21     private static final Logger LOG = LoggerFactory.getLogger(OtnDeviceRenderingTask.class);
22
23     private final OtnDeviceRendererService otnDeviceRenderer;
24     private final OtnServicePathInput otnServicePathInput;
25
26     public OtnDeviceRenderingTask(OtnDeviceRendererService otnDeviceRendererService,
27             OtnServicePathInput otnServicePathInput) {
28         this.otnDeviceRenderer = otnDeviceRendererService;
29         this.otnServicePathInput = otnServicePathInput;
30     }
31
32     @Override
33     public OtnDeviceRenderingResult call() throws Exception {
34         OtnServicePathOutput output;
35         switch (this.otnServicePathInput.getOperation()) {
36             case Create:
37                 output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput);
38                 if (!output.getSuccess()) {
39                     LOG.error("Device rendering setup otn service path failed.");
40                     return OtnDeviceRenderingResult.failed("Operation Failed");
41                 }
42                 LOG.info("Device rendering setup otn service path finished successfully.");
43                 return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()),
44                     new ArrayList<>(output.nonnullLinkTp()));
45             case Delete:
46                 output = this.otnDeviceRenderer.deleteOtnServicePath(this.otnServicePathInput);
47                 if (!output.getSuccess()) {
48                     LOG.error("Device rendering delete otn service path failed.");
49                     return OtnDeviceRenderingResult.failed("Operation Failed");
50                 }
51                 LOG.info("Device rendering delete otn service path finished successfully.");
52                 return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()),
53                     new ArrayList<>(output.nonnullLinkTp()));
54             default:
55                 return OtnDeviceRenderingResult.failed("Device rendering failed - unknwon operation");
56         }
57     }
58 }