1. 将配置挪到config.properties
This commit is contained in:
parent
e2cc8e4eee
commit
9988a14649
|
|
@ -0,0 +1,71 @@
|
|||
package com.ai.cloud.config;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ConfigInitializer {
|
||||
|
||||
public static Logger logger = LogManager.getLogger(ConfigInitializer.class);
|
||||
|
||||
public static void initialize(Properties properties, Class<?> rootConfigType) throws IllegalAccessException {
|
||||
initNextLevel(properties, rootConfigType, new ConfigDesc());
|
||||
}
|
||||
|
||||
private static void initNextLevel(Properties properties, Class<?> recentConfigType, ConfigDesc parentDesc) throws NumberFormatException, IllegalArgumentException, IllegalAccessException {
|
||||
for (Field field : recentConfigType.getFields()) {
|
||||
if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
|
||||
String configKey = (parentDesc + "." +
|
||||
field.getName()).toLowerCase();
|
||||
String value = properties.getProperty(configKey);
|
||||
if (value != null) {
|
||||
if (field.getType().equals(int.class))
|
||||
field.set(null, Integer.valueOf(value));
|
||||
if (field.getType().equals(String.class))
|
||||
field.set(null, value);
|
||||
if (field.getType().equals(long.class))
|
||||
field.set(null, Long.valueOf(value));
|
||||
}
|
||||
logger.debug("{}={}", configKey, field.get(null));
|
||||
}
|
||||
}
|
||||
for (Class<?> innerConfiguration : recentConfigType.getClasses()) {
|
||||
parentDesc.append(innerConfiguration.getSimpleName());
|
||||
initNextLevel(properties, innerConfiguration, parentDesc);
|
||||
parentDesc.removeLastDesc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigDesc {
|
||||
private LinkedList<String> descs = new LinkedList<String>();
|
||||
|
||||
void append(String currentDesc) {
|
||||
descs.addLast(currentDesc);
|
||||
}
|
||||
|
||||
void removeLastDesc() {
|
||||
descs.removeLast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (descs.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder ret = new StringBuilder(descs.getFirst());
|
||||
boolean first = true;
|
||||
for (String desc : descs) {
|
||||
if (first) {
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
ret.append(".").append(desc);
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.ai.cloud.config;
|
||||
|
||||
import com.ai.cloud.util.Constants;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.servlet.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class InitialConfigFilter implements Filter {
|
||||
|
||||
private Logger logger = LogManager.getLogger(InitialConfigFilter.class);
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(InitialConfigFilter.class.getResourceAsStream("/config.properties"));
|
||||
ConfigInitializer.initialize(properties, Constants.class);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.error("Failed to init config.", e);
|
||||
System.exit(-1);
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to init config.", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package com.ai.cloud.util;
|
||||
|
||||
|
|
@ -8,75 +8,92 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* 常量类
|
||||
*
|
||||
*
|
||||
* @author tz
|
||||
* @date 2015年11月10日 下午2:51:25
|
||||
* @version V0.1
|
||||
* @date 2015年11月10日 下午2:51:25
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
public static final String VERSION_STR = "version";
|
||||
public static final String VERSION_STR = "version";
|
||||
|
||||
public static final String VERSION_VAL = "0.1";
|
||||
public static final String VERSION_VAL = "0.1";
|
||||
|
||||
/** hbase集群 */
|
||||
public static final String QUORUM = "10.1.235.197,10.1.235.198,10.1.235.199";
|
||||
/** zk端口 */
|
||||
public static final String CLIENT_PORT = "29181";
|
||||
/** hbase表名 */
|
||||
public static final String TABLE_NAME_CHAIN = "sw-call-chain";
|
||||
/** 层级分割符 */
|
||||
public static final char VAL_SPLIT_CHAR = '.';
|
||||
/** RPC远端调用节点结束标识 */
|
||||
public static final String RPC_END_FLAG = "-S";
|
||||
public static class HBaseConfig {
|
||||
/**
|
||||
* hbase集群
|
||||
*/
|
||||
public static String QUORUM;
|
||||
/**
|
||||
* zk端口
|
||||
*/
|
||||
public static String CLIENT_PORT;
|
||||
}
|
||||
|
||||
public static final String SPAN_TYPE_M = "M";
|
||||
public static final String SPAN_TYPE_J = "J";
|
||||
public static final String SPAN_TYPE_W = "W";
|
||||
public static final String SPAN_TYPE_D = "D";
|
||||
public static final String SPAN_TYPE_U = "U";
|
||||
/** SPAN_TYPE码表 */
|
||||
public static Map<String, String> SPAN_TYPE_MAP = new HashMap<String, String>() {
|
||||
{
|
||||
put("M", "JAVA");
|
||||
put("J", "JDBC");
|
||||
put("W", "WEB");
|
||||
put("D", "DUBBO");
|
||||
put("U", "UNKNOWN");
|
||||
}
|
||||
};
|
||||
/**
|
||||
* hbase表名
|
||||
*/
|
||||
public static final String TABLE_NAME_CHAIN = "sw-call-chain";
|
||||
/**
|
||||
* 层级分割符
|
||||
*/
|
||||
public static final char VAL_SPLIT_CHAR = '.';
|
||||
/**
|
||||
* RPC远端调用节点结束标识
|
||||
*/
|
||||
public static final String RPC_END_FLAG = "-S";
|
||||
|
||||
public static final String STATUS_CODE_0 = "0";
|
||||
public static final String STATUS_CODE_1 = "1";
|
||||
public static final String STATUS_CODE_9 = "9";
|
||||
/** STATUS_CODE码表 */
|
||||
public static Map<String, String> STATUS_CODE_MAP = new HashMap<String, String>() {
|
||||
{
|
||||
put("0", "OK");
|
||||
put("1", "FAIL");
|
||||
put("9", "MISSING");
|
||||
}
|
||||
};
|
||||
|
||||
public static final String JSON_RESULT_KEY_RESULT = "result";
|
||||
public static final String JSON_RESULT_KEY_RESULT_OK = "OK";
|
||||
public static final String JSON_RESULT_KEY_RESULT_FAIL = "FAIL";
|
||||
|
||||
public static final String JSON_RESULT_KEY_RESULT_MSG = "msg";
|
||||
public static final String JSON_RESULT_KEY_RESULT_DATA = "data";
|
||||
|
||||
public static final String ROLE_TYPE_USER = "user";
|
||||
public static final String ROLE_TYPE_ADMIN = "admin";
|
||||
|
||||
public static final String STR_VAL_A = "A";
|
||||
public static final String STR_VAL_P = "P";
|
||||
|
||||
public static final String IS_GLOBAL_FALG_0 = "0";
|
||||
public static final String IS_GLOBAL_FALG_1 = "1";
|
||||
|
||||
public static final String TODO_TYPE_0 = "0";
|
||||
public static final String TODO_TYPE_1 = "1";
|
||||
|
||||
public static final String MAIL_SPLIT_CHAR = ",";
|
||||
public static final String SPAN_TYPE_M = "M";
|
||||
public static final String SPAN_TYPE_J = "J";
|
||||
public static final String SPAN_TYPE_W = "W";
|
||||
public static final String SPAN_TYPE_D = "D";
|
||||
public static final String SPAN_TYPE_U = "U";
|
||||
/**
|
||||
* SPAN_TYPE码表
|
||||
*/
|
||||
public static Map<String, String> SPAN_TYPE_MAP = new HashMap<String, String>() {
|
||||
{
|
||||
put("M", "JAVA");
|
||||
put("J", "JDBC");
|
||||
put("W", "WEB");
|
||||
put("D", "DUBBO");
|
||||
put("U", "UNKNOWN");
|
||||
}
|
||||
};
|
||||
|
||||
public static final String STATUS_CODE_0 = "0";
|
||||
public static final String STATUS_CODE_1 = "1";
|
||||
public static final String STATUS_CODE_9 = "9";
|
||||
/**
|
||||
* STATUS_CODE码表
|
||||
*/
|
||||
public static Map<String, String> STATUS_CODE_MAP = new HashMap<String, String>() {
|
||||
{
|
||||
put("0", "OK");
|
||||
put("1", "FAIL");
|
||||
put("9", "MISSING");
|
||||
}
|
||||
};
|
||||
|
||||
public static final String JSON_RESULT_KEY_RESULT = "result";
|
||||
public static final String JSON_RESULT_KEY_RESULT_OK = "OK";
|
||||
public static final String JSON_RESULT_KEY_RESULT_FAIL = "FAIL";
|
||||
|
||||
public static final String JSON_RESULT_KEY_RESULT_MSG = "msg";
|
||||
public static final String JSON_RESULT_KEY_RESULT_DATA = "data";
|
||||
|
||||
public static final String ROLE_TYPE_USER = "user";
|
||||
public static final String ROLE_TYPE_ADMIN = "admin";
|
||||
|
||||
public static final String STR_VAL_A = "A";
|
||||
public static final String STR_VAL_P = "P";
|
||||
|
||||
public static final String IS_GLOBAL_FALG_0 = "0";
|
||||
public static final String IS_GLOBAL_FALG_1 = "1";
|
||||
|
||||
public static final String TODO_TYPE_0 = "0";
|
||||
public static final String TODO_TYPE_1 = "1";
|
||||
|
||||
public static final String MAIL_SPLIT_CHAR = ",";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ public class HBaseConnectionUtil {
|
|||
try {
|
||||
if (configuration == null) {
|
||||
configuration = HBaseConfiguration.create();
|
||||
configuration.set("hbase.zookeeper.quorum", Constants.QUORUM);
|
||||
configuration.set("hbase.zookeeper.property.clientPort", Constants.CLIENT_PORT);
|
||||
configuration.set("hbase.zookeeper.quorum", Constants.HBaseConfig.QUORUM);
|
||||
configuration.set("hbase.zookeeper.property.clientPort", Constants.HBaseConfig.CLIENT_PORT);
|
||||
connection = ConnectionFactory.createConnection(configuration);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
hbaseconfig.quorum=10.1.235.197,10.1.235.198,10.1.235.199
|
||||
hbaseconfig.client_port=29181
|
||||
|
|
@ -1,52 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>skywalking-webui</display-name>
|
||||
<servlet>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
classpath*:spring/springmvc-servlet.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<filter>
|
||||
<filter-name>CharacterEncodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>skywalking-webui</display-name>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter-mapping>
|
||||
<filter-name>CharacterEncodingFilter</filter-name>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
</filter-mapping>
|
||||
<filter>
|
||||
<filter-name>InitialConfig</filter-name>
|
||||
<filter-class>com.ai.cloud.config.InitialConfigFilter</filter-class>
|
||||
</filter>
|
||||
|
||||
<error-page>
|
||||
<error-code>404</error-code>
|
||||
<location>/404</location>
|
||||
</error-page>
|
||||
<error-page>
|
||||
<error-code>500</error-code>
|
||||
<location>/500</location>
|
||||
</error-page>
|
||||
<filter-mapping>
|
||||
<filter-name>InitialConfig</filter-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>index</welcome-file>
|
||||
</welcome-file-list>
|
||||
<servlet>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
classpath*:spring/springmvc-servlet.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<filter>
|
||||
<filter-name>CharacterEncodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter-mapping>
|
||||
<filter-name>CharacterEncodingFilter</filter-name>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
</filter-mapping>
|
||||
|
||||
<error-page>
|
||||
<error-code>404</error-code>
|
||||
<location>/404</location>
|
||||
</error-page>
|
||||
<error-page>
|
||||
<error-code>500</error-code>
|
||||
<location>/500</location>
|
||||
</error-page>
|
||||
|
||||
<welcome-file-list>
|
||||
<welcome-file>index</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
</web-app>
|
||||
|
|
|
|||
Loading…
Reference in New Issue