From d070fcda2258da7dde32bd56f6d62a6d03742617 Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Thu, 3 Mar 2022 11:34:32 +0800 Subject: bugfix - fixed the healthcheck problem Issue-ID: HOLMES-512 Signed-off-by: GuangrongFu Change-Id: I95891f918b0abb2ea74caf8f1d39aed92c80624c --- .../java/org/onap/holmes/engine/Initializer.java | 34 +++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'engine-d/src/main') diff --git a/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java b/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java index 9eca2a6..f3dae34 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/Initializer.java @@ -29,6 +29,8 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import static org.onap.holmes.common.config.MicroServiceConfig.getMicroServiceIpAndPort; import static org.onap.holmes.common.utils.CommonUtils.getEnv; @@ -37,6 +39,7 @@ import static org.onap.holmes.common.utils.CommonUtils.isIpAddress; @Service public class Initializer { private static final Logger logger = LoggerFactory.getLogger(Initializer.class); + private volatile static boolean readyForMsbReg = false; private MsbRegister msbRegister; @Inject @@ -46,13 +49,36 @@ public class Initializer { @PostConstruct private void init() { - try { - msbRegister.register2Msb(createMicroServiceInfo()); - } catch (CorrelationException e) { - logger.error(e.getMessage(), e); + Executors.newSingleThreadExecutor().execute(() -> { + waitUntilReady(); + try { + msbRegister.register2Msb(createMicroServiceInfo()); + } catch (CorrelationException e) { + logger.error(e.getMessage(), e); + } + }); + } + + private void waitUntilReady() { + int count = 1; + while (!readyForMsbReg) { + if (count > 20) { + break; + } + int interval = 5 * count++; + logger.info("Not ready for MSB registration. Try again after {} seconds...", interval); + try { + TimeUnit.SECONDS.sleep(interval); + } catch (InterruptedException e) { + logger.info(e.getMessage(), e); + } } } + public static void setReadyForMsbReg(boolean readyForMsbReg) { + Initializer.readyForMsbReg = readyForMsbReg; + } + private MicroServiceInfo createMicroServiceInfo() { String[] serviceIpAndPort = getMicroServiceIpAndPort(); MicroServiceInfo msinfo = new MicroServiceInfo(); -- cgit 1.2.3-korg