2 * Copyright 2017-2018 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.holmes.rulemgt;
19 import org.jvnet.hk2.annotations.Service;
20 import org.onap.holmes.common.config.MicroServiceConfig;
21 import org.onap.holmes.common.exception.CorrelationException;
22 import org.onap.holmes.common.utils.CommonUtils;
23 import org.onap.holmes.common.utils.MsbRegister;
24 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
25 import org.onap.msb.sdk.discovery.entity.Node;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import javax.annotation.PostConstruct;
30 import javax.inject.Inject;
31 import java.util.HashSet;
34 import static org.onap.holmes.common.utils.CommonUtils.getEnv;
35 import static org.onap.holmes.common.utils.CommonUtils.isIpAddress;
38 public class Initializer {
39 private static final Logger logger = LoggerFactory.getLogger(Initializer.class);
40 private MsbRegister msbRegister;
43 public Initializer(MsbRegister msbRegister) {
44 this.msbRegister = msbRegister;
50 msbRegister.register2Msb(createMicroServiceInfo());
51 } catch (CorrelationException e) {
52 logger.error(e.getMessage(), e);
56 private MicroServiceInfo createMicroServiceInfo() {
57 String[] serviceIpAndPort = MicroServiceConfig.getMicroServiceIpAndPort();
58 MicroServiceInfo msinfo = new MicroServiceInfo();
59 msinfo.setServiceName("holmes-rule-mgmt");
60 msinfo.setVersion("v1");
61 msinfo.setUrl("/api/holmes-rule-mgmt/v1");
62 msinfo.setPath("/api/holmes-rule-mgmt/v1");
63 msinfo.setProtocol("REST");
64 msinfo.setVisualRange("0|1");
65 msinfo.setLb_policy("round-robin");
66 msinfo.setEnable_ssl(CommonUtils.isHttpsEnabled());
67 Set<Node> nodes = new HashSet<>();
68 Node node = new Node();
69 node.setIp(isIpAddress(serviceIpAndPort[0]) ? serviceIpAndPort[0] : getEnv("HOLMES_RULE_MGMT_SERVICE_HOST"));
71 /* Following codes will cause an unregistration from MSB (due to MSB malfunction), comment them for now
72 String msbAddrTemplate = (CommonUtils.isHttpsEnabled() ? "https" : "http")
73 + "://%s:%s/api/holmes-rule-mgmt/v1/healthcheck";
74 node.setCheckType("HTTP");
75 node.setCheckUrl(String.format(msbAddrTemplate, serviceIpAndPort[0], "9101"));
76 node.setCheckTimeOut("60s");
77 node.setCheckInterval("60s");*/
80 msinfo.setNodes(nodes);