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.openo.holmes.common.utils;
\r
19 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
\r
20 import java.io.IOException;
\r
21 import lombok.extern.slf4j.Slf4j;
\r
22 import org.jvnet.hk2.annotations.Service;
\r
23 import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
\r
24 import org.openo.holmes.common.config.MicroServiceConfig;
\r
25 import org.openo.holmes.common.msb.MicroserviceBusRest;
\r
29 public class MSBRegisterUtil {
\r
31 public void register(ServiceRegisterEntity entity) throws IOException {
\r
32 log.info("start holmes micro service register");
\r
33 boolean flag = false;
\r
35 while (!flag && retry < 20) {
\r
36 log.info("Holmes microservice register. retry:" + retry);
\r
38 flag = innerRegister(entity);
\r
40 log.warn("micro service register failed, sleep 30S and try again.");
\r
43 log.info("micro service register success!");
\r
47 log.info("holmes micro service register end.");
\r
50 private boolean innerRegister(ServiceRegisterEntity entity) {
\r
52 log.info("msbServerAddr:" + MicroServiceConfig.getMsbServerAddr());
\r
53 log.info("entity:" + entity);
\r
54 MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer(
\r
55 MicroServiceConfig.getMsbServerAddr(), MicroserviceBusRest.class);
\r
56 resourceserviceproxy.registerServce("false", entity);
\r
57 } catch (Exception error) {
\r
58 log.error("microservice register failed!" + error.getMessage(), error);
\r
64 private void threadSleep(int second) {
\r
65 log.info("start sleep ....");
\r
67 Thread.sleep(second);
\r
68 } catch (InterruptedException error) {
\r
69 log.error("thread sleep error.errorMsg:" + error.getMessage(), error);
\r
70 Thread.currentThread().interrupt();
\r
72 log.info("sleep end .");
\r