/**\r
- * Copyright 2017-2020 ZTE Corporation.\r
+ * Copyright 2017-2021 ZTE Corporation.\r
* <p>\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
*/\r
package org.onap.holmes.common.config;\r
\r
+import com.google.gson.JsonArray;\r
import com.google.gson.JsonObject;\r
import com.google.gson.JsonParser;\r
import org.onap.holmes.common.constant.AlarmConst;\r
String queryString = getConsulAddrInfo() + hostname;\r
log.info("Query the " + hostname + " address using the URL: " + queryString);\r
try {\r
- JsonObject addrJson = JsonParser.parseString(execQuery(queryString))\r
- .getAsJsonArray()\r
- .get(0)\r
- .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
+ 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
\r
public static String[] getMsbIpAndPort() {\r
- return new String[] {getEnv(MSB_IAG_SERVICE_HOST), getEnv(MSB_IAG_SERVICE_PORT)};\r
+ return new String[]{getEnv(MSB_IAG_SERVICE_HOST), getEnv(MSB_IAG_SERVICE_PORT)};\r
}\r
\r
public static String[] getMicroServiceIpAndPort() {\r