X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2Fosgi%2FConfigPersisterActivator.java;h=3c901c3f59e1f45194a5d17cc7979f48932a623b;hp=e7916c2d5f3d041ee315e03335586d533c76206e;hb=526cbb181ae68d4858473a7774a81d7c1414b9e5;hpb=b8e98bb0e826534f0164000ca2453cf23f8b0063 diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java index e7916c2d5f..3c901c3f59 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java @@ -8,8 +8,13 @@ package org.opendaylight.controller.netconf.persist.impl.osgi; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import org.opendaylight.controller.netconf.client.NetconfClient; import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler; +import org.opendaylight.controller.netconf.persist.impl.ConfigPusher; import org.opendaylight.controller.netconf.persist.impl.PersisterAggregator; +import org.opendaylight.controller.netconf.persist.impl.Util; import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -28,14 +33,19 @@ public class ConfigPersisterActivator implements BundleActivator { private final static MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); private static final String IGNORED_MISSING_CAPABILITY_REGEX_SUFFIX = "ignoredMissingCapabilityRegex"; - private ConfigPersisterNotificationHandler configPersisterNotificationHandler; + public static final String NETCONF_CONFIG_PERSISTER = "netconf.config.persister"; - private Thread initializationThread; + public static final String STORAGE_ADAPTER_CLASS_PROP_SUFFIX = "storageAdapterClass"; - public static final String NETCONF_CONFIG_PERSISTER = "netconf.config.persister"; - public static final String STORAGE_ADAPTER_CLASS_PROP_SUFFIX = "storageAdapterClass"; public static final String DEFAULT_IGNORED_REGEX = "^urn:ietf:params:xml:ns:netconf:base:1.0"; + + private volatile ConfigPersisterNotificationHandler jmxNotificationHandler; + private volatile NetconfClient netconfClient; + private Thread initializationThread; + private EventLoopGroup nettyThreadgroup; + private PersisterAggregator persisterAggregator; + @Override public void start(final BundleContext context) throws Exception { logger.debug("ConfigPersister starting"); @@ -49,22 +59,29 @@ public class ConfigPersisterActivator implements BundleActivator { } else { regex = DEFAULT_IGNORED_REGEX; } - Pattern ignoredMissingCapabilityRegex = Pattern.compile(regex); - PersisterAggregator persister = PersisterAggregator.createFromProperties(propertiesProvider); + final Pattern ignoredMissingCapabilityRegex = Pattern.compile(regex); + nettyThreadgroup = new NioEventLoopGroup(); + + persisterAggregator = PersisterAggregator.createFromProperties(propertiesProvider); + final InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context, "Netconf is not configured, persister is not operational", true); + final ConfigPusher configPusher = new ConfigPusher(address, nettyThreadgroup); - InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context, - "Netconf is not configured, persister is not operational",true); - configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address, - platformMBeanServer, ignoredMissingCapabilityRegex); // offload initialization to another thread in order to stop blocking activator Runnable initializationRunnable = new Runnable() { @Override public void run() { try { - configPersisterNotificationHandler.init(); + netconfClient = configPusher.init(persisterAggregator.loadLastConfigs()); + jmxNotificationHandler = new ConfigPersisterNotificationHandler( + platformMBeanServer, netconfClient, persisterAggregator, + ignoredMissingCapabilityRegex); + jmxNotificationHandler.init(); } catch (InterruptedException e) { - logger.info("Interrupted while waiting for netconf connection"); + Thread.currentThread().interrupt(); + logger.error("Interrupted while waiting for netconf connection"); + // uncaught exception handler will deal with this failure + throw new RuntimeException("Interrupted while waiting for netconf connection", e); } } }; @@ -75,6 +92,18 @@ public class ConfigPersisterActivator implements BundleActivator { @Override public void stop(BundleContext context) throws Exception { initializationThread.interrupt(); - configPersisterNotificationHandler.close(); + if (jmxNotificationHandler != null) { + jmxNotificationHandler.close(); + } + if (netconfClient != null) { + netconfClient = jmxNotificationHandler.getNetconfClient(); + try { + Util.closeClientAndDispatcher(netconfClient); + } catch (Exception e) { + logger.warn("Unable to close connection to netconf {}", netconfClient, e); + } + } + nettyThreadgroup.shutdownGracefully(); + persisterAggregator.close(); } }