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.netconf.util.osgi.NetconfConfigUtil;
16 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.TLSConfiguration;
17 import org.osgi.framework.BundleActivator;
18 import org.osgi.framework.BundleContext;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import javax.management.MBeanServer;
23 import java.lang.management.ManagementFactory;
24 import java.net.InetSocketAddress;
26 public class ConfigPersisterActivator implements BundleActivator {
28 private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterActivator.class);
30 private final static MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
32 private ConfigPersisterNotificationHandler configPersisterNotificationHandler;
34 private Thread initializationThread;
37 public void start(BundleContext context) throws Exception {
38 logger.debug("ConfigPersister activator started");
40 Optional<PersisterImpl> maybePersister = PersisterImpl.createFromProperties(context);
41 if (maybePersister.isPresent() == false) {
42 throw new IllegalStateException("No persister is defined in " + PersisterImpl.STORAGE_ADAPTER_CLASS_PROP
43 + " property. For noop persister use " + NoOpStorageAdapter.class.getCanonicalName()
44 + " . Persister is not operational");
47 Optional<TLSConfiguration> maybeTLSConfiguration = NetconfConfigUtil.extractTLSConfiguration(context);
48 Optional<InetSocketAddress> maybeTCPAddress = NetconfConfigUtil.extractTCPNetconfAddress(context);
50 InetSocketAddress address;
51 if (maybeTLSConfiguration.isPresent()) {
52 throw new UnsupportedOperationException("TLS is currently not supported for persister");
53 } else if (maybeTCPAddress.isPresent()) {
54 address = maybeTCPAddress.get();
56 throw new IllegalStateException("Netconf is not configured, persister is not operational");
59 PersisterImpl persister = maybePersister.get();
60 configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address,
62 Runnable initializationRunnable = new Runnable() {
66 configPersisterNotificationHandler.init();
67 } catch (InterruptedException e) {
68 logger.info("Interrupted while waiting for netconf connection");
72 initializationThread = new Thread(initializationRunnable, "ConfigPersister-registrator");
73 initializationThread.start();
77 public void stop(BundleContext context) throws Exception {
78 initializationThread.interrupt();
79 configPersisterNotificationHandler.close();