Merge "Prevent ssh hang during shutdown"
authorJakub Morvay <jakub.morvay@gmail.com>
Mon, 7 Jan 2019 12:07:32 +0000 (12:07 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 7 Jan 2019 12:07:32 +0000 (12:07 +0000)
netconf/mdsal-netconf-ssh/pom.xml
netconf/mdsal-netconf-ssh/src/main/resources/org/opendaylight/blueprint/netconf-ssh.xml
netconf/netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/NetconfNorthboundSshServer.java

index ff13ec2eaf7035203163105ca648ba262050aaf0..2e9a06a44ba1db0b738236cd12b75bac78a066cf 100644 (file)
       <groupId>${project.groupId}</groupId>
       <artifactId>netconf-ssh</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.aries.blueprint</groupId>
+      <artifactId>org.apache.aries.blueprint.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <build>
index 9d5d3ed409ec50d0f4c71ab44a006c97065692ce..1b1278edf6e9afab207b474ad16b93147b783423 100755 (executable)
 
     <reference id="netconfServerDispatcher" interface="org.opendaylight.netconf.api.NetconfServerDispatcher"/>
     <reference id="globalWorkerGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-worker-group"/>
-    <reference id="executor" interface="io.netty.util.concurrent.EventExecutor" odl:type="global-event-executor"/>
     <reference id="authProvider" interface="org.opendaylight.netconf.auth.AuthProvider" odl:type="netconf-auth-provider"/>
 
+    <reference id="executor" interface="io.netty.util.concurrent.EventExecutor" odl:type="global-event-executor">
+        <reference-listener ref="netconfMdsalServer" unbind-method="unbind"/>
+    </reference>
+
     <!--    NETCONF server for MD-SAL (listening by default on port 2830)-->
 
     <cm:property-placeholder persistent-id="org.opendaylight.netconf.ssh" update-strategy="none">
index f478029323821c1f6e1f8193a8ddb6def06ac456..fa5337c6c85c95b8d4f092924a9791d5d88e3e2f 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.netconf.auth.AuthProvider;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
+import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -87,4 +88,18 @@ public class NetconfNorthboundSshServer {
             localServer.cancel(true);
         }
     }
+
+    /*
+     * Called when the underlying reference to EventExecutor is about to be removed from the container allowing
+     * us to close the ssh server while it still exists.
+     */
+    public void unbind(final ServiceReference<?> reference) {
+        LOG.debug("EventExecutor is being removed, closing netconf ssh server. {}", reference);
+
+        try {
+            close();
+        } catch (final IOException e) {
+            LOG.error("Closing of ssh server failed while unbinding reference listener.", e);
+        }
+    }
 }