Adapt renderer to manage 100GE service on Switch
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / OtnDeviceRenderingTask.java
index 22396244de91a5937c3ca1a38da26bf9d4bbaf24..59296db118e5bbc4168991f5352bce0f5c05270d 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.renderer.device.rev200128.OtnServicePathInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.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;
 
@@ -22,26 +22,37 @@ public class OtnDeviceRenderingTask implements Callable<OtnDeviceRenderingResult
 
     private final OtnDeviceRendererService otnDeviceRenderer;
     private final OtnServicePathInput otnServicePathInput;
+    private final String serviceType;
 
     public OtnDeviceRenderingTask(OtnDeviceRendererService otnDeviceRendererService,
-        OtnServicePathInput otnServicePathInput) {
+            OtnServicePathInput otnServicePathInput, String serviceType) {
         this.otnDeviceRenderer = otnDeviceRendererService;
         this.otnServicePathInput = otnServicePathInput;
-
+        this.serviceType = serviceType;
     }
 
     @Override
     public OtnDeviceRenderingResult call() throws Exception {
-        OtnServicePathOutput output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput);
-        if (Boolean.TRUE.equals(output.isSuccess())) {
-            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.");
+        OtnServicePathOutput output;
+        String operation;
+        switch (this.otnServicePathInput.getOperation()) {
+            case Create:
+                operation = "setup";
+                output = this.otnDeviceRenderer.setupOtnServicePath(this.otnServicePathInput, this.serviceType);
+                break;
+            case Delete:
+                operation = "delete";
+                output = this.otnDeviceRenderer.deleteOtnServicePath(this.otnServicePathInput, this.serviceType);
+                break;
+            default:
+                return OtnDeviceRenderingResult.failed("Device rendering failed - unknown operation");
+        }
+        if (!output.getSuccess()) {
+            LOG.error("Device rendering {} otn service path failed.", operation);
             return OtnDeviceRenderingResult.failed("Operation Failed");
         }
+        LOG.info("Device rendering {} otn service path finished successfully.", operation);
+        return OtnDeviceRenderingResult.ok(new ArrayList<>(output.nonnullNodeInterface().values()),
+            new ArrayList<>(output.nonnullLinkTp()));
     }
-
 }