Update the logic for MSB addr retrieving
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / config / MicroServiceConfig.java
index 01a5f2e..212bc66 100644 (file)
@@ -49,6 +49,7 @@ public class MicroServiceConfig {
     public static String getConfigBindingServiceAddrInfo() {\r
         String ret = null;\r
         String queryString = getConsulAddrInfo() + CONFIG_BINDING_SERVICE;\r
+        log.info("Query the CBS address using the URL: " + queryString);\r
         try {\r
             JSONObject addrJson = (JSONObject) JSONArray.fromObject(execQuery(queryString)).get(0);\r
             if (addrJson.has("ServiceAddress") && addrJson.has("ServicePort")) {\r
@@ -57,6 +58,7 @@ public class MicroServiceConfig {
         } catch (Exception e) {\r
             log.warn(e.getMessage(), e);\r
         }\r
+        log.info("The CBS address is " + ret);\r
         return ret;\r
     }\r
 \r
@@ -71,6 +73,7 @@ public class MicroServiceConfig {
         String url = getConfigBindingServiceAddrInfo() + "/service_component/" +serviceName;\r
         try {\r
             JSONObject jsonObject = JSONObject.fromObject(execQuery(url));\r
+            log.info("The origin configurations (" + url + ") returned by DCAE is: " + jsonObject.toString());\r
             if (jsonObject.has(serviceName)) {\r
                 ret = (String) jsonObject.getJSONArray(serviceName).get(0);\r
             }\r
@@ -92,7 +95,11 @@ public class MicroServiceConfig {
     public static String[] getMsbAddrInfo() {\r
         String[] msbServerInfo = null;\r
 \r
-        String info = getServiceAddrInfoFromCBS(MSB_ADDR);\r
+        //String info = getServiceAddrInfoFromCBS(MSB_ADDR);\r
+        String info = getServiceAddrInfoFromCBS(getEnv(HOSTNAME));\r
+        log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from CBS. The response is " + info + ".");\r
+        JSONObject infoObj = JSONObject.fromObject(info);\r
+        info = infoObj.has("msb.hostname") ? infoObj.getString("msb.hostname") : null;\r
         if (info != null){\r
             msbServerInfo = split(info);\r
         } else {\r
@@ -105,6 +112,7 @@ public class MicroServiceConfig {
     public static String[] getServiceAddrInfo() {\r
         String[] serviceAddrInfo = null;\r
         String info = getServiceAddrInfoFromCBS(getEnv(HOSTNAME));\r
+        log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from CBS. The response is " + info + ".");\r
         if (info != null){\r
             serviceAddrInfo = split(info);\r
         } else {\r