Prevent ssh hang during shutdown 70/79270/1
authorTomas Cere <tomas.cere@pantheon.tech>
Mon, 7 Jan 2019 10:21:09 +0000 (11:21 +0100)
committerTomas Cere <tomas.cere@pantheon.tech>
Mon, 7 Jan 2019 12:09:25 +0000 (12:09 +0000)
Add a reference listener for netty executor service provided by blueprint
so we can close ssh servers while the bundle still exists. This prevents
the hang seen during shutdown since the executor was being shutdown before
the mdsal-netconf-ssh.

JIRA: NETCONF-577
Change-Id: I062c9e8afb349817435ea0b1dde796a54ebb22d2
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
(cherry picked from commit e7f9ea2cd02cc8ffb743cff4d07ba7068d1e7c73)

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 2b93375ed2e72e86795427fce04e505edeb0172c..caf7f12bf6797129db5a0efb813c323632a32007 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);
+        }
+    }
 }