Bug 2058: Fix reading config variables in Karaf 05/11505/2
authorLorand Jakab <lojakab@cisco.com>
Wed, 24 Sep 2014 00:25:45 +0000 (17:25 -0700)
committerLorand Jakab <lojakab@cisco.com>
Wed, 24 Sep 2014 14:57:07 +0000 (07:57 -0700)
Change-Id: I0ab027e0278dd75e588c8aa2d22cef185de2f5fb
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/config/ConfigIni.java

index 181e03e48f16fac3bab7db48f411de98766dfb6d..652284bcbf1b626fd52ba1820867b840d6303528 100644 (file)
@@ -7,35 +7,79 @@
  */
 package org.opendaylight.lispflowmapping.implementation.config;
 
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class ConfigIni {
+    protected static final Logger logger = LoggerFactory.getLogger(ConfigIni.class);
     private boolean mappingOverwrite;
     private boolean smr;
 
+    private static final String LISP_MAPPINGOVERWRITE = "lisp.mappingOverwrite";
+    private static final String LISP_SMR = "lisp.smr";
+
     public ConfigIni() {
-        initMappingOverwrite();
-        initSmr();
+        Bundle b = FrameworkUtil.getBundle(this.getClass());
+        BundleContext context = null;
+        if (b != null) {
+            context = b.getBundleContext();
+        }
+
+        initMappingOverwrite(context);
+        initSmr(context);
     }
 
-    private void initMappingOverwrite() {
-        String str = System.getProperty("lisp.mappingOverwrite");
-        if (str != null) {
-            if (str.trim().equalsIgnoreCase("false")) {
-                this.mappingOverwrite = false;
+    private void initMappingOverwrite(BundleContext context) {
+        // set the default value first
+        this.mappingOverwrite = true;
+
+        String str = null;
+
+        if (context != null)
+            str = context.getProperty(LISP_MAPPINGOVERWRITE);
+
+        if (str == null) {
+            str = System.getProperty(LISP_MAPPINGOVERWRITE);
+            if (str == null) {
+                logger.debug("Configuration variable '{}' is unset. Setting to default value: true", LISP_MAPPINGOVERWRITE);
                 return;
             }
         }
-        this.mappingOverwrite = true;
+
+        if (str.trim().equalsIgnoreCase("false")) {
+            this.mappingOverwrite = false;
+            logger.debug("Setting configuration variable '{}' to false", LISP_MAPPINGOVERWRITE);
+        } else {
+            logger.debug("Setting configuration variable '{}' to true", LISP_MAPPINGOVERWRITE);
+        }
     }
 
-    private void initSmr() {
-        String str = System.getProperty("lisp.smr");
-        if (str != null) {
-            if (str.trim().equalsIgnoreCase("true")) {
-                this.smr = true;
+    private void initSmr(BundleContext context) {
+        // set the default value first
+        this.smr = false;
+
+        String str = null;
+
+        if (context != null)
+            str = context.getProperty(LISP_SMR);
+
+        if (str == null) {
+            str = System.getProperty(LISP_SMR);
+            if (str == null) {
+                logger.debug("Configuration variable '{}' is unset. Setting to default value: false", LISP_SMR);
                 return;
             }
         }
-        this.smr = false;
+
+        if (str.trim().equalsIgnoreCase("true")) {
+            this.smr = true;
+            logger.debug("Setting configuration variable '{}' to true", LISP_SMR);
+        } else {
+            logger.debug("Setting configuration variable '{}' to false", LISP_SMR);
+        }
     }
 
     public boolean mappingOverwriteIsSet() {