Merge "BUG-732 Fix sal-netconf-connector unable to download schemas"
authorTony Tkacik <ttkacik@cisco.com>
Mon, 28 Apr 2014 12:01:53 +0000 (12:01 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 28 Apr 2014 12:01:53 +0000 (12:01 +0000)
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfMapping.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfRemoteSchemaSourceProvider.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractNetconfSession.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlNetconfConstants.java

index 8d52950a2954539da471fcbe1f164b01f4eeb1c1..aa5c6f40a9a4f827c88aa97d9a72551d6e8fd94f 100644 (file)
@@ -289,7 +289,7 @@ public class NetconfDevice implements Provider, //
 
     @Override
     public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
-        return listener.sendRequest(toRpcMessage(rpc, input, getSchemaContext()));
+        return listener.sendRequest(toRpcMessage(rpc, input, getSchemaContext()), rpc);
     }
 
     @Override
index 94f5e166a115e216cf839e52a044bc870c34c661..1dfc3b44d3191bf00427d9e5908ff0f68f7517e0 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.netconf.client.NetconfClientSession;
 import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -45,10 +46,12 @@ class NetconfDeviceListener implements NetconfClientSessionListener {
     private static final class Request {
         final UncancellableFuture<RpcResult<CompositeNode>> future;
         final NetconfMessage request;
+        final QName rpc;
 
-        private Request(UncancellableFuture<RpcResult<CompositeNode>> future, NetconfMessage request) {
+        private Request(UncancellableFuture<RpcResult<CompositeNode>> future, NetconfMessage request, final QName rpc) {
             this.future = future;
             this.request = request;
+            this.rpc = rpc;
         }
     }
 
@@ -163,14 +166,13 @@ class NetconfDeviceListener implements NetconfClientSessionListener {
                 return;
             }
 
-            r.future.set(Rpcs.getRpcResult(true, NetconfMapping.toNotificationNode(message, device.getSchemaContext()),
-                    Collections.<RpcError>emptyList()));
+            r.future.set(NetconfMapping.toRpcResult(message, r.rpc, device.getSchemaContext()));
         } else {
             LOG.warn("Ignoring unsolicited message", message);
         }
     }
 
