2 * Copyright 2017 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 static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
\r
21 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
\r
22 import java.io.IOException;
\r
23 import lombok.extern.slf4j.Slf4j;
\r
24 import org.jvnet.hk2.annotations.Service;
\r
25 import org.onap.holmes.common.api.entity.ServiceRegisterEntity;
\r
26 import org.onap.holmes.common.config.MicroServiceConfig;
\r
27 import org.onap.holmes.common.exception.CorrelationException;
\r
28 import org.onap.holmes.common.msb.MicroserviceBusRest;
\r
29 import org.onap.msb.sdk.discovery.common.RouteException;
\r
30 import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
\r
31 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
\r
32 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
\r
36 public class MSBRegisterUtil {
\r
38 public void register2Msb(MicroServiceInfo msinfo) throws CorrelationException {
\r
39 String[] msbAddrInfo = MicroServiceConfig.getMsbAddrInfo();
\r
40 MSBServiceClient msbClient = new MSBServiceClient(msbAddrInfo[0],
\r
41 Integer.parseInt(msbAddrInfo[1]));
\r
43 log.info("Start to register Holmes Service to MSB...");
\r
44 MicroServiceFullInfo microServiceFullInfo = null;
\r
46 while (null == microServiceFullInfo && retry < 20) {
\r
47 log.info("Holmes Service Registration. Retry: " + retry);
\r
50 microServiceFullInfo = msbClient.registerMicroServiceInfo(msinfo, false);
\r
51 } catch (RouteException e) {
\r
55 if (null == microServiceFullInfo) {
\r
56 log.warn("Failed to register the service to MSB. Sleep 30s and try again.");
\r
59 log.info("Registration succeeded!");
\r
64 if (null == microServiceFullInfo) {
\r
65 throw new CorrelationException("Failed to register the service to MSB!");
\r
68 log.info("Service registration completed.");
\r
71 private void threadSleep(int second) {
\r
72 log.info("Start sleeping...");
\r
74 Thread.sleep(second);
\r
75 } catch (InterruptedException error) {
\r
76 log.error("thread sleep error message:" + error.getMessage(), error);
\r
77 Thread.currentThread().interrupt();
\r
79 log.info("Wake up.");
\r