Merge "BUG-2343 Report sideloaded models for nc correctly"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 12 Mar 2015 11:58:32 +0000 (11:58 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Mar 2015 11:58:33 +0000 (11:58 +0000)
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMRpcImplementationAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingRpcImplementationAdapter.java
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 d76d4f9bba23ffaeba3d088eeda0b80c98561bf6..c4a99efdbe1822542f43644a012a6ff8a9c0be83 100644 (file)
@@ -50,8 +50,8 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
     public <T extends RpcService> BindingDOMRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec, final Class<T> type ,final T delegate) {
         this.codec = codec;
         this.delegate = delegate;
-        this.invoker = RpcServiceInvoker.from(type);
-        this.module = BindingReflections.getQNameModule(type);
+        invoker = RpcServiceInvoker.from(type);
+        module = BindingReflections.getQNameModule(type);
     }
 
     public QNameModule getQNameModule() {
@@ -61,7 +61,7 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
     @Override
     public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
         final SchemaPath schemaPath = rpc.getType();
-        final DataObject bindingInput = deserilialize(rpc.getType(),input);
+        final DataObject bindingInput = input != null ? deserilialize(rpc.getType(),input) : null;
         final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath,bindingInput);
         return transformResult(schemaPath,bindingResult);
     }
index 9f0de746e63f6fdfe2af1587430ab5d50dce99fb..25a6ebde9783b916a424cbb1fe0f2fd11633194b 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation;
@@ -33,7 +34,7 @@ public class BindingRpcImplementationAdapter implements DOMRpcImplementation {
     private static final Function<? super Exception, DOMRpcException> EXCEPTION_MAPPER = new Function<Exception, DOMRpcException>() {
 
         @Override
-        public DOMRpcException apply(Exception input) {
+        public DOMRpcException apply(final Exception input) {
             // FIXME: Return correct exception
             return null;
         }
@@ -44,7 +45,7 @@ public class BindingRpcImplementationAdapter implements DOMRpcImplementation {
     private final RpcService delegate;
     private final QNameModule module;
 
-    private Function<RpcResult<?>,DOMRpcResult> lazySerializedMapper = new Function<RpcResult<?>,DOMRpcResult>() {
+    private final Function<RpcResult<?>,DOMRpcResult> lazySerializedMapper = new Function<RpcResult<?>,DOMRpcResult>() {
 
         @Override
         public DOMRpcResult apply(final RpcResult<?> input) {
@@ -52,11 +53,11 @@ public class BindingRpcImplementationAdapter implements DOMRpcImplementation {
         }
     };
 
-    public <T extends RpcService> BindingRpcImplementationAdapter(BindingNormalizedNodeCodecRegistry codec, Class<T> type ,T delegate) {
+    public <T extends RpcService> BindingRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec, final Class<T> type ,final T delegate) {
         this.codec = codec;
         this.delegate = delegate;
-        this.invoker = RpcServiceInvoker.from(type);
-        this.module = BindingReflections.getQNameModule(type);
+        invoker = RpcServiceInvoker.from(type);
+        module = BindingReflections.getQNameModule(type);
     }
 
     public QNameModule getQNameModule() {
@@ -64,29 +65,29 @@ public class BindingRpcImplementationAdapter implements DOMRpcImplementation {
     }
 
     @Override
-    public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(DOMRpcIdentifier rpc, NormalizedNode<?, ?> input) {
-        SchemaPath schemaPath = rpc.getType();
-        DataObject bindingInput = deserilialize(rpc.getType(),input);
-        ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath,bindingInput);
+    public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final DOMRpcIdentifier rpc, @Nullable final NormalizedNode<?, ?> input) {
+        final SchemaPath schemaPath = rpc.getType();
+        final DataObject bindingInput = input != null ? deserilialize(rpc.getType(),input) : null;
+        final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
         return transformResult(schemaPath,bindingResult);
     }
 
-    private DataObject deserilialize(SchemaPath rpcPath, NormalizedNode<?, ?> input) {
+    private DataObject deserilialize(final SchemaPath rpcPath, final NormalizedNode<?, ?> input) {
         if(input instanceof LazySerializedContainerNode) {
             return ((LazySerializedContainerNode) input).bindingData();
         }
-        SchemaPath inputSchemaPath = rpcPath.createChild(QName.create(module,"input"));
+        final SchemaPath inputSchemaPath = rpcPath.createChild(QName.create(module,"input"));
         return codec.fromNormalizedNodeRpcData(inputSchemaPath, (ContainerNode) input);
     }
 
 
-    private ListenableFuture<RpcResult<?>> invoke(SchemaPath schemaPath, DataObject input) {
+    private ListenableFuture<RpcResult<?>> invoke(final SchemaPath schemaPath, final DataObject input) {
         return JdkFutureAdapters.listenInPoolThread(invoker.invokeRpc(delegate, schemaPath.getLastComponent(), input));
     }
 
-    private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(SchemaPath schemaPath,
-            ListenableFuture<RpcResult<?>> bindingResult) {
-        ListenableFuture<DOMRpcResult> transformed = Futures.transform(bindingResult, lazySerializedMapper);
+    private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(final SchemaPath schemaPath,
+            final ListenableFuture<RpcResult<?>> bindingResult) {
+        final ListenableFuture<DOMRpcResult> transformed = Futures.transform(bindingResult, lazySerializedMapper);
         return Futures.makeChecked(transformed, EXCEPTION_MAPPER);
     }
 
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));