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.utils.CommonUtils.getEnv;
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
@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 = MicroServiceConfig.getMicroServiceIpAndPort();
MicroServiceInfo msinfo = new MicroServiceInfo();
Node node = new Node();
node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv("HOLMES_RULE_MGMT_SERVICE_HOST"));
node.setPort("9101");
- /* Following codes will cause an unregistration from MSB (due to MSB malfunction), comment them for now*/
+ /* Following codes will cause an unregistration from MSB (due to MSB malfunction), comment them for now
String msbAddrTemplate = (CommonUtils.isHttpsEnabled() ? "https" : "http")
+ "://%s:%s/api/holmes-rule-mgmt/v1/healthcheck";
node.setCheckType("HTTP");
node.setCheckUrl(String.format(msbAddrTemplate, serviceIpAndPort[0], "9101"));
node.setCheckTimeOut("60s");
- node.setCheckInterval("60s");
+ node.setCheckInterval("60s");*/
nodes.add(node);
msinfo.setNodes(nodes);