-    synchronized ListenableFuture<RpcResult<CompositeNode>> sendRequest(final NetconfMessage message) {
+    synchronized ListenableFuture<RpcResult<CompositeNode>> sendRequest(final NetconfMessage message, final QName rpc) {
         if (session == null) {
             LOG.debug("Session to {} is disconnected, failing RPC request {}", device.getName(), message);
             return Futures.<RpcResult<CompositeNode>>immediateFuture(new RpcResult<CompositeNode>() {
@@ -192,7 +194,7 @@ class NetconfDeviceListener implements NetconfClientSessionListener {
             });
         }
 
-        final Request req = new Request(new UncancellableFuture<RpcResult<CompositeNode>>(true), message);
+        final Request req = new Request(new UncancellableFuture<RpcResult<CompositeNode>>(true), message, rpc);
         requests.add(req);
 
         session.sendMessage(req.request).addListener(new FutureListener<Void>() {
@@ -200,7 +202,7 @@ class NetconfDeviceListener implements NetconfClientSessionListener {
             public void operationComplete(final Future<Void> future) throws Exception {
                 if (!future.isSuccess()) {
                     // We expect that a session down will occur at this point
-                    LOG.debug("Failed to send request {}", req.request, future.cause());
+                    LOG.debug("Failed to send request {}", XmlUtil.toString(req.request.getDocument()), future.cause());
                     req.future.setException(future.cause());
                 } else {
                     LOG.trace("Finished sending request {}", req.request);
index a6e6b3dfdf456d92711da924522d22de0aeea788..f0b711d368595dede27c14030b4d0d4ef64112a6 100644 (file)
@@ -192,12 +192,6 @@ public class NetconfMapping {
                 rawRpc = it.toInstance();
                 // sys(xmlData)
             } else {
-                RpcDefinition rpcSchema = Iterables.find(context.get().getOperations(), new Predicate<RpcDefinition>() {
-                    @Override
-                    public boolean apply(final RpcDefinition input) {
-                        return rpc == input.getQName();
-                    }
-                });
                 rawRpc = (CompositeNode) toCompositeNode(message.getDocument());
             }
         else {
index c734e80d9aa06f76d3c4a96c277b8c71a7a48d74..abd935dd63e177ddfe23b1de713891351080c3ab 100644 (file)
@@ -20,6 +20,8 @@ import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String> {
 
@@ -30,8 +32,11 @@ class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String>
 
     private final NetconfDevice device;
 
+    private final Logger logger;
+
     public NetconfRemoteSchemaSourceProvider(NetconfDevice device) {
         this.device = Preconditions.checkNotNull(device);
+        logger = LoggerFactory.getLogger(NetconfDevice.class + "#" + device.getName());
     }
 
     @Override
@@ -44,7 +49,7 @@ class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String>
             request.addLeaf("version", revision.get());
         }
 
-        device.logger.trace("Loading YANG schema source for {}:{}", moduleName, revision);
+        logger.trace("Loading YANG schema source for {}:{}", moduleName, revision);
         try {
             RpcResult<CompositeNode> schemaReply = device.invokeRpc(GET_SCHEMA_QNAME, request.toInstance()).get();
             if (schemaReply.isSuccessful()) {
@@ -54,9 +59,9 @@ class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String>
                     return Optional.of(schemaBody);
                 }
             }
-            device.logger.warn("YANG shcema was not successfully retrieved.");
+            logger.warn("YANG shcema was not successfully retrieved.");
         } catch (InterruptedException | ExecutionException e) {
-            device.logger.warn("YANG shcema was not successfully retrieved.", e);
+            logger.warn("YANG shcema was not successfully retrieved.", e);
         }
         return Optional.absent();
     }
index 9e15b49a843c677cdc12ae6bee2a927a2f891df7..7af1f01a08ea89c0712b1fb69e80f550832b97cf 100644 (file)
@@ -33,8 +33,8 @@ import org.slf4j.LoggerFactory;
 public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfMessage, NetconfClientSession, NetconfClientSessionListener> {
 
     public static final java.util.Set<String> CLIENT_CAPABILITIES = Sets.newHashSet(
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_1,
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1,
             XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0);
 
     private static final String START_EXI_MESSAGE_ID = "default-start-exi";
index 9d958660615c27c27e86fee68e669f7e17c6a1b1..c5f8e99f2271baaa84b9a4c58657a69f50c92369 100644 (file)
@@ -8,10 +8,11 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.collect.Sets;
-import io.netty.channel.Channel;
-import io.netty.util.Timer;
-import io.netty.util.concurrent.Promise;
+import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
@@ -23,18 +24,24 @@ import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.opendaylight.protocol.framework.SessionNegotiator;
 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-import java.util.Set;
+import com.google.common.collect.Sets;
 
-import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting;
+import io.netty.channel.Channel;
+import io.netty.util.Timer;
+import io.netty.util.concurrent.Promise;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfHelloMessage, NetconfServerSession, NetconfServerSessionListener> {
 
-    private static final Set<String> DEFAULT_CAPABILITIES = Sets.newHashSet(
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0);
+    private static final Set<String> DEFAULT_BASE_CAPABILITIES = ImmutableSet.of(
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0
+            // FIXME, Chunk framing causes ConcurrentClientsTest to fail, investigate
+//            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1,
+            // FIXME, EXI causing issues with sal-netconf-connector, investigate
+//            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0
+    );
 
     private final Timer timer;
 
@@ -45,9 +52,11 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     private final SessionMonitoringService monitoringService;
     private static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionNegotiatorFactory.class);
 
+    // TODO too many params, refactor
     public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider,
                                                  SessionIdProvider idProvider, long connectionTimeoutMillis,
-                                                 DefaultCommitNotificationProducer commitNot, SessionMonitoringService monitoringService) {
+                                                 DefaultCommitNotificationProducer commitNot,
+                                                 SessionMonitoringService monitoringService) {
         this.timer = timer;
         this.netconfOperationProvider = netconfOperationProvider;
         this.idProvider = idProvider;
@@ -91,7 +100,7 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     }
 
     private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) throws NetconfDocumentedException {
-        return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_CAPABILITIES), sessionId);
+        return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_BASE_CAPABILITIES), sessionId);
     }
 
 }
index db5a359d7a16c72784911a447b2756de36356b42..02889b62a5bf71fe6cdb1161c7ac3fdaa0c00eaf 100644 (file)
@@ -8,20 +8,31 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.HashedWheelTimer;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+
+import java.io.DataOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.commons.io.IOUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.client.test.TestingNetconfClient;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.controller.netconf.client.test.TestingNetconfClient;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
 import org.opendaylight.controller.netconf.mapping.api.Capability;
@@ -31,28 +42,20 @@ import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedEx
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
+import org.opendaylight.controller.netconf.util.messages.NetconfStartExiMessage;
 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
-import java.io.DataOutputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.util.HashedWheelTimer;
 
 public class ConcurrentClientsTest {
 
@@ -90,13 +93,12 @@ public class ConcurrentClientsTest {
 
         SessionIdProvider idProvider = new SessionIdProvider();
         hashedWheelTimer = new HashedWheelTimer();
+
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
                 hashedWheelTimer, factoriesListener, idProvider, 5000, commitNot, createMockedMonitoringService());
 
         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
 
-
-
         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory);
         dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup);
 
