Merge "Refactor persister to handle multiple storage engines. Allow persister to...
[controller.git] / opendaylight / netconf / config-persister-impl / src / main / java / org / opendaylight / controller / netconf / persist / impl / osgi / ConfigPersisterActivator.java
index 241830ddc33ebb74a4d95168887f48c225d77bc8..5fa0b49d7b954434e88220f5378ccc89d0f51f8d 100644 (file)
@@ -8,9 +8,8 @@
 
 package org.opendaylight.controller.netconf.persist.impl.osgi;
 
-import org.opendaylight.controller.config.persist.api.storage.StorageAdapter.PropertiesProvider;
 import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
-import org.opendaylight.controller.netconf.persist.impl.PersisterImpl;
+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;
@@ -20,42 +19,43 @@ 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;
 
     private Thread initializationThread;
 
-    private static final String NETCONF_CONFIG_PERSISTER_PREFIX = "netconf.config.persister.";
+    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";
 
     @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);
 
-        PersisterImpl persister = PersisterImpl.createFromProperties(propertiesProvider);
+        String regexProperty = propertiesProvider.getProperty(IGNORED_MISSING_CAPABILITY_REGEX_SUFFIX);
+        String regex;
+        if (regexProperty != null) {
+            regex = regexProperty;
+        } else {
+            regex = DEFAULT_IGNORED_REGEX;
+        }
+        Pattern ignoredMissingCapabilityRegex = Pattern.compile(regex);
+        PersisterAggregator persister = PersisterAggregator.createFromProperties(propertiesProvider);
 
         InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context,
                 "Netconf is not configured, persister is not operational");
         configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address,
-                platformMBeanServer);
+                platformMBeanServer, ignoredMissingCapabilityRegex);
 
         // offload initialization to another thread in order to stop blocking activator
         Runnable initializationRunnable = new Runnable() {