X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2Fosgi%2FConfigPersisterActivator.java;h=656091115c8907aa5de61394e1a6a6f9da516317;hb=03abf047ba966c53f4901d36ae5198156d66dc05;hp=ae6c95312c9143d29f384571ffe9182b227aa862;hpb=350dbdeb0a3d942ba532ada1d1931baf591bec5b;p=controller.git 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 ae6c95312c..656091115c 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,12 +8,14 @@ package org.opendaylight.controller.netconf.persist.impl.osgi; -import com.google.common.base.Optional; +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.NoOpStorageAdapter; -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.persist.impl.Util; import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; -import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.TLSConfiguration; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.slf4j.Logger; @@ -22,48 +24,59 @@ import org.slf4j.LoggerFactory; import javax.management.MBeanServer; import java.lang.management.ManagementFactory; import java.net.InetSocketAddress; +import java.util.regex.Pattern; public class ConfigPersisterActivator implements BundleActivator { private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterActivator.class); 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"; + 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(BundleContext context) throws Exception { - logger.debug("ConfigPersister activator started"); - - Optional maybePersister = PersisterImpl.createFromProperties(context); - if (maybePersister.isPresent() == false) { - throw new IllegalStateException("No persister is defined in " + PersisterImpl.STORAGE_ADAPTER_CLASS_PROP - + " property. For noop persister use " + NoOpStorageAdapter.class.getCanonicalName() - + " . Persister is not operational"); - } + public void start(final BundleContext context) throws Exception { + logger.debug("ConfigPersister starting"); - Optional maybeTLSConfiguration = NetconfConfigUtil.extractTLSConfiguration(context); - Optional maybeTCPAddress = NetconfConfigUtil.extractTCPNetconfAddress(context); + PropertiesProviderBaseImpl propertiesProvider = new PropertiesProviderBaseImpl(context); - InetSocketAddress address; - if (maybeTLSConfiguration.isPresent()) { - throw new UnsupportedOperationException("TLS is currently not supported for persister"); - } else if (maybeTCPAddress.isPresent()) { - address = maybeTCPAddress.get(); + String regexProperty = propertiesProvider.getProperty(IGNORED_MISSING_CAPABILITY_REGEX_SUFFIX); + String regex; + if (regexProperty != null) { + regex = regexProperty; } else { - throw new IllegalStateException("Netconf is not configured, persister is not operational"); + regex = DEFAULT_IGNORED_REGEX; } + 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); - PersisterImpl persister = maybePersister.get(); - configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address, - platformMBeanServer); + + // 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"); } @@ -76,6 +89,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(); } }