Refactor Prov DB handling
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / DRRouteCLI.java
index 867d116..187364f 100644 (file)
@@ -23,6 +23,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import static java.lang.System.exit;\r
+\r
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
 import java.io.File;\r
@@ -51,6 +53,7 @@ import org.apache.http.util.EntityUtils;
 import org.json.JSONArray;\r
 import org.json.JSONObject;\r
 import org.json.JSONTokener;\r
+import org.onap.dmaap.datarouter.provisioning.ProvRunner;\r
 \r
 /**\r
  * This class provides a Command Line Interface for the routing tables in the DR Release 2.0 DB.\r
@@ -96,9 +99,9 @@ public class DRRouteCLI {
         }\r
     }\r
 \r
-    public static final String ENV_VAR = "PROVSRVR";\r
-    public static final String PROMPT = "dr-route> ";\r
-    public static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";\r
+    private static final String ENV_VAR = "PROVSRVR";\r
+    private static final String PROMPT = "dr-route> ";\r
+    private static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";\r
     private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
 \r
     private final String server;\r
@@ -113,12 +116,20 @@ public class DRRouteCLI {
      */\r
     public DRRouteCLI(String server) throws Exception {\r
         this.server = server;\r
-        this.width = 120;\r
         this.httpclient = new DefaultHttpClient();\r
 \r
-        Properties prop = (new DB()).getProperties();\r
-        String truststoreFile = prop.getProperty("org.onap.dmaap.datarouter.provserver.truststore.path");\r
-        String truststorePw = prop.getProperty("org.onap.dmaap.datarouter.provserver.truststore.password");\r
+        Properties provProperties = ProvRunner.getProvProperties();\r
+        try {\r
+            AafPropsUtils.init(new File(provProperties.getProperty(\r
+                "org.onap.dmaap.datarouter.provserver.aafprops.path",\r
+                "/opt/app/osaaf/local/org.onap.dmaap-dr.props")));\r
+        } catch (IOException e) {\r
+            intlogger.error("NODE0314 Failed to load AAF props. Exiting", e);\r
+            exit(1);\r
+        }\r
+\r
+        String truststoreFile = AafPropsUtils.getInstance().getTruststorePathProperty();\r
+        String truststorePw = AafPropsUtils.getInstance().getTruststorePassProperty();\r
 \r
         KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());\r
         if (truststoreFile == null || truststoreFile.equals("")) {\r
@@ -139,8 +150,8 @@ public class DRRouteCLI {
             } finally {\r
                 try {\r
                     instream.close();\r
-                } catch (Exception ignore) {\r
-                    intlogger.error("Ignore error closing input stream: " + ignore.getMessage(), ignore);\r
+                } catch (Exception e) {\r
+                    intlogger.error("Ignore error closing input stream: " + e.getMessage(), e);\r
                 }\r
             }\r
         }\r
@@ -178,7 +189,7 @@ public class DRRouteCLI {
      * @param args The command line arguments.\r
      * @return true if the command was valid and succeeded\r
      */\r
-    public boolean runCommand(String[] args) {\r
+    boolean runCommand(String[] args) {\r
         String cmd = args[0].trim().toLowerCase();\r
         if (cmd.equals("add")) {\r
             if (args.length > 2) {\r
@@ -471,12 +482,12 @@ public class DRRouteCLI {
         return rv;\r
     }\r
 \r
-    private void printErrorText(HttpEntity entity) throws IllegalStateException, IOException {\r
+    private void printErrorText(HttpEntity entity) throws IOException {\r
         // Look for and print only the part of the output between <pre>...</pre>\r
         InputStream is = entity.getContent();\r
         StringBuilder sb = new StringBuilder();\r
         byte[] bite = new byte[512];\r
-        int num = 0;\r
+        int num;\r
         while ((num = is.read(bite)) > 0) {\r
             sb.append(new String(bite, 0, num));\r
         }\r