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=1157ddbd83a814be6d7ea4091ea116bf8398255d;hp=036cb757ae9b0d20e88b22f696e64afc7284731f;hb=c5b0b028392646507133df0af5efcee547763b6d;hpb=7746d7c42b1e91e62fd00550973f39e10929e221 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 036cb757ae..1157ddbd83 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,9 +8,11 @@ package org.opendaylight.controller.netconf.persist.impl.osgi; -import org.opendaylight.controller.config.persist.api.storage.StorageAdapter.PropertiesProvider; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler; -import org.opendaylight.controller.netconf.persist.impl.PersisterImpl; +import org.opendaylight.controller.netconf.persist.impl.ConfigPusher; +import org.opendaylight.controller.netconf.persist.impl.PersisterAggregator; import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -29,29 +31,25 @@ 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; + private static final String MAX_WAIT_FOR_CAPABILITIES_MILLIS = "maxWaitForCapabilitiesMillis"; - private Thread initializationThread; + public static final String NETCONF_CONFIG_PERSISTER = "netconf.config.persister"; + + public static final String STORAGE_ADAPTER_CLASS_PROP_SUFFIX = "storageAdapterClass"; - private static final String NETCONF_CONFIG_PERSISTER_PREFIX = "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 Thread initializationThread; + private EventLoopGroup nettyThreadGroup; + private PersisterAggregator persisterAggregator; + @Override public void start(final BundleContext context) throws Exception { logger.debug("ConfigPersister starting"); - PropertiesProvider propertiesProvider = new PropertiesProvider() { - @Override - public String getProperty(String key) { - return context.getProperty(getFullKeyForReporting(key)); - } - - @Override - public String getFullKeyForReporting(String key) { - return NETCONF_CONFIG_PERSISTER_PREFIX + key; - } - }; + PropertiesProviderBaseImpl propertiesProvider = new PropertiesProviderBaseImpl(context); String regexProperty = propertiesProvider.getProperty(IGNORED_MISSING_CAPABILITY_REGEX_SUFFIX); String regex; @@ -60,23 +58,40 @@ public class ConfigPersisterActivator implements BundleActivator { } else { regex = DEFAULT_IGNORED_REGEX; } - Pattern ignoredMissingCapabilityRegex = Pattern.compile(regex); - PersisterImpl persister = PersisterImpl.createFromProperties(propertiesProvider); - InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context, - "Netconf is not configured, persister is not operational"); - configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address, - platformMBeanServer, ignoredMissingCapabilityRegex); + String timeoutProperty = propertiesProvider.getProperty(MAX_WAIT_FOR_CAPABILITIES_MILLIS); + long maxWaitForCapabilitiesMillis; + if (timeoutProperty == null) { + maxWaitForCapabilitiesMillis = ConfigPusher.DEFAULT_MAX_WAIT_FOR_CAPABILITIES_MILLIS; + } else { + maxWaitForCapabilitiesMillis = Integer.valueOf(timeoutProperty); + } + + 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, maxWaitForCapabilitiesMillis, + ConfigPusher.DEFAULT_CONNECTION_TIMEOUT_MILLIS); + // offload initialization to another thread in order to stop blocking activator Runnable initializationRunnable = new Runnable() { @Override public void run() { try { - configPersisterNotificationHandler.init(); + configPusher.pushConfigs(persisterAggregator.loadLastConfigs()); + jmxNotificationHandler = new ConfigPersisterNotificationHandler(platformMBeanServer, persisterAggregator, + ignoredMissingCapabilityRegex); } 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); } + logger.info("Configuration Persister initialization completed."); } }; initializationThread = new Thread(initializationRunnable, "ConfigPersister-registrator"); @@ -86,6 +101,10 @@ public class ConfigPersisterActivator implements BundleActivator { @Override public void stop(BundleContext context) throws Exception { initializationThread.interrupt(); - configPersisterNotificationHandler.close(); + if (jmxNotificationHandler != null) { + jmxNotificationHandler.close(); + } + nettyThreadGroup.shutdownGracefully(); + persisterAggregator.close(); } }