Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.更换数据库连接池 c3p0 => durid #267

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion disconf-client/deploy/package-jar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<directory>target/classes</directory>
<excludes>
<exclude>disconf.properties</exclude>
<exclude>logback.xml</exclude>
</excludes>
<outputDirectory>/</outputDirectory>
</fileSet>
Expand Down
32 changes: 21 additions & 11 deletions disconf-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.baidu.disconf</groupId>
<artifactId>disconf-base</artifactId>
<version>2.6.36</version>
<version>2.6.41</version>
</parent>

<licenses>
Expand Down Expand Up @@ -67,6 +67,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -83,6 +84,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -93,21 +95,29 @@
<!-- log dependencies -->

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- ================ test ================ -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private DisconfMgr() {
}

/**
* 总入口
* 总入口 (Just for test ?)
*/
public synchronized void start(List<String> scanPackageList) {

Expand Down Expand Up @@ -199,6 +199,38 @@ public synchronized void reloadableScan(String fileName) {
}
}

/**
* reloadable config file scan, for xml config
* Modify at 20170802 by felix.sung
*/
public synchronized void reloadableScan(String fileName,String relativePath) {

if (!isFirstInit) {
return;
}

if (DisClientConfig.getInstance().ENABLE_DISCONF) {
try {

if (!DisClientConfig.getInstance().getIgnoreDisconfKeySet().contains(fileName)) {

if (scanMgr != null) {
scanMgr.reloadableScan(fileName,relativePath);
}

if (disconfCoreMgr != null) {
disconfCoreMgr.processFile(fileName);
}
LOGGER.debug("disconf reloadable file: {} , relativeFilePath : {}", fileName , relativePath);
}

} catch (Exception e) {

LOGGER.error(e.toString(), e);
}
}
}

/**
* @Description: 总关闭
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DisconfMgrBean implements BeanDefinitionRegistryPostProcessor, Prio

private ApplicationContext applicationContext;

private String scanPackage = null;
private String scanPackage = null;

public void destroy() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -59,14 +60,16 @@ public void setLocations(List<String> fileNames) {
filename = filename.trim();

String realFileName = getFileName(filename);
String relativeFilePath = getFileRelativePath(filename);

//
// register to disconf
//
DisconfMgr.getInstance().reloadableScan(realFileName);
DisconfMgr.getInstance().reloadableScan(realFileName,relativeFilePath);

//
// only properties will reload
// TODO 是否可以考虑支持多类型配置文件
//
String ext = FilenameUtils.getExtension(filename);
if (ext.equals("properties")) {
Expand Down Expand Up @@ -118,6 +121,30 @@ private String getFileName(String fileName) {
return null;
}

private String getFileRelativePath(String fileName){
if (fileName != null) {
int index = fileName.indexOf(':');
if (index < 0) {
return fileName;
} else {
fileName = fileName.substring(index + 1);
}
//配置文件应该使用相对路径,此操作避免读取系统绝对路径
if(fileName.startsWith("/")){
fileName = fileName.substring(1);
}
//判断是否包含目录
if(fileName.indexOf("/") > 0){
fileName = fileName.substring(0,fileName.lastIndexOf("/"));
}else{
return "";
}

return fileName;
}
return null;
}

protected Resource[] getLocations() {
return locations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public String getFileDir() {
if (targetDirPath.startsWith("/")) {
return OsUtil.pathJoin(targetDirPath);
}

LOGGER.info("Download target file path : {}" , OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), targetDirPath));
return OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), targetDirPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class DisconfAnyFileProcessorImpl implements DisconfFileTypeProcessor {
@Override
public Map<String, Object> getKvMap(String fileName) throws Exception {
// TODO Auto-generated method stub


return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void updateOneConfFile(String fileName, DisconfCenterFile disconfCenterF
}

//
// 注入到仓库中
// 注入到仓库中,Reload非注解形式bean属性值
//
disconfStoreProcessor.inject2Store(fileName, new DisconfValue(null, dataMap));
LOGGER.debug("inject ok.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public class FetcherMgrImpl implements FetcherMgr {
// 创建对象
//
public FetcherMgrImpl(RestfulMgr restfulMgr, int retryTime, int retrySleepSeconds,
boolean enableLocalDownloadDirInClassPath, String localDownloadDir, String
localDownloadDirTemp, List<String>
hostList) {
boolean enableLocalDownloadDirInClassPath, String localDownloadDir,
String localDownloadDirTemp, List<String> hostList) {

this.restfulMgr = restfulMgr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public interface ScanMgr {
* @throws Exception
*/
void reloadableScan(String fileName) throws Exception;

