Update AAF loading procedure
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / SynchronizerTask.java
index 8c5a49a..2a907fb 100644 (file)
@@ -77,6 +77,7 @@ import org.onap.dmaap.datarouter.provisioning.beans.NetworkRoute;
 import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
 import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
 import org.onap.dmaap.datarouter.provisioning.beans.Syncable;
+import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils;
 import org.onap.dmaap.datarouter.provisioning.utils.DB;
 import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
 import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet;
@@ -99,6 +100,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
  * @author Robert Eby
  * @version $Id: SynchronizerTask.java,v 1.10 2014/03/21 13:50:10 eby Exp $
  */
+
 public class SynchronizerTask extends TimerTask {
 
     /**
@@ -143,20 +145,21 @@ public class SynchronizerTask extends TimerTask {
 
         logger.info("PROV5000: Sync task starting, server podState is UNKNOWN_POD");
         try {
-            Properties props = (new DB()).getProperties();
-            String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
-            String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
-            String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
+            // Set up keystore
+            String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY;
+            String store = Main.aafPropsUtils.getKeystorePathProperty();
+            String pass = Main.aafPropsUtils.getKeystorePassProperty();
             KeyStore keyStore = KeyStore.getInstance(type);
             try (FileInputStream instream = new FileInputStream(new File(store))) {
                 keyStore.load(instream, pass.toCharArray());
 
             }
-            store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
-            pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
+            // Set up truststore
+            store = Main.aafPropsUtils.getTruststorePathProperty();
+            pass = Main.aafPropsUtils.getTruststorePassProperty();
             KeyStore trustStore = null;
             if (store != null && store.length() > 0) {
-                trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+                trustStore = KeyStore.getInstance(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY);
                 try (FileInputStream instream = new FileInputStream(new File(store))) {
                     trustStore.load(instream, pass.toCharArray());
 
@@ -165,7 +168,7 @@ public class SynchronizerTask extends TimerTask {
 
             // We are connecting with the node name, but the certificate will have the CNAME
             // So we need to accept a non-matching certificate name
-            String keystorepass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
+            String keystorepass = Main.aafPropsUtils.getKeystorePassProperty();
             try (AbstractHttpClient hc = new DefaultHttpClient()) {
                 SSLSocketFactory socketFactory =
                         (trustStore == null)
@@ -176,18 +179,18 @@ public class SynchronizerTask extends TimerTask {
                 hc.getConnectionManager().getSchemeRegistry().register(sch);
                 httpclient = hc;
             }
-            setSynchTimer(props);
+            setSynchTimer(new DB().getProperties().getProperty(
+                "org.onap.dmaap.datarouter.provserver.sync_interval", "5000"));
         } catch (Exception e) {
             logger.warn("PROV5005: Problem starting the synchronizer: " + e);
         }
     }
 
-    private void setSynchTimer(Properties props) {
+    private void setSynchTimer(String strInterval) {
         // Run once every 5 seconds to check DNS, etc.
         long interval;
         try {
-            String s = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000");
-            interval = Long.parseLong(s);
+            interval = Long.parseLong(strInterval);
         } catch (NumberFormatException e) {
             interval = 5000L;
         }
@@ -342,8 +345,8 @@ public class SynchronizerTask extends TimerTask {
         Collection<Syncable> coll = new ArrayList<>();
         for (int n = 0; n < ja.length(); n++) {
             try {
-                Feed f = new Feed(ja.getJSONObject(n));
-                coll.add(f);
+                Feed feed = new Feed(ja.getJSONObject(n));
+                coll.add(feed);
             } catch (Exception e) {
                 logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n), e);
             }
@@ -361,10 +364,10 @@ public class SynchronizerTask extends TimerTask {
         for (int n = 0; n < ja.length(); n++) {
             try {
                 //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
-                JSONObject j = ja.getJSONObject(n);
-                j.put("sync", "true");
-                Subscription s = new Subscription(j);
-                coll.add(s);
+                JSONObject jsonObject = ja.getJSONObject(n);
+                jsonObject.put("sync", "true");
+                Subscription sub = new Subscription(jsonObject);
+                coll.add(sub);
             } catch (Exception e) {
                 logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n), e);
             }
@@ -381,8 +384,8 @@ public class SynchronizerTask extends TimerTask {
         Collection<Syncable> coll = new ArrayList<>();
         for (int n = 0; n < ja.length(); n++) {
             try {
-                Group g = new Group(ja.getJSONObject(n));
-                coll.add(g);
+                Group group = new Group(ja.getJSONObject(n));
+                coll.add(group);
             } catch (Exception e) {
                 logger.warn("PROV5004: Invalid object in group: " + ja.optJSONObject(n), e);
             }
@@ -399,25 +402,25 @@ public class SynchronizerTask extends TimerTask {
     private void syncParams(JSONObject jo) {
         Collection<Syncable> coll = new ArrayList<>();
         for (String k : jo.keySet()) {
-            String v = "";
+            String val = "";
             try {
-                v = jo.getString(k);
+                val = jo.getString(k);
             } catch (JSONException e) {
                 logger.warn("PROV5004: Invalid object in parameters: " + jo.optJSONObject(k), e);
                 try {
-                    v = "" + jo.getInt(k);
+                    val = "" + jo.getInt(k);
                 } catch (JSONException e1) {
                     logger.warn("PROV5004: Invalid object in parameters: " + jo.optInt(k), e1);
                     JSONArray ja = jo.getJSONArray(k);
                     for (int i = 0; i < ja.length(); i++) {
                         if (i > 0) {
-                            v += "|";
+                            val += "|";
                         }
-                        v += ja.getString(i);
+                        val += ja.getString(i);
                     }
                 }
             }
-            coll.add(new Parameters(k, v));
+            coll.add(new Parameters(k, val));
         }
         if (sync(coll, Parameters.getParameterCollection())) {
             BaseServlet.provisioningDataChanged();
@@ -526,9 +529,9 @@ public class SynchronizerTask extends TimerTask {
         return newobj.doInsert(conn);
     }
 
-    private Map<String, Syncable> getMap(Collection<? extends Syncable> c) {
+    private Map<String, Syncable> getMap(Collection<? extends Syncable> coll) {
         Map<String, Syncable> map = new HashMap<>();
-        for (Syncable v : c) {
+        for (Syncable v : coll) {
             map.put(v.getKey(), v);
         }
         return map;
@@ -650,11 +653,11 @@ public class SynchronizerTask extends TimerTask {
         String url = URLUtilities.generatePeerLogsURL();
         HttpPost post = new HttpPost(url);
         try {
-            String t = bs.toString();
-            HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create(TEXT_CT));
+            String str = bs.toString();
+            HttpEntity body = new ByteArrayEntity(str.getBytes(), ContentType.create(TEXT_CT));
             post.setEntity(body);
             if (logger.isDebugEnabled()) {
-                logger.debug("Requesting records: " + t);
+                logger.debug("Requesting records: " + str);
             }
 
             HttpResponse response = httpclient.execute(post);