Split out OperationInvocation
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / DOMRpcRouter.java
index a0d1f1418d7ed74496c5de247cd1dafbd834462c..14bd9cf14183d6840d4e26cf8375f07ccd0f9fd6 100644 (file)
@@ -31,7 +31,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -71,8 +70,6 @@ import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
@@ -550,87 +547,4 @@ public final class DOMRpcRouter extends AbstractRegistration
             };
         }
     }
-
-    static final class OperationInvocation {
-        private static final Logger LOG = LoggerFactory.getLogger(OperationInvocation.class);
-
-        static ListenableFuture<? extends DOMActionResult> invoke(final DOMActionRoutingTableEntry entry,
-                final Absolute type, final DOMDataTreeIdentifier path, final ContainerNode input) {
-            List<DOMActionImplementation> impls = entry.getImplementations(path);
-            if (impls == null) {
-                impls = entry.getImplementations(
-                    new DOMDataTreeIdentifier(path.getDatastoreType(), YangInstanceIdentifier.of()));
-                if (impls == null) {
-                    return Futures.immediateFailedFuture(new DOMActionNotAvailableException(
-                        "No implementation of Action %s available for %s", type, path));
-                }
-            }
-
-            return impls.get(0).invokeAction(type, path, input);
-        }
-
-        static ListenableFuture<? extends DOMRpcResult> invoke(final AbstractDOMRpcRoutingTableEntry entry,
-                final ContainerNode input) {
-            if (entry instanceof UnknownDOMRpcRoutingTableEntry) {
-                return Futures.immediateFailedFuture(
-                    new DOMRpcImplementationNotAvailableException("%s is not resolved to an RPC", entry.getType()));
-            } else if (entry instanceof RoutedDOMRpcRoutingTableEntry routed) {
-                return invokeRoutedRpc(routed, input);
-            } else if (entry instanceof GlobalDOMRpcRoutingTableEntry global) {
-                return invokeGlobalRpc(global, input);
-            }
-
-            return Futures.immediateFailedFuture(
-                new DOMRpcImplementationNotAvailableException("Unsupported RPC entry."));
-        }
-
-        private static ListenableFuture<? extends DOMRpcResult> invokeRoutedRpc(
-                final RoutedDOMRpcRoutingTableEntry entry, final ContainerNode input) {
-            final Optional<NormalizedNode> maybeKey = NormalizedNodes.findNode(input,
-                entry.getRpcId().getContextReference());
-
-            // Routing key is present, attempt to deliver as a routed RPC
-            if (maybeKey.isPresent()) {
-                final NormalizedNode key = maybeKey.orElseThrow();
-                final Object value = key.body();
-                if (value instanceof YangInstanceIdentifier iid) {
-                    // Find a DOMRpcImplementation for a specific iid
-                    final List<DOMRpcImplementation> specificImpls = entry.getImplementations(iid);
-                    if (specificImpls != null) {
-                        return specificImpls.get(0)
-                            .invokeRpc(DOMRpcIdentifier.create(entry.getType(), iid), input);
-                    }
-
-                    LOG.debug("No implementation for context {} found will now look for wildcard id", iid);
-
-                    // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
-                    // implementation this way
-                    final List<DOMRpcImplementation> mayBeRemoteImpls =
-                        entry.getImplementations(YangInstanceIdentifier.of());
-
-                    if (mayBeRemoteImpls != null) {
-                        return mayBeRemoteImpls.get(0)
-                            .invokeRpc(DOMRpcIdentifier.create(entry.getType(), iid), input);
-                    }
-
-                } else {
-                    LOG.warn("Ignoring wrong context value {}", value);
-                }
-            }
-
-            final List<DOMRpcImplementation> impls = entry.getImplementations(null);
-            if (impls != null) {
-                return impls.get(0).invokeRpc(entry.getRpcId(), input);
-            }
-
-            return Futures.immediateFailedFuture(
-                new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available",
-                    entry.getType()));
-        }
-
-        private static ListenableFuture<? extends DOMRpcResult> invokeGlobalRpc(
-                final GlobalDOMRpcRoutingTableEntry entry, final ContainerNode input) {
-            return entry.getImplementations(YangInstanceIdentifier.of()).get(0).invokeRpc(entry.getRpcId(), input);
-        }
-    }
 }