2 * Copyright 2016 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.aai.esr.common;
19 import org.onap.aai.esr.externalservice.entity.ServiceRegisterEntity;
20 import org.onap.aai.esr.externalservice.msb.MicroserviceBusConsumer;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
30 public class ServiceRegistrer implements Runnable {
31 private final ServiceRegisterEntity extsysEntity = new ServiceRegisterEntity();
32 private static final Logger LOG = LoggerFactory.getLogger(ServiceRegistrer.class);
34 public ServiceRegistrer() {
40 LOG.info("start extsys microservice register");
43 while (!flag && retry < 1000) {
44 LOG.info("extsys microservice register.retry:" + retry);
46 flag = MicroserviceBusConsumer.registerService(extsysEntity);
48 LOG.warn("microservice register failed, sleep 30S and try again.");
51 LOG.info("microservice register success!");
55 LOG.info("extsys microservice register end.");
58 private void threadSleep(int second) {
59 LOG.info("start sleep ....");
62 } catch (InterruptedException error) {
63 LOG.error("thread sleep error.errorMsg:" + error.getMessage());
65 LOG.info("sleep end .");
68 private void initServiceEntity() {
69 extsysEntity.setServiceName("extsys");
70 extsysEntity.setProtocol("REST");
71 extsysEntity.setVersion("v1");
72 extsysEntity.setUrl("/openoapi/extsys/v1");
73 extsysEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8100", 0);
74 extsysEntity.setVisualRange("1");