+++ /dev/null
-/**\r
- * Copyright 2017-2020 ZTE Corporation.\r
- * <p>\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * <p>\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * <p>\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.holmes.common.utils;\r
-\r
-import lombok.extern.slf4j.Slf4j;\r
-import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.config.MicroServiceConfig;\r
-import org.onap.holmes.common.exception.CorrelationException;\r
-import org.onap.msb.sdk.discovery.common.RouteException;\r
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;\r
-import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
-import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;\r
-\r
-@Slf4j\r
-@Service\r
-public class MSBRegisterUtil {\r
-\r
- public void register2Msb(MicroServiceInfo msinfo) throws CorrelationException {\r
- String[] msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();\r
- MSBServiceClient msbClient = new MSBServiceClient(msbAddrInfo[0],\r
- Integer.parseInt(msbAddrInfo[1]));\r
-\r
- log.info("Start to register Holmes Service to MSB...");\r
- MicroServiceFullInfo microServiceFullInfo = null;\r
- int retry = 0;\r
- while (null == microServiceFullInfo && retry < 20) {\r
- log.info("Holmes Service Registration. Retry: " + retry);\r
- retry++;\r
- try {\r
- microServiceFullInfo = msbClient.registerMicroServiceInfo(msinfo, false);\r
- } catch (RouteException e) {\r
-\r
- }\r
-\r
- if (null == microServiceFullInfo) {\r
- log.warn("Failed to register the service to MSB. Sleep 30s and try again.");\r
- threadSleep(30000);\r
- } else {\r
- log.info("Registration succeeded!");\r
- break;\r
- }\r
- }\r
-\r
- if (null == microServiceFullInfo) {\r
- throw new CorrelationException("Failed to register the service to MSB!");\r
- }\r
-\r
- log.info("Service registration completed.");\r
- }\r
-\r
- private void threadSleep(int second) {\r
- log.info("Start sleeping...");\r
- try {\r
- Thread.sleep(second);\r
- } catch (InterruptedException error) {\r
- log.error("thread sleep error message:" + error.getMessage(), error);\r
- Thread.currentThread().interrupt();\r
- }\r
- log.info("Wake up.");\r
- }\r
-}
\ No newline at end of file