diff options
author | GuangrongFu <fu.guangrong@zte.com.cn> | 2022-03-15 20:16:58 +0800 |
---|---|---|
committer | GuangrongFu <fu.guangrong@zte.com.cn> | 2022-03-15 20:21:36 +0800 |
commit | 8c5da34af36d79d6210e0ac6708079ada670b1e8 (patch) | |
tree | a14dd9673150afc707c30eb9e31f49e9b7bf70a5 /holmes-actions/src | |
parent | 9980653129155973f31e599d7789aae9c65828c9 (diff) |
bugfix - catch runtime exceptions during MSB reg
Issue-ID: HOLMES-512
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Change-Id: I0e6862f0a73f4408cd62c329ade037b639552c05
Diffstat (limited to 'holmes-actions/src')
-rw-r--r-- | holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java index 79ccbdc..3b72aaf 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java @@ -53,23 +53,27 @@ public class MsbRegister { int retry = 0; int interval = 5; while (null == microServiceFullInfo && retry < 20) { - log.info("Holmes Service Registration. Retry: " + retry++); - - microServiceFullInfo = client - .header("Accept", MediaType.APPLICATION_JSON) - .queryParam("createOrUpdate", true) - .post(String.format("%s://%s:%s/api/microservices/v1/services", - isHttpsEnabled ? PROTOCOL_HTTPS : PROTOCOL_HTTP, msbAddrInfo[0], msbAddrInfo[1]), - Entity.entity(msinfo, MediaType.APPLICATION_JSON), - MicroServiceFullInfo.class); - - if (null == microServiceFullInfo) { - log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", interval)); - threadSleep(TimeUnit.SECONDS.toSeconds(interval)); - interval += 5; - } else { - log.info("Registration succeeded!"); - break; + try { + log.info("Holmes Service Registration. Retry: " + retry++); + + microServiceFullInfo = client + .header("Accept", MediaType.APPLICATION_JSON) + .queryParam("createOrUpdate", true) + .post(String.format("%s://%s:%s/api/microservices/v1/services", + isHttpsEnabled ? PROTOCOL_HTTPS : PROTOCOL_HTTP, msbAddrInfo[0], msbAddrInfo[1]), + Entity.entity(msinfo, MediaType.APPLICATION_JSON), + MicroServiceFullInfo.class); + + if (null == microServiceFullInfo) { + log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", interval)); + threadSleep(TimeUnit.SECONDS.toSeconds(interval)); + interval += 5; + } else { + log.info("Registration succeeded!"); + break; + } + } catch (Exception e) { + log.warn("Unexpected exception: " + e.getMessage(), e); } } |