Fix java check style issue
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / wrapper / util / ConfigUtil.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  *
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
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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
12  * the License.
13  */
14 package org.onap.msb.sdclient.wrapper.util;
15
16 import org.apache.commons.lang3.StringUtils;
17 import org.onap.msb.sdclient.DiscoverAppConfig;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * @ClassName: ConfigUtil
23  * @Description: TODO(服务发现配置项工具类)
24  * @author tanghua10186366
25  * @date 2017年1月23日
26  * 
27  */
28 public class ConfigUtil {
29
30     private static ConfigUtil instance = new ConfigUtil();
31
32
33     private ConfigUtil() {}
34
35     public static ConfigUtil getInstance() {
36         return instance;
37     }
38
39
40     private String tcpudpPortRangeStart = DiscoverUtil.TCP_UDP_PORT_RANGE_START;
41
42     private String tcpudpPortRangeEnd = DiscoverUtil.TCP_UDP_PORT_RANGE_END;
43
44     private String consulAddress = DiscoverUtil.CONSUL_ADDRESSS;
45
46     private String consulRegisterMode = DiscoverUtil.CONSUL_REGISTER_MODE;
47
48     private static final Logger LOGGER = LoggerFactory.getLogger(ConfigUtil.class);
49
50     public void initConsulClientInfo(DiscoverAppConfig config) {
51
52
53         String env_CONSUL_IP = System.getenv("CONSUL_IP");
54
55
56         if (StringUtils.isNotBlank(env_CONSUL_IP)) {
57             String consul_port = DiscoverUtil.CONSUL_DEFAULT_PORT;
58             try {
59                 consul_port = config.getConsulAdderss().split(":")[1];
60             } catch (Exception e) {
61                 LOGGER.error("initConsulClientInfo throw err:" + e.getMessage());
62             }
63
64             consulAddress = env_CONSUL_IP + ":" + consul_port;
65         } else if (StringUtils.isNotBlank(config.getConsulAdderss())) {
66             {
67                 consulAddress = config.getConsulAdderss();
68             }
69
70
71             LOGGER.info("init Discover CONSUL ADDRESSS:" + consulAddress);
72
73
74         }
75     }
76
77     public void initTCP_UDP_portRange() {
78
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");
81
82
83         if (StringUtils.isNotBlank(env_TCP_UDP_PORT_RANGE_START)) {
84             tcpudpPortRangeStart = env_TCP_UDP_PORT_RANGE_START;
85         }
86
87
88         if (StringUtils.isNotBlank(env_TCP_UDP_PORT_RANGE_END)) {
89             tcpudpPortRangeEnd = env_TCP_UDP_PORT_RANGE_END;
90         }
91
92         LOGGER.info("init TCP_UDP portRange:" + tcpudpPortRangeStart + "-" + tcpudpPortRangeEnd);
93
94     }
95
96     public void initConsulRegisterMode(DiscoverAppConfig config) {
97
98         String env_CONSUL_REGISTER_MODE = System.getenv("CONSUL_REGISTER_MODE");
99
100         if (StringUtils.isNotBlank(env_CONSUL_REGISTER_MODE)) {
101             consulRegisterMode = env_CONSUL_REGISTER_MODE;
102         } else {
103             if (StringUtils.isNotBlank(config.getConsulRegisterMode())) {
104                 consulRegisterMode = config.getConsulRegisterMode();
105             }
106         }
107
108         LOGGER.info("init Consul Register Mode:" + consulRegisterMode);
109
110     }
111
112
113
114     public String getConsulAddress() {
115         return consulAddress;
116     }
117
118     public String getTcpudpPortRangeStart() {
119         return tcpudpPortRangeStart;
120     }
121
122
123     public String getTcpudpPortRangeEnd() {
124         return tcpudpPortRangeEnd;
125     }
126
127
128     public String getConsulRegisterMode() {
129         return consulRegisterMode;
130     }
131
132
133
134 }