diff --git a/disconf-client/src/main/java/com/baidu/disconf/client/common/annotations/DisconfFile.java b/disconf-client/src/main/java/com/baidu/disconf/client/common/annotations/DisconfFile.java index 99d044f13..d16099872 100644 --- a/disconf-client/src/main/java/com/baidu/disconf/client/common/annotations/DisconfFile.java +++ b/disconf-client/src/main/java/com/baidu/disconf/client/common/annotations/DisconfFile.java @@ -38,10 +38,10 @@ String app() default ""; /** - * 以"/"开头则是系统的全路径,否则则是相对于classpath的路径,默认是classpath根路径 + * 配置文件目标地址dir, 以"/"开头则是系统的全路径,否则则是相对于classpath的路径,默认是classpath根路径 * 注意:根路径要注意是否有权限,否则会出现找不到路径,推荐采用相对路径 * * @return */ - String copy2TargetDirPath() default ""; + String targetDirPath() default ""; } diff --git a/disconf-client/src/main/java/com/baidu/disconf/client/common/model/DisconfCenterFile.java b/disconf-client/src/main/java/com/baidu/disconf/client/common/model/DisconfCenterFile.java index 2d78a983e..64d846bd6 100644 --- a/disconf-client/src/main/java/com/baidu/disconf/client/common/model/DisconfCenterFile.java +++ b/disconf-client/src/main/java/com/baidu/disconf/client/common/model/DisconfCenterFile.java @@ -41,8 +41,8 @@ public class DisconfCenterFile extends DisconfCenterBaseModel { // 文件名 private String fileName; - // 复制到指定的路径下 - private String copy2TargetDirPath; + // 配置文件 指定路径下 + private String targetDirPath; // 文件类型 private SupportFileTypeEnum supportFileTypeEnum = SupportFileTypeEnum.ANY; @@ -95,18 +95,18 @@ public void setIsTaggedWithNonAnnotationFile(boolean isTaggedWithNonAnnotationFi this.isTaggedWithNonAnnotationFile = isTaggedWithNonAnnotationFile; } - public String getCopy2TargetDirPath() { - return copy2TargetDirPath; + public String getTargetDirPath() { + return targetDirPath; } - public void setCopy2TargetDirPath(String copy2TargetDirPath) { - this.copy2TargetDirPath = copy2TargetDirPath; + public void setTargetDirPath(String targetDirPath) { + this.targetDirPath = targetDirPath; } @Override public String toString() { return "\n\tDisconfCenterFile [\n\tkeyMaps=" + keyMaps + "\n\tcls=" + cls + "\n\tfileName=" + fileName - + "\n\tcopy2TargetDirPath=" + copy2TargetDirPath + + + "\n\ttargetDirPath=" + targetDirPath + super.toString() + "]"; } @@ -141,17 +141,19 @@ public Map getKV() { * 配置文件的路径 */ public String getFilePath() { + + // 不放到classpath, 则文件路径根据 userDefineDownloadDir 来设置 if (!DisClientConfig.getInstance().enableLocalDownloadDirInClassPath) { return OsUtil.pathJoin(DisClientConfig.getInstance().userDefineDownloadDir, fileName); } - if (copy2TargetDirPath != null) { + if (targetDirPath != null) { - if (copy2TargetDirPath.startsWith("/")) { - return OsUtil.pathJoin(copy2TargetDirPath, fileName); + if (targetDirPath.startsWith("/")) { + return OsUtil.pathJoin(targetDirPath, fileName); } - return OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), copy2TargetDirPath, fileName); + return OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), targetDirPath, fileName); } return OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), fileName); @@ -163,13 +165,13 @@ public String getFilePath() { public String getFileDir() { // 获取相对于classpath的路径 - if (copy2TargetDirPath != null) { + if (targetDirPath != null) { - if (copy2TargetDirPath.startsWith("/")) { - return OsUtil.pathJoin(copy2TargetDirPath); + if (targetDirPath.startsWith("/")) { + return OsUtil.pathJoin(targetDirPath); } - return OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), copy2TargetDirPath); + return OsUtil.pathJoin(ClassLoaderUtil.getClassPath(), targetDirPath); } return ClassLoaderUtil.getClassPath(); diff --git a/disconf-client/src/main/java/com/baidu/disconf/client/fetcher/FetcherMgr.java b/disconf-client/src/main/java/com/baidu/disconf/client/fetcher/FetcherMgr.java index 46abd6978..195ffabcf 100644 --- a/disconf-client/src/main/java/com/baidu/disconf/client/fetcher/FetcherMgr.java +++ b/disconf-client/src/main/java/com/baidu/disconf/client/fetcher/FetcherMgr.java @@ -14,11 +14,11 @@ public interface FetcherMgr { String getValueFromServer(String url) throws Exception; /** - * 下载配置文件, remoteUrl是目标 url, 下载到预定义的文件夹,并复制到classpath文件夹下 + * 下载配置文件, remoteUrl是目标 url, 下载到预定义的文件夹,并 下载到 targetDirPath 目录下 * * @throws Exception */ - String downloadFileFromServer(String url, String fileName, String copy2TargetDirPath) throws Exception; + String downloadFileFromServer(String url, String fileName, String targetDirPath) throws Exception; /** * 释放资源 diff --git a/disconf-client/src/main/java/com/baidu/disconf/client/scan/inner/statically/impl/StaticScannerFileMgrImpl.java b/disconf-client/src/main/java/com/baidu/disconf/client/scan/inner/statically/impl/StaticScannerFileMgrImpl.java index 6f9834ec2..f93b4078a 100644 --- a/disconf-client/src/main/java/com/baidu/disconf/client/scan/inner/statically/impl/StaticScannerFileMgrImpl.java +++ b/disconf-client/src/main/java/com/baidu/disconf/client/scan/inner/statically/impl/StaticScannerFileMgrImpl.java @@ -96,8 +96,8 @@ private static DisconfCenterFile transformScanFile(Class disconfFileClass, Se // file name disconfCenterFile.setFileName(disconfFileAnnotation.filename()); - // copy 2 target path - disconfCenterFile.setCopy2TargetDirPath(disconfFileAnnotation.copy2TargetDirPath().trim()); + // config file target dir path + disconfCenterFile.setTargetDirPath(disconfFileAnnotation.targetDirPath().trim()); // file type disconfCenterFile.setSupportFileTypeEnum(SupportFileTypeEnum.getByFileName(disconfFileAnnotation.filename())); diff --git a/disconf-client/src/test/java/com/baidu/disconf/client/test/fetcher/inner/restful/RestfulMgrMock.java b/disconf-client/src/test/java/com/baidu/disconf/client/test/fetcher/inner/restful/RestfulMgrMock.java index d2b1aa35f..b67b8c771 100644 --- a/disconf-client/src/test/java/com/baidu/disconf/client/test/fetcher/inner/restful/RestfulMgrMock.java +++ b/disconf-client/src/test/java/com/baidu/disconf/client/test/fetcher/inner/restful/RestfulMgrMock.java @@ -60,7 +60,7 @@ public T getJsonData(Class clazz, RemoteUrl remoteUrl, int retryTimes, in */ @Mock public String downloadFromServer(RemoteUrl remoteUrl, String fileName, String localFileDir, String localFileDirTemp, - String copy2TargetDirPath, boolean download2Classpath, int retryTimes, + String targetDirPath, boolean download2Classpath, int retryTimes, int retrySleepSeconds) throws Exception { diff --git a/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/RestfulMgr.java b/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/RestfulMgr.java index 92ceb91d2..7389dbf75 100644 --- a/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/RestfulMgr.java +++ b/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/RestfulMgr.java @@ -23,17 +23,17 @@ public interface RestfulMgr { T getJsonData(Class clazz, RemoteUrl remoteUrl, int retryTimes, int retrySleepSeconds) throws Exception; /** - * @param remoteUrl 远程地址 - * @param fileName 文件名 - * @param localFileDir 本地文件地址 - * @param copy2TargetDirPath 下载完后,还需要复制到此文件夹下 + * @param remoteUrl 远程地址 + * @param fileName 文件名 + * @param localFileDir 本地文件地址 + * @param targetDirPath 下载完后,配置文件放到此目录下 * * @return 如果是放到Classpath目录下,则返回相对Classpath的路径,如果不是,则返回全路径 * * @throws Exception */ String downloadFromServer(RemoteUrl remoteUrl, String fileName, String localFileDir, String localFileDirTemp, - String copy2TargetDirPath, + String targetDirPath, boolean enableLocalDownloadDirInClassPath, int retryTimes, int retrySleepSeconds) throws Exception; diff --git a/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/impl/RestfulMgrImpl.java b/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/impl/RestfulMgrImpl.java index 63ec929e5..00212dd3a 100644 --- a/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/impl/RestfulMgrImpl.java +++ b/disconf-core/src/main/java/com/baidu/disconf/core/common/restful/impl/RestfulMgrImpl.java @@ -76,10 +76,10 @@ public T getJsonData(Class clazz, RemoteUrl remoteUrl, int retryTimes, in } /** - * @param remoteUrl 远程地址 - * @param fileName 文件名 - * @param localFileDir 本地文件地址 - * @param copy2TargetDirPath 下载完后,还需要复制到此文件夹下 + * @param remoteUrl 远程地址 + * @param fileName 文件名 + * @param localFileDir 本地文件地址 + * @param targetDirPath 下载完后,配置文件指定的文件目录 * @param retryTimes * @param retrySleepSeconds * @@ -89,7 +89,7 @@ public T getJsonData(Class clazz, RemoteUrl remoteUrl, int retryTimes, in */ @Override public String downloadFromServer(RemoteUrl remoteUrl, String fileName, String localFileDir, String localFileDirTemp, - String copy2TargetDirPath, boolean enableLocalDownloadDirInClassPath, + String targetDirPath, boolean enableLocalDownloadDirInClassPath, int retryTimes, int retrySleepSeconds) throws Exception { @@ -110,12 +110,12 @@ public String downloadFromServer(RemoteUrl remoteUrl, String fileName, String lo localFile = transfer2SpecifyDir(tmpFilePathUniqueFile, localFileDir, fileName, false); // mv 到指定目录 - if (copy2TargetDirPath != null) { + if (targetDirPath != null) { // - if (enableLocalDownloadDirInClassPath || !copy2TargetDirPath.equals(ClassLoaderUtil.getClassPath + if (enableLocalDownloadDirInClassPath || !targetDirPath.equals(ClassLoaderUtil.getClassPath ())) { - localFile = transfer2SpecifyDir(tmpFilePathUniqueFile, copy2TargetDirPath, fileName, true); + localFile = transfer2SpecifyDir(tmpFilePathUniqueFile, targetDirPath, fileName, true); } } @@ -129,7 +129,7 @@ public String downloadFromServer(RemoteUrl remoteUrl, String fileName, String lo // // 判断是否下载失败 // - + if (localFile == null || !localFile.exists()) { throw new Exception("target file cannot be found! " + fileName); } @@ -184,20 +184,20 @@ private File retryDownload(String localFileDirTemp, String fileName, RemoteUrl r * copy/mv 到指定目录 * * @param srcFile - * @param copy2TargetDirPath + * @param targetDirPath * @param fileName * * @return * * @throws Exception */ - private File transfer2SpecifyDir(File srcFile, String copy2TargetDirPath, String fileName, + private File transfer2SpecifyDir(File srcFile, String targetDirPath, String fileName, boolean isMove) throws Exception { // make dir - OsUtil.makeDirs(copy2TargetDirPath); + OsUtil.makeDirs(targetDirPath); - File targetPath = new File(OsUtil.pathJoin(copy2TargetDirPath, fileName)); + File targetPath = new File(OsUtil.pathJoin(targetDirPath, fileName)); // 从下载文件 复制/mv 到targetPath 原子性的做转移 OsUtil.transferFileAtom(srcFile, targetPath, isMove); return targetPath; diff --git a/disconf-web/profile/rd/zoo.properties b/disconf-web/profile/rd/zoo.properties index 35b788f27..4ba077c79 100644 --- a/disconf-web/profile/rd/zoo.properties +++ b/disconf-web/profile/rd/zoo.properties @@ -1,5 +1,5 @@ -hosts=10.128.21.89:8581,10.128.21.89:8582,10.128.21.89:8583 +hosts=127.0.0.1:8581,127.0.0.1:8582,127.0.0.1:8583 # zookeeper\u7684\u524D\u7F00\u8DEF\u5F84\u540D zookeeper_url_prefix=/disconf \ No newline at end of file diff --git a/docs/source/others/update.md b/docs/source/others/update.md index d4d85b362..1d3efd06b 100644 --- a/docs/source/others/update.md +++ b/docs/source/others/update.md @@ -8,4 +8,5 @@ - disconf-client: - 支持https的web端 https://github.com/knightliao/disconf/issues/158 - path支持windows: https://github.com/knightliao/disconf/issues/166 - - 删除类 DisconfMgrJustHostFileBean \ No newline at end of file + - 删除类 DisconfMgrJustHostFileBean + - DisconfFile 的属性 copy2TargetDirPath 更改为 targetDirPath \ No newline at end of file diff --git a/docs/source/tutorial-client/Tutorial11-config-download-path.md b/docs/source/tutorial-client/Tutorial11-config-download-path.md index d5601ae16..2d0e866de 100644 --- a/docs/source/tutorial-client/Tutorial11-config-download-path.md +++ b/docs/source/tutorial-client/Tutorial11-config-download-path.md @@ -5,17 +5,27 @@ Tutorial 11 配置文件下载地址讨论 ### 解决:按以下顺序进行判断 -- 一定会下载到 disconf.user_define_download_dir 目录下(使用此方法可以方便的构造一个下载器 [Tutorial10](Tutorial10.html) ) +对于注解式配置文件: + +- 一定会下载到 disconf.user_define_download_dir 目录下(使用此方法可以方便的构造一个下载器. [Tutorial10](Tutorial10.html) ) +- 如果 disconf.enable_local_download_dir_in_class_path 为true(默认值), 则会执行以下判断: + - 如果 @DisconfFile 的 targetDirPath 值不为空, 则会下载到 targetDirPath 这个目录下, 配置数据从该路径读取。这对于那些不想放在classpath根目录的程序, 比较有用. + - 如果 @DisconfFile 的 targetDirPath 值为空, 则会下载到classpath路径下, 配置数据从该路径读取. +- 如果 disconf.enable_local_download_dir_in_class_path 为false, 则不会下载到classpath目录下. 配置数据从 disconf.user_define_download_dir 读取 + +对于XML式配置文件: + +- 一定会下载到 disconf.user_define_download_dir 目录下(使用此方法可以方便的构造一个下载器). - 如果 disconf.enable_local_download_dir_in_class_path 为true(默认值), 则会执行以下判断: - - 如果 @DisconfFile 的 copy2TargetDirPath 值不为空,则会下载这个目录下。(copy2TargetDirPath值说明:以"/"开头则是系统的全路径,否则则是相对于classpath的路径,默认是classpath根路径 - 注意:根路径要注意是否有权限,否则会出现找不到路径,推荐采用相对路径)。这对于那些不想放在classpath根目录的程序,比较有用。 - - 如果 @DisconfFile 的 copy2TargetDirPath 值为空,则会下载到根路径下。大部分程序是从根目录读取配置的,因此,默认是放到根下。 -- 如果 disconf.enable_local_download_dir_in_class_path 为false, 则不会下载到classpath目录下 + - 如果 @DisconfFile 的 targetDirPath 值不为空, 则会下载到 targetDirPath 这个目录下. + - 如果 @DisconfFile 的 targetDirPath 值为空, 则会下载到classpath路径下. +- 如果 disconf.enable_local_download_dir_in_class_path 为false, 则不会下载到classpath目录下. 注: 1. 如果不作任何配置的改变,默认情况下,会下载到 disconf.user_define_download_dir 目录 和 classpath 两个目录下。 -2. 配置说明看这里 [config](../../config/client-config.html) +2. targetDirPath 值说明:以"/"开头则是系统的全路径,否则则是相对于classpath的路径,默认是classpath根路径。注意:根路径要注意是否有权限,否则会出现找不到路径,推荐采用相对路径。 +3. 配置说明看这里 [config](../../config/client-config.html) ### 问题二 不想下载到classpath目录下