Merge "BUG-2314 Allow rpcs with no input in netconf connector"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 12 Mar 2015 11:57:36 +0000 (11:57 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Mar 2015 11:57:37 +0000 (11:57 +0000)
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/api/MessageTransformer.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceRpc.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java
opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceTest.java
opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java

index 6f81ce06cd62687c2bd2b216279e0e2e54b55a21..dc27cd6572c9dcaa8504c0c3b321db9092dd9474 100644 (file)
@@ -9,13 +9,14 @@ package org.opendaylight.controller.sal.connect.api;
 
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 public interface MessageTransformer<M> {
 
     ContainerNode toNotification(M message);
 
-    M toRpcRequest(SchemaPath rpc, ContainerNode node);
+    M toRpcRequest(SchemaPath rpc, NormalizedNode<?, ?> node);
 
     DOMRpcResult toRpcResult(M message, SchemaPath rpc);
 
index 108b33ad14f9bf39807f7bd435678df622817c93..178b0502edbb9678a21adca7738679e7ff355f32 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.sal.connect.netconf.sal;
 
 import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
@@ -28,7 +27,6 @@ import org.opendaylight.controller.sal.connect.api.MessageTransformer;
 import org.opendaylight.controller.sal.connect.api.RemoteDeviceCommunicator;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -61,9 +59,7 @@ public final class NetconfDeviceRpc implements DOMRpcService {
     @Nonnull
     @Override
     public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final SchemaPath type, @Nullable final NormalizedNode<?, ?> input) {
-        Preconditions.checkArgument(input instanceof ContainerNode, "Epc payload has to be a %s, was %s", ContainerNode.class, input);
-
-        final NetconfMessage message = transformer.toRpcRequest(type, (ContainerNode) input);
+        final NetconfMessage message = transformer.toRpcRequest(type, input);
         final ListenableFuture<RpcResult<NetconfMessage>> delegateFutureWithPureResult = listener.sendRequest(message, type.getLastComponent());
 
         final ListenableFuture<DOMRpcResult> transformed = Futures.transform(delegateFutureWithPureResult, new Function<RpcResult<NetconfMessage>, DOMRpcResult>() {
index 9e32dd0663a079fc2bde071a5287bf12369a2d4e..e768b5eb5b62ba66d81c3e0c731ee2364577c145 100644 (file)
@@ -152,7 +152,7 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
     }
 
     @Override
-    public NetconfMessage toRpcRequest(SchemaPath rpc, final ContainerNode payload) {
+    public NetconfMessage toRpcRequest(SchemaPath rpc, final NormalizedNode<?, ?> payload) {
         // In case no input for rpc is defined, we can simply construct the payload here
         final QName rpcQName = rpc.getLastComponent();
         Map<QName, RpcDefinition> currentMappedRpcs = mappedRpcs;
@@ -172,6 +172,10 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
             return new NetconfMessage(document);
         }
 
+        Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpcQName);
+        Preconditions.checkArgument(payload instanceof ContainerNode,
+                "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpcQName, payload);
+
         // Set the path to the input of rpc for the node stream writer
         rpc = rpc.createChild(QName.cachedReference(QName.create(rpcQName, "input")));
         final DOMResult result = prepareDomResultForRpcRequest(rpcQName);
@@ -179,7 +183,7 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         try {
             // If the schema context for netconf device does not contain model for base netconf operations, use default pre build context with just the base model
             // This way operations like lock/unlock are supported even if the source for base model was not provided
-            writeNormalizedRpc(payload, result, rpc, needToUseBaseCtx ? BASE_NETCONF_CTX : schemaContext);
+            writeNormalizedRpc(((ContainerNode) payload), result, rpc, needToUseBaseCtx ? BASE_NETCONF_CTX : schemaContext);
         } catch (final XMLStreamException | IOException | IllegalStateException e) {
             throw new IllegalStateException("Unable to serialize " + rpc, e);
         }
index 61bd73a0a8e576963ce4b2ac1a80fd5840c42639..c7f1c6ad70bf7c2f9df4dff3721d3da9506cd1ae 100644 (file)
@@ -50,6 +50,7 @@ import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransf
 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -278,7 +279,7 @@ public class NetconfDeviceTest {
 
     public MessageTransformer<NetconfMessage> getMessageTransformer() throws Exception {
         final MessageTransformer<NetconfMessage> messageTransformer = mockClass(MessageTransformer.class);
-        doReturn(notification).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(ContainerNode.class));
+        doReturn(notification).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(NormalizedNode.class));
         doReturn(rpcResultC).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(SchemaPath.class));
         doReturn(compositeNode).when(messageTransformer).toNotification(any(NetconfMessage.class));
         return messageTransformer;
index 643c67af287862b92619d295be11ac2f8b8baa0b..669479d3d582809470739803dd7d14859402abf9 100644 (file)
@@ -107,8 +107,7 @@ public class NetconfMessageTransformerTest {
 
     @Test
     public void testDiscardChangesRequest() throws Exception {
-        final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME),
-                NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT);
+        final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME), null);
         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<discard"));
     }
 
@@ -125,7 +124,6 @@ public class NetconfMessageTransformerTest {
                 "</rpc>");
     }
 
-
     @Test
     public void tesGetSchemaResponse() throws Exception {
         final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true));