2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
14 package org.onap.msb.sdclient.wrapper.util;
16 import org.apache.commons.lang3.StringUtils;
17 import org.onap.msb.sdclient.DiscoverAppConfig;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * @ClassName: ConfigUtil
23 * @Description: TODO(服务发现配置项工具类)
24 * @author tanghua10186366
28 public class ConfigUtil {
30 private static ConfigUtil instance = new ConfigUtil();
33 private ConfigUtil() {}
35 public static ConfigUtil getInstance() {
40 private String tcpudpPortRangeStart = DiscoverUtil.TCP_UDP_PORT_RANGE_START;
42 private String tcpudpPortRangeEnd = DiscoverUtil.TCP_UDP_PORT_RANGE_END;
44 private String consulAddress = DiscoverUtil.CONSUL_ADDRESSS;
46 private String consulRegisterMode = DiscoverUtil.CONSUL_REGISTER_MODE;
48 private static final Logger LOGGER = LoggerFactory.getLogger(ConfigUtil.class);
50 public void initConsulClientInfo(DiscoverAppConfig config) {
53 String env_CONSUL_IP = System.getenv("CONSUL_IP");
56 if (StringUtils.isNotBlank(env_CONSUL_IP)) {
57 String consul_port = DiscoverUtil.CONSUL_DEFAULT_PORT;
59 consul_port = config.getConsulAdderss().split(":")[1];
60 } catch (Exception e) {
61 LOGGER.error("initConsulClientInfo throw err:" + e.getMessage());
64 consulAddress = env_CONSUL_IP + ":" + consul_port;
65 } else if (StringUtils.isNotBlank(config.getConsulAdderss())) {
67 consulAddress = config.getConsulAdderss();
71 LOGGER.info("init Discover CONSUL ADDRESSS:" + consulAddress);
77 public void initTCP_UDP_portRange() {
79 String env_TCP_UDP_PORT_RANGE_START = System.getenv("TCP_UDP_PORT_RANGE_START");
80 String env_TCP_UDP_PORT_RANGE_END = System.getenv("TCP_UDP_PORT_RANGE_END");
83 if (StringUtils.isNotBlank(env_TCP_UDP_PORT_RANGE_START)) {
84 tcpudpPortRangeStart = env_TCP_UDP_PORT_RANGE_START;
88 if (StringUtils.isNotBlank(env_TCP_UDP_PORT_RANGE_END)) {
89 tcpudpPortRangeEnd = env_TCP_UDP_PORT_RANGE_END;
92 LOGGER.info("init TCP_UDP portRange:" + tcpudpPortRangeStart + "-" + tcpudpPortRangeEnd);
96 public void initConsulRegisterMode(DiscoverAppConfig config) {
98 String env_CONSUL_REGISTER_MODE = System.getenv("CONSUL_REGISTER_MODE");
100 if (StringUtils.isNotBlank(env_CONSUL_REGISTER_MODE)) {
101 consulRegisterMode = env_CONSUL_REGISTER_MODE;
103 if (StringUtils.isNotBlank(config.getConsulRegisterMode())) {
104 consulRegisterMode = config.getConsulRegisterMode();
108 LOGGER.info("init Consul Register Mode:" + consulRegisterMode);
114 public String getConsulAddress() {
115 return consulAddress;
118 public String getTcpudpPortRangeStart() {
119 return tcpudpPortRangeStart;
123 public String getTcpudpPortRangeEnd() {
124 return tcpudpPortRangeEnd;
128 public String getConsulRegisterMode() {
129 return consulRegisterMode;