diff options
author | GuangrongFu <fu.guangrong@zte.com.cn> | 2022-03-03 11:34:32 +0800 |
---|---|---|
committer | GuangrongFu <fu.guangrong@zte.com.cn> | 2022-03-03 11:34:32 +0800 |
commit | d070fcda2258da7dde32bd56f6d62a6d03742617 (patch) | |
tree | 5bd4b20c31c49de56154a77d828e84bca18d6255 /engine-d/src/main/java/org | |
parent | 3ec3a8e1980c1c1bd08f9f0e28b76f46d11ba9f6 (diff) |
bugfix - fixed the healthcheck problem
Issue-ID: HOLMES-512
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Change-Id: I95891f918b0abb2ea74caf8f1d39aed92c80624c
Diffstat (limited to 'engine-d/src/main/java/org')
-rw-r--r-- | engine-d/src/main/java/org/onap/holmes/engine/Initializer.java | 34 |
1 files changed, 30 insertions, 4 deletions
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(); |