Renderer and OLM update
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / tasks / DeviceRenderingTask.java
diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/tasks/DeviceRenderingTask.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/provisiondevice/tasks/DeviceRenderingTask.java
new file mode 100644 (file)
index 0000000..abe7818
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2017 AT&T and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.transportpce.renderer.provisiondevice.tasks;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import org.opendaylight.transportpce.renderer.ServicePathInputData;
+import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
+import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRenderingResult;
+import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.renderer.rev170228.ServicePathOutput;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DeviceRenderingTask implements Callable<DeviceRenderingResult> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DeviceRenderingTask.class);
+
+    private final DeviceRendererService deviceRenderer;
+    private final ServicePathInputData servicePathInputData;
+    private final ServicePathDirection direction;
+
+    public DeviceRenderingTask(DeviceRendererService deviceRenderer, ServicePathInputData servicePathInputData,
+            ServicePathDirection direction) {
+        this.deviceRenderer = deviceRenderer;
+        this.servicePathInputData = servicePathInputData;
+        this.direction = direction;
+    }
+
+    @Override
+    public DeviceRenderingResult call() throws Exception {
+        ServicePathOutput output = this.deviceRenderer.setupServicePath(this.servicePathInputData.getServicePathInput(),
+                this.direction);
+        if (! output.isSuccess()) {
+            LOG.warn("Device rendering not successfully finished.");
+            return DeviceRenderingResult.failed("Operation Failed");
+        }
+        List<Nodes> olmList = this.servicePathInputData.getNodeLists().getOlmList();
+        LOG.info("Device rendering finished successfully.");
+        return DeviceRenderingResult.ok(olmList, output.getNodeInterface());
+    }
+
+}