}\r
\r
public static String getConsulAddrInfo() {\r
- return getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;\r
+ return "http://" + getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;\r
}\r
\r
- public static String getConfigBindingServiceAddrInfo() {\r
+ public static String getServiceAddrInfoFromDcaeConsulByHostName(String hostname) {\r
String ret = null;\r
- String queryString = getConsulAddrInfo() + CONFIG_BINDING_SERVICE;\r
- log.info("Query the CBS address using the URL: " + queryString);\r
+ String queryString = getConsulAddrInfo() + hostname;\r
+ log.info("Query the " + hostname + " 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
- ret = addrJson.getString("ServiceAddress") + ":" + addrJson.getString("ServicePort");\r
+ ret = "http://" + addrJson.getString("ServiceAddress") + ":" + addrJson.getString("ServicePort");\r
}\r
} catch (Exception e) {\r
log.warn(e.getMessage(), e);\r
}\r
- log.info("The CBS address is " + ret);\r
+ log.info("The " + hostname + " address is " + ret);\r
return ret;\r
}\r
\r
return response.readEntity(String.class);\r
}\r
\r
- public static String getServiceAddrInfoFromCBS(String serviceName) {\r
+ public static String getServiceConfigInfoFromCBS(String hostname) {\r
String ret = null;\r
- String url = getConfigBindingServiceAddrInfo() + "/service_component/" +serviceName;\r
+ String url = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(CONFIG_BINDING_SERVICE)) + "/service_component/" + hostname;\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
+ ret = execQuery(url);\r
} catch (Exception e) {\r
log.warn(e.getMessage(), e);\r
}\r
+ log.info("The query url is: " + url + ". The corresponding configurations are " + ret);\r
return ret;\r
}\r
\r
- public static String getMsbServerAddr() {\r
- String[] addrInfo = getMsbAddrInfo();\r
+ public static String getMsbServerAddrWithHttpPrefix() {\r
+ String[] addrInfo = getMsbIpAndPort();\r
String ret = addrInfo[0] + ":" + addrInfo[1];\r
if (!ret.startsWith(AlarmConst.HTTP) || !ret.startsWith(AlarmConst.HTTPS)){\r
ret = AlarmConst.HTTP + ret;\r
return ret;\r
}\r
\r
- public static String[] getMsbAddrInfo() {\r
- String[] msbServerInfo = null;\r
-\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
-\r
- if (info != null){\r
- JSONObject infoObj = JSONObject.fromObject(info);\r
- String msbInfoTmp = infoObj.has("msb.hostname") ? infoObj.getString("msb.hostname") : null;\r
- if (msbInfoTmp != null) {\r
- msbServerInfo = split(msbInfoTmp);\r
- } else {\r
- msbServerInfo = split(getEnv(MSB_ADDR));\r
- }\r
- } else {\r
- msbServerInfo = split(getEnv(MSB_ADDR));\r
- }\r
-\r
- return msbServerInfo;\r
+ public static String[] getMsbIpAndPort() {\r
+ return split(getEnv(MSB_ADDR));\r
}\r
\r
- public static String[] getServiceAddrInfo() {\r
+ public static String[] getMicroServiceIpAndPort() {\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
+ String info = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(HOSTNAME));\r
+ log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from Consul. The response is " + info + ".");\r
+ if (info != null && !info.isEmpty()){\r
serviceAddrInfo = split(info);\r
} else {\r
serviceAddrInfo = split(getEnv(HOSTNAME));\r