Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteActionImplementation.java
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteActionImplementation.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteActionImplementation.java
new file mode 100644 (file)
index 0000000..c3eeeed
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2019 Nordix Foundation.  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.controller.remote.rpc;
+
+import akka.actor.ActorRef;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.remote.rpc.messages.ExecuteAction;
+import org.opendaylight.mdsal.dom.api.DOMActionImplementation;
+import org.opendaylight.mdsal.dom.api.DOMActionResult;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link DOMActionImplementation} which routes invocation requests to a remote invoker actor.
+ */
+final class RemoteActionImplementation extends AbstractRemoteImplementation<ExecuteAction>
+        implements DOMActionImplementation {
+    private static final Logger LOG = LoggerFactory.getLogger(RemoteActionImplementation.class);
+
+    RemoteActionImplementation(final ActorRef remoteInvoker, final RemoteOpsProviderConfig config) {
+        super(remoteInvoker, config);
+    }
+
+    /**
+     * Routes action request to a remote invoker, which will execute the action and return with result.
+     */
+    @Override
+    public ListenableFuture<DOMActionResult> invokeAction(final SchemaPath type, final DOMDataTreeIdentifier path,
+                                                          final ContainerNode input) {
+        LOG.debug("invoking action {} with path {}", type, path);
+        return new RemoteDOMActionFuture(type, ask(ExecuteAction.from(type, path, input)));
+    }
+
+    @Override
+    public long invocationCost() {
+        return COST;
+    }
+}