Bump upstream dependencies to Ca
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / rpcs / ServicePathImpl.java
diff --git a/renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/ServicePathImpl.java b/renderer/src/main/java/org/opendaylight/transportpce/renderer/rpcs/ServicePathImpl.java
new file mode 100644 (file)
index 0000000..52da3b5
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2024 Orange, Inc. 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.rpcs;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePath;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class is the implementation of the 'service-path' RESTCONF service,
+ * which is one of the external APIs into the renderer application. The
+ * service provides two functions:
+ *
+ * <p>
+ * 1. Create This operation results in provisioning the device for a given
+ * wavelength and a list of nodes with each node listing its termination
+ * points.
+ *
+ * <p>
+ * 2. Delete This operation results in de-provisioning the device for a
+ * given wavelength and a list of nodes with each node listing its
+ * termination points.
+ *
+ * <p>
+ * The signature for this method was generated by yang tools from the
+ * renderer API model.
+ */
+public class ServicePathImpl implements ServicePath {
+    private static final Logger LOG = LoggerFactory.getLogger(ServicePathImpl.class);
+    private DeviceRendererService deviceRendererService;
+
+    public ServicePathImpl(final DeviceRendererService deviceRendererService) {
+        this.deviceRendererService = requireNonNull(deviceRendererService);
+    }
+
+    @Override
+    public ListenableFuture<RpcResult<ServicePathOutput>> invoke(ServicePathInput input) {
+        if (input.getOperation() != null) {
+            if (input.getOperation().getIntValue() == 1) {
+                LOG.info("Create operation request received");
+                return RpcResultBuilder.success(
+                        this.deviceRendererService.setupServicePath(input, null))
+                        .buildFuture();
+            } else if (input.getOperation().getIntValue() == 2) {
+                LOG.info("Delete operation request received");
+                return RpcResultBuilder
+                        .success(this.deviceRendererService.deleteServicePath(input))
+                        .buildFuture();
+            }
+        }
+        return RpcResultBuilder
+            .success(new ServicePathOutputBuilder().setResult("Invalid operation").build())
+            .buildFuture();
+    }
+
+}