Manage ODU4 services over multiple OTU4
[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.rev211004.OtnServicePathInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.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     private final String serviceType;
26
27     public OtnDeviceRenderingTask(OtnDeviceRendererService otnDeviceRendererService,
28             OtnServicePathInput otnServicePathInput, String serviceType) {
29         this.otnDeviceRenderer = otnDeviceRendererService;
30         this.otnServicePathInput = otnServicePathInput;
31         this.serviceType = serviceType;
32     }
33
34     @Override
35     public OtnDeviceRenderingResult call() throws Exception {
36         OtnServicePathOutput output;
37         String operation;
38         switch (this.otnServicePathInput.getOperation()) {
39             case Create:
40                 operation = "setup";
41                 output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput, this.serviceType);
42                 break;
43             case Delete:
44                 operation = "delete";
45                 output = this.otnDeviceRenderer.deleteOtnServicePath(this.otnServicePathInput, this.serviceType);
46                 break;
47             default:
48                 return OtnDeviceRenderingResult.failed("Device rendering failed - unknown operation");
49         }
50         if (!output.getSuccess()) {
51             LOG.error("Device rendering {} otn service path failed.", operation);
52             return OtnDeviceRenderingResult.failed("Operation Failed");
53         }
54         LOG.info("Device rendering {} otn service path finished successfully.", operation);
55         return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()),
56             new ArrayList<>(output.nonnullLinkTp()));
57     }
58 }