/**
* reloadable for non-annotation config file(eg: spring xml)
* @param fileName config file name
* @param relativePath relative path
* @throws Exception
*/
void reloadableScan(String fileName , String relativePath) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ public void reloadableScan(String fileName) throws Exception {
StaticScannerNonAnnotationFileMgrImpl.scanData2Store(fileName);
}

@Override
public void reloadableScan(String fileName, String relativePath) throws Exception {
StaticScannerNonAnnotationFileMgrImpl.scanData2Store(fileName,relativePath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void scanData2Store(ScanStaticModel scanModel) {
/**
*
*/
@Deprecated
public static void scanData2Store(String fileName) {

DisconfCenterBaseModel disconfCenterBaseModel =
Expand All @@ -45,6 +46,14 @@ public static void scanData2Store(String fileName) {
DisconfStoreProcessorFactory.getDisconfStoreFileProcessor().transformScanData(disconfCenterBaseModel);
}

public static void scanData2Store(String fileName, String relativePath) {

DisconfCenterBaseModel disconfCenterBaseModel =
StaticScannerNonAnnotationFileMgrImpl.getDisconfCenterFile(fileName,relativePath);

DisconfStoreProcessorFactory.getDisconfStoreFileProcessor().transformScanData(disconfCenterBaseModel);
}

/**
*
*/
Expand Down Expand Up @@ -104,4 +113,41 @@ public static DisconfCenterBaseModel getDisconfCenterFile(String fileName) {
return disconfCenterFile;
}

/**
*
*/
public static DisconfCenterBaseModel getDisconfCenterFile(String fileName , String relativePath) {

DisconfCenterFile disconfCenterFile = new DisconfCenterFile();

fileName = fileName.trim();

//
// file name
disconfCenterFile.setFileName(fileName);

// 非注解式
disconfCenterFile.setIsTaggedWithNonAnnotationFile(true);

// file type
disconfCenterFile.setSupportFileTypeEnum(SupportFileTypeEnum.getByFileName(fileName));
disconfCenterFile.setTargetDirPath(relativePath);

//
// disConfCommonModel
DisConfCommonModel disConfCommonModel = makeDisConfCommonModel("", "", "");
disconfCenterFile.setDisConfCommonModel(disConfCommonModel);

// Remote URL
String url = DisconfWebPathMgr.getRemoteUrlParameter(DisClientSysConfig.getInstance().CONF_SERVER_STORE_ACTION,
disConfCommonModel.getApp(),
disConfCommonModel.getVersion(),
disConfCommonModel.getEnv(),
disconfCenterFile.getFileName(),
DisConfigTypeEnum.FILE);
disconfCenterFile.setRemoteServerUrl(url);

return disconfCenterFile;
}

}
19 changes: 19 additions & 0 deletions disconf-client/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

log4j.rootLogger=INFO,dailyRolling,CONSOLE

log4j.logger.org.apache.zookeeper=WARN
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework.aop.framework.Cglib2AopProxy = INFO

log4j.appender.dailyRolling=org.apache.log4j.DailyRollingFileAppender
log4j.appender.dailyRolling.File=../log/disconf-client.log
log4j.appender.dailyRolling.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyRolling.layout.ConversionPattern=%d [%t] %-5p %-17c{2} (%13F:%L) %3x - %m%n

log4j.appender.Threshold=WARN
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %-17c{2} (%13F:%L) %3x - %m%n


50 changes: 0 additions & 50 deletions disconf-client/src/test/resources/logback.xml

This file was deleted.

Loading