+ public static String getConsulAddrInfo() {\r
+ return "http://" + getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;\r
+ }\r
+\r
+ public static String getServiceAddrInfoFromDcaeConsulByHostName(String hostname) {\r
+ String ret = null;\r
+ String queryString = getConsulAddrInfo() + hostname;\r
+ log.info("Query the " + hostname + " address using the URL: " + queryString);\r
+ try {\r
+ JSONObject addrJson = (JSONObject) JSON.parseArray(execQuery(queryString)).get(0);\r
+ if (addrJson != null && addrJson.get("ServiceAddress") != null\r
+ && addrJson.get("ServicePort") != null) {\r
+ ret = "http://" + addrJson.getString("ServiceAddress") + ":" + addrJson\r
+ .getString("ServicePort");\r
+ }\r
+ } catch (Exception e) {\r
+ log.warn(e.getMessage(), e);\r
+ }\r
+ log.info("The " + hostname + " address is " + ret);\r
+ return ret;\r
+ }\r
+\r
+ private static String execQuery(String queryString) {\r
+ Client client = ClientBuilder.newBuilder().build();\r
+ Response response = client.target(queryString).request().get();\r
+ return response.readEntity(String.class);\r
+ }\r
+\r
+ public static String getServiceConfigInfoFromCBS(String hostname) {\r
+ String ret = null;\r
+ String url = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(CONFIG_BINDING_SERVICE)) + "/service_component/" + hostname;\r
+ try {\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 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
+ }\r
+ return ret;\r
+ }\r
+\r
+ public static String getAaiAddr() {\r
+ return AlarmConst.HTTPS + AAI_HOSTNAME + ":8443";\r