2 * Copyright 2016-2017 ZTE, Inc. and others.
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.
16 package org.onap.msb.sdclient.wrapper.util;
18 import org.apache.commons.lang3.StringUtils;
19 import org.onap.msb.sdclient.DiscoverAppConfig;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * @ClassName: ConfigUtil
25 * @Description: TODO(服务发现配置项工具类)
26 * @author tanghua10186366
30 public class ConfigUtil {
32 private static ConfigUtil instance = new ConfigUtil();
35 private ConfigUtil() {}
37 public static ConfigUtil getInstance() {
42 private String tcpudpPortRangeStart= DiscoverUtil.TCP_UDP_PORT_RANGE_START;
44 private String tcpudpPortRangeEnd=DiscoverUtil.TCP_UDP_PORT_RANGE_END;
46 private String consulAddress = DiscoverUtil.CONSUL_ADDRESSS;
48 private String consulRegisterMode=DiscoverUtil.CONSUL_REGISTER_MODE;
50 private static final Logger LOGGER = LoggerFactory.getLogger(ConfigUtil.class);
52 public void initConsulClientInfo(DiscoverAppConfig config) {
55 String env_CONSUL_IP = System.getenv("CONSUL_IP");
58 if (StringUtils.isNotBlank(env_CONSUL_IP)) {
59 String consul_port = DiscoverUtil.CONSUL_DEFAULT_PORT;
61 consul_port = config.getConsulAdderss().split(":")[1];
62 } catch (Exception e) {
63 LOGGER.error("initConsulClientInfo throw err:" + e.getMessage());
66 consulAddress = env_CONSUL_IP + ":" + consul_port;
67 } else if (StringUtils.isNotBlank(config.getConsulAdderss())) {
69 consulAddress = config.getConsulAdderss();
73 LOGGER.info("init Discover CONSUL ADDRESSS:" + consulAddress);
79 public void initTCP_UDP_portRange(){
81 String env_TCP_UDP_PORT_RANGE_START=System.getenv("TCP_UDP_PORT_RANGE_START");
82 String env_TCP_UDP_PORT_RANGE_END=System.getenv("TCP_UDP_PORT_RANGE_END");
85 if(StringUtils.isNotBlank(env_TCP_UDP_PORT_RANGE_START))
87 tcpudpPortRangeStart=env_TCP_UDP_PORT_RANGE_START;
91 if(StringUtils.isNotBlank(env_TCP_UDP_PORT_RANGE_END))
93 tcpudpPortRangeEnd=env_TCP_UDP_PORT_RANGE_END;
96 LOGGER.info("init TCP_UDP portRange:"+ tcpudpPortRangeStart+"-"+tcpudpPortRangeEnd);
100 public void initConsulRegisterMode(DiscoverAppConfig config){
102 String env_CONSUL_REGISTER_MODE=System.getenv("CONSUL_REGISTER_MODE");
104 if(StringUtils.isNotBlank(env_CONSUL_REGISTER_MODE))
106 consulRegisterMode=env_CONSUL_REGISTER_MODE;
109 if(StringUtils.isNotBlank(config.getConsulRegisterMode())){
110 consulRegisterMode=config.getConsulRegisterMode();
114 LOGGER.info("init Consul Register Mode:"+consulRegisterMode);
120 public String getConsulAddress() {
121 return consulAddress;
124 public String getTcpudpPortRangeStart() {
125 return tcpudpPortRangeStart;
129 public String getTcpudpPortRangeEnd() {
130 return tcpudpPortRangeEnd;
134 public String getConsulRegisterMode() {
135 return consulRegisterMode;