Merge "Bug 616 - Eliminate the use of xtend in md-sal/topology-lldp-discovery"
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerSessionNegotiatorFactory.java
index 9106b6ad85ef68ec00e4cbb037c82e1b93047b03..c5f8e99f2271baaa84b9a4c58657a69f50c92369 100644 (file)
@@ -10,8 +10,10 @@ package org.opendaylight.controller.netconf.impl;
 
 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;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
@@ -28,12 +30,18 @@ import com.google.common.collect.Sets;
 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;
 
@@ -42,10 +50,13 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     private final long connectionTimeoutMillis;
     private final DefaultCommitNotificationProducer commitNotificationProducer;
     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;
@@ -71,8 +82,14 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
                 getNetconfSessionIdForReporting(sessionId));
         CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot);
 
-        NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(
-                createHelloMessage(sessionId, capabilityProvider), sessionId);
+        NetconfServerSessionPreferences proposal = null;
+        try {
+            proposal = new NetconfServerSessionPreferences(
+                    createHelloMessage(sessionId, capabilityProvider), sessionId);
+        } catch (NetconfDocumentedException e) {
+            logger.error("Unable to create hello mesage for session {} with capability provider {}", sessionId,capabilityProvider);
+            throw new IllegalStateException(e);
+        }
 
         NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory(
                 commitNotificationProducer, monitoringService,
@@ -82,8 +99,8 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
                 sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
     }
 
-    private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) {
-        return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_CAPABILITIES), sessionId);
+    private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) throws NetconfDocumentedException {
+        return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_BASE_CAPABILITIES), sessionId);
     }
 
 }