Move otn link update from renderer to SH
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / OtnDeviceRenderingTask.java
index 2721f99a8c3a5f09f592a56f6609e6efadc98908..34365fb7b13c8f49e5330800244b1b259065dd65 100644 (file)
@@ -12,8 +12,8 @@ import java.util.ArrayList;
 import java.util.concurrent.Callable;
 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRenderingResult;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.OtnServicePathInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev200128.OtnServicePathOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathOutput;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,24 +24,35 @@ public class OtnDeviceRenderingTask implements Callable<OtnDeviceRenderingResult
     private final OtnServicePathInput otnServicePathInput;
 
     public OtnDeviceRenderingTask(OtnDeviceRendererService otnDeviceRendererService,
-        OtnServicePathInput otnServicePathInput) {
+            OtnServicePathInput otnServicePathInput) {
         this.otnDeviceRenderer = otnDeviceRendererService;
         this.otnServicePathInput = otnServicePathInput;
-
     }
 
     @Override
     public OtnDeviceRenderingResult call() throws Exception {
-        OtnServicePathOutput output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput);
-        if (Boolean.TRUE.equals(output.getSuccess())) {
-            LOG.info("Device rendering finished successfully.");
-            return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()));
-
-        } else {
-            //false or null case
-            LOG.warn("Device rendering not successfully finished.");
-            return OtnDeviceRenderingResult.failed("Operation Failed");
+        OtnServicePathOutput output;
+        switch (this.otnServicePathInput.getOperation()) {
+            case Create:
+                output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput);
+                if (!output.getSuccess()) {
+                    LOG.error("Device rendering setup otn service path failed.");
+                    return OtnDeviceRenderingResult.failed("Operation Failed");
+                }
+                LOG.info("Device rendering setup otn service path finished successfully.");
+                return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()),
+                    new ArrayList<>(output.nonnullLinkTp()));
+            case Delete:
+                output = this.otnDeviceRenderer.deleteOtnServicePath(this.otnServicePathInput);
+                if (!output.getSuccess()) {
+                    LOG.error("Device rendering delete otn service path failed.");
+                    return OtnDeviceRenderingResult.failed("Operation Failed");
+                }
+                LOG.info("Device rendering delete otn service path finished successfully.");
+                return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()),
+                    new ArrayList<>(output.nonnullLinkTp()));
+            default:
+                return OtnDeviceRenderingResult.failed("Device rendering failed - unknwon operation");
         }
     }
-
 }