+ final static public String CONSUL_ADDR_SUF = ":8500/v1/catalog/service/";\r
+ final static public String CONSUL_HOST = "CONSUL_HOST";\r
+ final static public String HOSTNAME = "HOSTNAME";\r
+ final static public String POD_IP = "POD_IP";\r
+ final static public String CONFIG_BINDING_SERVICE = "CONFIG_BINDING_SERVICE";\r
+ final static public String DOCKER_HOST = "DOCKER_HOST";\r
+ final static public String MSB_ADDR = "MSB_ADDR";\r
+ final static public String MSB_IAG_SERVICE_HOST = "MSB_IAG_SERVICE_HOST";\r
+ final static public String MSB_IAG_SERVICE_PORT = "MSB_IAG_SERVICE_PORT";\r
+\r
+ final static public String AAI_HOSTNAME = "aai.onap";\r
+\r
+ final static public Logger log = LoggerFactory.getLogger(MicroServiceConfig.class);\r
+\r
+ 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
+ JsonArray addrArray = JsonParser.parseString(execQuery(queryString)).getAsJsonArray();\r
+ if (addrArray.size() > 0) {\r
+ JsonObject addrJson = addrArray.get(0).getAsJsonObject();\r
+ if (addrJson != null && addrJson.get("ServiceAddress") != null\r
+ && addrJson.get("ServicePort") != null) {\r
+ ret = "http://" + addrJson.get("ServiceAddress").getAsString() + ":" + addrJson\r
+ .get("ServicePort").getAsString();\r
+ }\r
+ } else {\r
+ log.info("No service info is returned from DCAE Consul. Hostname: {}", hostname);\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