@@ -125,7 +127,9 @@ public class ConcurrentClientsTest {
                         return Sets.<NetconfOperation> newHashSet(new NetconfOperation() {
                             @Override
                             public HandlingPriority canHandle(Document message) {
-                                return HandlingPriority.getHandlingPriority(Integer.MAX_VALUE);
+                                return XmlUtil.toString(message).contains(NetconfStartExiMessage.START_EXI) ?
+                                        HandlingPriority.CANNOT_HANDLE :
+                                        HandlingPriority.HANDLE_WITH_MAX_PRIORITY;
                             }
 
                             @Override
@@ -152,7 +156,7 @@ public class ConcurrentClientsTest {
         commitNot.close();
     }
 
-    @Test
+    @Test(timeout = 30 * 1000)
     public void multipleClients() throws Exception {
         List<TestingThread> threads = new ArrayList<>();
 
@@ -173,12 +177,12 @@ public class ConcurrentClientsTest {
         }
     }
 
-    @Test
+    @Test(timeout = 30 * 1000)
     public void synchronizationTest() throws Exception {
         new BlockingThread("foo").run2();
     }
 
-    @Test
+    @Test(timeout = 30 * 1000)
     public void multipleBlockingClients() throws Exception {
         List<BlockingThread> threads = new ArrayList<>();
         for (int i = 0; i < CONCURRENCY; i++) {
index 270af3505f63a7589ab0957c1177badb72b6ab1d..aa1afc025d736f154822e88dee11c89766d9bd63 100644 (file)
@@ -61,7 +61,7 @@ public abstract class AbstractNetconfSession<S extends NetconfSession, L extends
     @Override
     public ChannelFuture sendMessage(final NetconfMessage netconfMessage) {
         final ChannelFuture future = channel.writeAndFlush(netconfMessage);
-        if (delayedEncoder !=null) {
+        if (delayedEncoder != null) {
                 replaceMessageEncoder(delayedEncoder);
                 delayedEncoder = null;
         }
index 39a49544a576abe3bd65403c864aa1b4572fc898..708f17cadbc2a16dd639b53b386dd84e212d3d54 100644 (file)
@@ -46,7 +46,9 @@ public final class XmlNetconfConstants {
     // TODO duplicate
     public static final String RFC4741_TARGET_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0";
     public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 = "urn:ietf:params:xml:ns:netconf:base:1.0";
-    public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_1 = "urn:ietf:params:xml:ns:netconf:base:1.1";
+//    public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_1 = "urn:ietf:params:xml:ns:netconf:base:1.1";
+    public static final String URN_IETF_PARAMS_NETCONF_BASE_1_0 = "urn:ietf:params:netconf:base:1.0";
+    public static final String URN_IETF_PARAMS_NETCONF_BASE_1_1 = "urn:ietf:params:netconf:base:1.1";
     public static final String URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0 = "urn:ietf:params:xml:ns:netconf:exi:1.0";
 
     public static final String URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0 = "urn:ietf:params:netconf:capability:exi:1.0";