2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.persist.impl.osgi;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
13 import org.opendaylight.controller.netconf.persist.impl.NoOpStorageAdapter;
14 import org.opendaylight.controller.netconf.persist.impl.PersisterImpl;
15 import org.opendaylight.controller.config.stat.ConfigProvider;
16 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
17 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.TLSConfiguration;
18 import org.osgi.framework.BundleActivator;
19 import org.osgi.framework.BundleContext;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import javax.management.MBeanServer;
24 import java.lang.management.ManagementFactory;
25 import java.net.InetSocketAddress;
27 public class ConfigPersisterActivator implements BundleActivator {
29 private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterActivator.class);
31 private final static MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
33 private ConfigPersisterNotificationHandler configPersisterNotificationHandler;
35 private Thread initializationThread;
38 public void start(BundleContext context) throws Exception {
39 logger.debug("ConfigPersister activator started");
41 ConfigProvider configProvider = new ConfigProvider.ConfigProviderImpl(context);
42 Optional<PersisterImpl> maybePersister = PersisterImpl.createFromProperties(configProvider);
43 if (maybePersister.isPresent() == false) {
44 throw new IllegalStateException("No persister is defined in " + PersisterImpl.STORAGE_ADAPTER_CLASS_PROP
45 + " property. For noop persister use " + NoOpStorageAdapter.class.getCanonicalName()
46 + " . Persister is not operational");
49 Optional<TLSConfiguration> maybeTLSConfiguration = NetconfConfigUtil.extractTLSConfiguration(configProvider);
50 Optional<InetSocketAddress> maybeTCPAddress = NetconfConfigUtil.extractTCPNetconfAddress(configProvider);
52 InetSocketAddress address;
53 if (maybeTLSConfiguration.isPresent()) {
54 throw new UnsupportedOperationException("TLS is currently not supported for persister");
55 } else if (maybeTCPAddress.isPresent()) {
56 address = maybeTCPAddress.get();
58 throw new IllegalStateException("Netconf is not configured, persister is not operational");
61 PersisterImpl persister = maybePersister.get();
62 configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address,
64 Runnable initializationRunnable = new Runnable() {
68 configPersisterNotificationHandler.init();
69 } catch (InterruptedException e) {
70 logger.info("Interrupted while waiting for netconf connection");
74 initializationThread = new Thread(initializationRunnable, "ConfigPersister-registrator");
75 initializationThread.start();
79 public void stop(BundleContext context) throws Exception {
80 initializationThread.interrupt();
81 configPersisterNotificationHandler.close();