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.glassfish.jersey.client.ClientConfig;
\r
23 import org.jvnet.hk2.annotations.Service;
\r
24 import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
\r
25 import org.openo.holmes.common.config.MicroServiceConfig;
\r
26 import org.openo.holmes.common.msb.MicroserviceBusRest;
\r
30 public class MSBRegisterUtil {
\r
32 public void register(ServiceRegisterEntity entity) throws IOException {
\r
33 log.info("start holmes micro service register");
\r
34 boolean flag = false;
\r
36 while (!flag && retry < 20) {
\r
37 log.info("Holmes microservice register. retry:" + retry);
\r
39 flag = inner_register(entity);
\r
41 log.warn("micro service register failed, sleep 30S and try again.");
\r
44 log.info("micro service register success!");
\r
48 log.info("holmes micro service register end.");
\r
51 private boolean inner_register(ServiceRegisterEntity entity) {
\r
52 ClientConfig config = new ClientConfig();
\r
54 log.info("msbServerAddr:" + MicroServiceConfig.getMsbServerAddr());
\r
55 log.info("entity:" + entity);
\r
56 MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer(
\r
57 MicroServiceConfig.getMsbServerAddr(), config, MicroserviceBusRest.class);
\r
58 resourceserviceproxy.registerServce("false", entity);
\r
59 } catch (Exception error) {
\r
60 log.error("microservice register failed!" + error.getMessage());
\r
66 private void threadSleep(int second) {
\r
67 log.info("start sleep ....");
\r
69 Thread.sleep(second);
\r
70 } catch (InterruptedException error) {
\r
71 log.error("thread sleep error.errorMsg:" + error.getMessage());
\r
73 log.info("sleep end .");
\r