X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Fcommon%2Fconfig%2FMicroServiceConfig.java;h=7566fa171c2a2ee7266b6f4d44d5123710b0fed7;hb=6852ae1f9ad08c26a57911ef6c633d5f9757d693;hp=7cbbb3e24f463e443b23c00d34a8bace9e8cb0c4;hpb=6af8af01fb0cdceb384cf47cf241736620510465;p=holmes%2Fcommon.git diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java index 7cbbb3e..7566fa1 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2020 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package org.onap.holmes.common.config; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.onap.holmes.common.constant.AlarmConst; @@ -59,14 +60,16 @@ public class MicroServiceConfig { String queryString = getConsulAddrInfo() + hostname; log.info("Query the " + hostname + " address using the URL: " + queryString); try { - JsonObject addrJson = JsonParser.parseString(execQuery(queryString)) - .getAsJsonArray() - .get(0) - .getAsJsonObject(); - if (addrJson != null && addrJson.get("ServiceAddress") != null - && addrJson.get("ServicePort") != null) { - ret = "http://" + addrJson.get("ServiceAddress").getAsString() + ":" + addrJson - .get("ServicePort").getAsString(); + JsonArray addrArray = JsonParser.parseString(execQuery(queryString)).getAsJsonArray(); + if (addrArray.size() > 0) { + JsonObject addrJson = addrArray.get(0).getAsJsonObject(); + if (addrJson != null && addrJson.get("ServiceAddress") != null + && addrJson.get("ServicePort") != null) { + ret = "http://" + addrJson.get("ServiceAddress").getAsString() + ":" + addrJson + .get("ServicePort").getAsString(); + } + } else { + log.info("No service info is returned from DCAE Consul. Hostname: {}", hostname); } } catch (Exception e) { log.warn(e.getMessage(), e); @@ -107,7 +110,7 @@ public class MicroServiceConfig { } public static String[] getMsbIpAndPort() { - return new String[] {getEnv(MSB_IAG_SERVICE_HOST), getEnv(MSB_IAG_SERVICE_PORT)}; + return new String[]{getEnv(MSB_IAG_SERVICE_HOST), getEnv(MSB_IAG_SERVICE_PORT)}; } public static String[] getMicroServiceIpAndPort() {