2 * Copyright 2017-2020 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.holmes.common.utils;
\r
19 import lombok.extern.slf4j.Slf4j;
\r
20 import org.jvnet.hk2.annotations.Service;
\r
21 import org.onap.holmes.common.config.MicroServiceConfig;
\r
22 import org.onap.holmes.common.exception.CorrelationException;
\r
23 import org.onap.msb.sdk.discovery.common.RouteException;
\r
24 import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
\r
25 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
\r
26 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
\r
30 public class MSBRegisterUtil {
\r
32 public void register2Msb(MicroServiceInfo msinfo) throws CorrelationException {
\r
33 String[] msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();
\r
34 MSBServiceClient msbClient = new MSBServiceClient(msbAddrInfo[0],
\r
35 Integer.parseInt(msbAddrInfo[1]));
\r
37 log.info("Start to register Holmes Service to MSB...");
\r
38 MicroServiceFullInfo microServiceFullInfo = null;
\r
40 while (null == microServiceFullInfo && retry < 20) {
\r
41 log.info("Holmes Service Registration. Retry: " + retry);
\r
44 microServiceFullInfo = msbClient.registerMicroServiceInfo(msinfo, false);
\r
45 } catch (RouteException e) {
\r
49 if (null == microServiceFullInfo) {
\r
50 log.warn("Failed to register the service to MSB. Sleep 30s and try again.");
\r
53 log.info("Registration succeeded!");
\r
58 if (null == microServiceFullInfo) {
\r
59 throw new CorrelationException("Failed to register the service to MSB!");
\r
62 log.info("Service registration completed.");
\r
65 private void threadSleep(int second) {
\r
66 log.info("Start sleeping...");
\r
68 Thread.sleep(second);
\r
69 } catch (InterruptedException error) {
\r
70 log.error("thread sleep error message:" + error.getMessage(), error);
\r
71 Thread.currentThread().interrupt();
\r
73 log.info("Wake up.");
\r