Tighten RPC dispatch 69/107069/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Jul 2023 22:09:58 +0000 (00:09 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Jul 2023 22:31:59 +0000 (00:31 +0200)
We have simple RPC dispatch, make sure we tighten the contracts to
conver exactly the RPCs we support.

Change-Id: I26b684f2d363f1a0b72982a43d5cdb4d80bc2f10
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-common-models/src/main/yang/sal-remote.yang
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java

index 994e070035c6ad4fde709c79ebb8535016bd3927..ba9cf37422cfeb9a620adb3ac087d175b1d6608f 100644 (file)
@@ -19,16 +19,13 @@ module sal-remote {
            http://www.eclipse.org/legal/epl-v10.html";
 
     revision "2014-01-14" {
-        description
-            "Initial revision";
+        description "Initial revision";
     }
 
-
-     typedef q-name {
-       type string;
-       reference
-         "http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#QName";
-     }
+    typedef q-name {
+        type string;
+        reference "http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#QName";
+    }
 
     rpc create-data-change-event-subscription {
         input {
@@ -36,13 +33,13 @@ module sal-remote {
                 type instance-identifier;
                 description "Subtree path. ";
             }
-         }
-         output {
+        }
+        output {
             leaf stream-name {
                 type string;
                 description "Notification stream name.";
             }
-         }
+        }
     }
 
     notification data-changed-notification {
@@ -88,10 +85,9 @@ module sal-remote {
 
     rpc begin-transaction {
         output {
-            anyxml data-modification-transaction{
+            anyxml data-modification-transaction {
                 description "DataModificationTransaction xml";
             }
         }
     }
-
-}
\ No newline at end of file
+}
index 778a94f98d8352468ab08c58121ba43ad17308f6..aabe066b9d9b32bb0f84cdb02603e69ef8378e4e 100644 (file)
@@ -106,6 +106,7 @@ final class CreateStreamUtil {
      *     }
      *     </pre>
      */
+    // FIXME: this really should be a normal RPC implementation
     static DOMRpcResult createDataChangeNotifiStream(final NormalizedNodePayload payload,
             final EffectiveModelContext refSchemaCtx) {
         // parsing out of container with settings and path
index d77f1fd6e1e47a62ca1bf7f325fd9a20fd3b3484..0914ce97e7d89f1f70321ebc539a971acd950b35 100644 (file)
@@ -34,12 +34,11 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
 import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106.SubscribeDeviceNotificationInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106.SubscribeDeviceNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscription;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -58,10 +57,6 @@ import org.slf4j.LoggerFactory;
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfInvokeOperationsServiceImpl.class);
 
-    // FIXME: at some point we do not want to have this here, as this is only used for dispatch
-    private static final QNameModule SAL_REMOTE_NAMESPACE = CreateDataChangeEventSubscriptionInput.QNAME.getModule();
-    private static final QNameModule DEVICE_NOTIFICATION_NAMESPACE = SubscribeDeviceNotificationInput.QNAME.getModule();
-
     private final DOMRpcService rpcService;
     private final DOMMountPointService mountPointService;
     private final SubscribeToStreamUtil streamUtils;
@@ -85,18 +80,9 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
 
         final ListenableFuture<? extends DOMRpcResult> future;
         if (mountPoint == null) {
-            // FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS,
-            //        except ... we check 'identifier' for .contains() instead of exact RPC name!
-            if (SAL_REMOTE_NAMESPACE.equals(rpcName.getModule())) {
-                if (identifier.contains("create-data-change-event-subscription")) {
-                    future = Futures.immediateFuture(
-                        CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContext));
-                } else {
-                    future = Futures.immediateFailedFuture(new RestconfDocumentedException("Unsupported operation",
-                        ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED));
-                }
-            } else if (DEVICE_NOTIFICATION_NAMESPACE.equals(rpcName.getModule())) {
-                // FIXME: this should be a match on RPC QName
+            if (CreateDataChangeEventSubscription.QNAME.equals(rpcName)) {
+                future = Futures.immediateFuture(CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContext));
+            } else if (SubscribeDeviceNotification.QNAME.equals(rpcName)) {
                 final String baseUrl = streamUtils.prepareUriByStreamName(uriInfo, "").toString();
                 future = Futures.immediateFuture(CreateStreamUtil.createDeviceNotificationListener(baseUrl, payload,
                     streamUtils, mountPointService));