├── .svn ├── format ├── entries ├── wc.db └── pristine │ └── 1f │ └── 1fdfc96a9a9e36369b5aa86db820145500e04379.svn-base ├── README.md ├── jobManager-core ├── .svn │ ├── entries │ ├── format │ ├── wc.db │ └── pristine │ │ ├── 50 │ │ └── 5096c57bcc1c112f04fd616820903e9b0090619b.svn-base │ │ ├── 59 │ │ └── 59bfe67cf59eb806e1a83adc89ac7c5dbd59e423.svn-base │ │ ├── 63 │ │ └── 639a0c57d90ac3bae8f3db2313fbef989a922ffd.svn-base │ │ ├── 73 │ │ └── 73d2a9c6e98645eaa65e57a5cb672bcd1c14ee93.svn-base │ │ ├── fd │ │ └── fd0c8983a319e9487cf8864f0fc39c37ed611484.svn-base │ │ ├── b5 │ │ └── b5343da1f11358e4c40633fb88a723aeaeea8da1.svn-base │ │ ├── 7f │ │ └── 7fc5cdf245634fc919f3c66c252def14f4e7d719.svn-base │ │ ├── 2b │ │ └── 2b0fb822118d590a8b17bd4cd7f3606364d106a6.svn-base │ │ ├── b1 │ │ └── b1e21ca54d7a8a5666a35e35aaf6bf8d917c0a7c.svn-base │ │ ├── 00 │ │ └── 008d7529df3da45a3254d6e9ad8e020ed0ffe186.svn-base │ │ └── ad │ │ └── ad92a2f826f08cd367350ece5320a670a115ff8d.svn-base ├── src │ └── main │ │ ├── pluginLib │ │ └── mysqlJobManager.jar │ │ ├── conf │ │ └── core.json │ │ └── java │ │ └── com │ │ └── cug │ │ └── intellM │ │ └── jobManager │ │ ├── plugin │ │ ├── Pluginable.java │ │ ├── JobManager.java │ │ └── AbstractPlugin.java │ │ ├── driver │ │ └── CliDriver.java │ │ ├── core │ │ └── PluginLoader.java │ │ └── util │ │ ├── PluginUtils.java │ │ └── Configuration.java ├── jobManager-core.iml └── pom.xml ├── mongoDBJobManager ├── .svn │ ├── entries │ ├── format │ ├── wc.db │ └── pristine │ │ ├── 72 │ │ └── 7226427002af5cc2382c9c3e9f00800a935523b6.svn-base │ │ ├── 5c │ │ └── 5ce20d09b5e93ee5f764ec5d7d732256acad5545.svn-base │ │ └── b5 │ │ └── b53bdd62f819d5499e0f30b9ed4a4e8db054f02b.svn-base ├── src │ └── main │ │ └── java │ │ └── com │ │ └── cug │ │ └── intellM │ │ └── jobManager │ │ └── mongoDBJobManager │ │ └── MongoDBJobManager.java ├── pom.xml └── mongoDBJobManager.iml ├── mysqlJobManager ├── .svn │ ├── entries │ ├── format │ ├── wc.db │ └── pristine │ │ ├── 67 │ │ └── 67ada89de2fbe97cce62befdd8a6dca271c52762.svn-base │ │ ├── 04 │ │ └── 048de174ab400210db3d23a5df26f160d2728cfa.svn-base │ │ └── 3e │ │ └── 3e4617707662436bb79f3a58f09768e92012557f.svn-base ├── src │ └── main │ │ └── java │ │ └── com │ │ └── cug │ │ └── intellM │ │ └── jobManager │ │ └── mysqlJobManager │ │ └── MysqlJobManager.java ├── pom.xml └── mysqlJobManager.iml ├── .idea ├── copyright │ └── profiles_settings.xml ├── vcs.xml ├── libraries │ ├── Maven__commons_io_commons_io_2_4.xml │ ├── Maven__com_alibaba_fastjson_1_2_38.xml │ └── Maven__org_apache_commons_commons_lang3_3_4.xml ├── modules.xml ├── misc.xml ├── compiler.xml ├── uiDesigner.xml └── workspace.xml ├── .gitattributes ├── pom.xml ├── .gitignore └── jobManager.iml /.svn/format: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /.svn/entries: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 利用Java反射实现插件框架 2 | -------------------------------------------------------------------------------- /jobManager-core/.svn/entries: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /jobManager-core/.svn/format: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /mongoDBJobManager/.svn/entries: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /mongoDBJobManager/.svn/format: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /mysqlJobManager/.svn/entries: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /mysqlJobManager/.svn/format: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /.svn/wc.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windwinds/jobManager/HEAD/.svn/wc.db -------------------------------------------------------------------------------- /jobManager-core/.svn/wc.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windwinds/jobManager/HEAD/jobManager-core/.svn/wc.db -------------------------------------------------------------------------------- /mysqlJobManager/.svn/wc.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windwinds/jobManager/HEAD/mysqlJobManager/.svn/wc.db -------------------------------------------------------------------------------- /mongoDBJobManager/.svn/wc.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windwinds/jobManager/HEAD/mongoDBJobManager/.svn/wc.db -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /jobManager-core/src/main/pluginLib/mysqlJobManager.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windwinds/jobManager/HEAD/jobManager-core/src/main/pluginLib/mysqlJobManager.jar -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/73/73d2a9c6e98645eaa65e57a5cb672bcd1c14ee93.svn-base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windwinds/jobManager/HEAD/jobManager-core/.svn/pristine/73/73d2a9c6e98645eaa65e57a5cb672bcd1c14ee93.svn-base -------------------------------------------------------------------------------- /jobManager-core/src/main/conf/core.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins":[ 3 | { 4 | "pluginName":"mysqlJobManager", 5 | "pluginClass":"com.cug.intellM.jobManager.mysqlJobManager.MysqlJobManager" 6 | } 7 | ] 8 | } -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/fd/fd0c8983a319e9487cf8864f0fc39c37ed611484.svn-base: -------------------------------------------------------------------------------- 1 | { 2 | "plugins":[ 3 | { 4 | "pluginName":"mysqlJobManager", 5 | "pluginClass":"com.cug.intellM.jobManager.mysqlJobManager.MysqlJobManager" 6 | } 7 | ] 8 | } -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/plugin/Pluginable.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.plugin; 2 | 3 | /** 4 | * Created by lyc on 2017/9/30. 5 | */ 6 | public interface Pluginable { 7 | public String getPluginName(); 8 | public void setPluginName(String pluginName); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/b5/b5343da1f11358e4c40633fb88a723aeaeea8da1.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.plugin; 2 | 3 | /** 4 | * Created by lyc on 2017/9/30. 5 | */ 6 | public interface Pluginable { 7 | public String getPluginName(); 8 | public void setPluginName(String pluginName); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/59/59bfe67cf59eb806e1a83adc89ac7c5dbd59e423.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.plugin; 2 | 3 | /** 4 | * Created by lyc on 2017/9/30. 5 | */ 6 | public abstract class JobManager extends AbstractPlugin{ 7 | 8 | public abstract void prepare(); 9 | 10 | public abstract void check(); 11 | 12 | public abstract void transformRule(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/plugin/JobManager.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.plugin; 2 | 3 | /** 4 | * Created by lyc on 2017/9/30. 5 | */ 6 | public abstract class JobManager extends AbstractPlugin{ 7 | 8 | public abstract void prepare(); 9 | 10 | public abstract void check(); 11 | 12 | public abstract void transformRule(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/7f/7fc5cdf245634fc919f3c66c252def14f4e7d719.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.plugin; 2 | 3 | /** 4 | * Created by lyc on 2017/9/30. 5 | */ 6 | //抽象类可以有抽象方法,不能被实例化,抽象方法不能有方法体,只能在子类中实现 7 | public abstract class AbstractPlugin implements Pluginable{ 8 | 9 | private String pluginName; 10 | 11 | public String getPluginName() { 12 | return pluginName; 13 | } 14 | 15 | public void setPluginName(String pluginName) { 16 | this.pluginName = pluginName; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/plugin/AbstractPlugin.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.plugin; 2 | 3 | /** 4 | * Created by lyc on 2017/9/30. 5 | */ 6 | //抽象类可以有抽象方法,不能被实例化,抽象方法不能有方法体,只能在子类中实现 7 | public abstract class AbstractPlugin implements Pluginable{ 8 | 9 | private String pluginName; 10 | 11 | public String getPluginName() { 12 | return pluginName; 13 | } 14 | 15 | public void setPluginName(String pluginName) { 16 | this.pluginName = pluginName; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_io_commons_io_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_fastjson_1_2_38.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /mongoDBJobManager/.svn/pristine/72/7226427002af5cc2382c9c3e9f00800a935523b6.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.mongoDBJobManager; 2 | 3 | import com.cug.intellM.jobManager.plugin.JobManager; 4 | 5 | /** 6 | * Created by lyc on 2017/10/10. 7 | */ 8 | public class MongoDBJobManager extends JobManager { 9 | 10 | public void prepare() { 11 | System.out.println("连接MongoDB数据库"); 12 | } 13 | 14 | public void check() { 15 | System.out.println("检查MongoDB数据库表、字段,没有则创建"); 16 | } 17 | 18 | public void transformRule() { 19 | System.out.println("将清洗条件转换为MongoDB"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mongoDBJobManager/src/main/java/com/cug/intellM/jobManager/mongoDBJobManager/MongoDBJobManager.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.mongoDBJobManager; 2 | 3 | import com.cug.intellM.jobManager.plugin.JobManager; 4 | 5 | /** 6 | * Created by lyc on 2017/10/10. 7 | */ 8 | public class MongoDBJobManager extends JobManager { 9 | 10 | public void prepare() { 11 | System.out.println("连接MongoDB数据库"); 12 | } 13 | 14 | public void check() { 15 | System.out.println("检查MongoDB数据库表、字段,没有则创建"); 16 | } 17 | 18 | public void transformRule() { 19 | System.out.println("将清洗条件转换为MongoDB"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_lang3_3_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /mysqlJobManager/.svn/pristine/04/048de174ab400210db3d23a5df26f160d2728cfa.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.mysqlJobManager; 2 | 3 | import com.cug.intellM.jobManager.plugin.JobManager; 4 | 5 | /** 6 | * Created by lyc on 2017/9/30. 7 | */ 8 | 9 | //包外继承抽象类,抽象类的抽象方法必须声明为public,否则子类无法实现抽象方法 10 | public class MysqlJobManager extends JobManager{ 11 | 12 | public void prepare(){ 13 | System.out.println("连接Mysql数据库"); 14 | } 15 | 16 | public void check(){ 17 | System.out.println("检查Mysql数据库表、字段,没有则创建"); 18 | } 19 | 20 | public void transformRule(){ 21 | System.out.println("将清洗条件转换为sql"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /mysqlJobManager/src/main/java/com/cug/intellM/jobManager/mysqlJobManager/MysqlJobManager.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.mysqlJobManager; 2 | 3 | import com.cug.intellM.jobManager.plugin.JobManager; 4 | 5 | /** 6 | * Created by lyc on 2017/9/30. 7 | */ 8 | 9 | //包外继承抽象类,抽象类的抽象方法必须声明为public,否则子类无法实现抽象方法 10 | public class MysqlJobManager extends JobManager{ 11 | 12 | public void prepare(){ 13 | System.out.println("连接Mysql数据库"); 14 | } 15 | 16 | public void check(){ 17 | System.out.println("检查Mysql数据库表、字段,没有则创建"); 18 | } 19 | 20 | public void transformRule(){ 21 | System.out.println("将清洗条件转换为sql"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cug.intellM.jobManager 8 | jobManager 9 | 1.0-SNAPSHOT 10 | 11 | jobManager-core 12 | mysqlJobManager 13 | mongoDBJobManager 14 | 15 | pom 16 | 17 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.svn/pristine/1f/1fdfc96a9a9e36369b5aa86db820145500e04379.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cug.intellM.jobManager 8 | jobManager 9 | 1.0-SNAPSHOT 10 | 11 | jobManager-core 12 | mysqlJobManager 13 | mongoDBJobManager 14 | 15 | pom 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /mongoDBJobManager/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jobManager 7 | com.cug.intellM.jobManager 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mongoDBJobManager 13 | 14 | 15 | com.cug.intellM.jobManager 16 | jobManager-core 17 | 1.0-SNAPSHOT 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /mysqlJobManager/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jobManager 7 | com.cug.intellM.jobManager 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mysqlJobManager 13 | jar 14 | 15 | 16 | 17 | com.cug.intellM.jobManager 18 | jobManager-core 19 | ${project.version} 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /jobManager.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /mongoDBJobManager/.svn/pristine/5c/5ce20d09b5e93ee5f764ec5d7d732256acad5545.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jobManager 7 | com.cug.intellM.jobManager 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mongoDBJobManager 13 | 14 | 15 | com.cug.intellM.jobManager 16 | jobManager-core 17 | 1.0-SNAPSHOT 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /mysqlJobManager/.svn/pristine/67/67ada89de2fbe97cce62befdd8a6dca271c52762.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jobManager 7 | com.cug.intellM.jobManager 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mysqlJobManager 13 | jar 14 | 15 | 16 | 17 | com.cug.intellM.jobManager 18 | jobManager-core 19 | ${project.version} 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/driver/CliDriver.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.driver; 2 | 3 | import com.cug.intellM.jobManager.core.PluginLoader; 4 | import com.cug.intellM.jobManager.plugin.JobManager; 5 | import com.cug.intellM.jobManager.util.PluginUtils; 6 | 7 | import java.net.MalformedURLException; 8 | 9 | /** 10 | * Created by lyc on 2017/9/30. 11 | * 程序入口 12 | */ 13 | public class CliDriver { 14 | 15 | public static void main(String[] args) throws Exception { 16 | 17 | if (args.length < 1){ 18 | System.out.println("缺少参数插件名称"); 19 | System.exit(-1); 20 | } 21 | 22 | String pluginName = args[0]; 23 | String pluginClassName = PluginLoader.getPluginClassName(pluginName); 24 | 25 | Class cls = PluginUtils.loadClass(pluginName, pluginClassName); 26 | 27 | JobManager jobManager = (JobManager)cls.newInstance(); 28 | 29 | jobManager.prepare(); 30 | jobManager.check(); 31 | jobManager.transformRule(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/2b/2b0fb822118d590a8b17bd4cd7f3606364d106a6.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.driver; 2 | 3 | import com.cug.intellM.jobManager.core.PluginLoader; 4 | import com.cug.intellM.jobManager.plugin.JobManager; 5 | import com.cug.intellM.jobManager.util.PluginUtils; 6 | 7 | import java.net.MalformedURLException; 8 | 9 | /** 10 | * Created by lyc on 2017/9/30. 11 | * 程序入口 12 | */ 13 | public class CliDriver { 14 | 15 | public static void main(String[] args) throws Exception { 16 | 17 | if (args.length < 1){ 18 | System.out.println("缺少参数插件名称"); 19 | System.exit(-1); 20 | } 21 | 22 | String pluginName = args[0]; 23 | String pluginClassName = PluginLoader.getPluginClassName(pluginName); 24 | 25 | Class cls = PluginUtils.loadClass(pluginName, pluginClassName); 26 | 27 | JobManager jobManager = (JobManager)cls.newInstance(); 28 | 29 | jobManager.prepare(); 30 | jobManager.check(); 31 | jobManager.transformRule(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jobManager-core/jobManager-core.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/63/639a0c57d90ac3bae8f3db2313fbef989a922ffd.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /mongoDBJobManager/mongoDBJobManager.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /mongoDBJobManager/.svn/pristine/b5/b53bdd62f819d5499e0f30b9ed4a4e8db054f02b.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /mysqlJobManager/mysqlJobManager.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /mysqlJobManager/.svn/pristine/3e/3e4617707662436bb79f3a58f09768e92012557f.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 38 | 40 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /jobManager-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jobManager 7 | com.cug.intellM.jobManager 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jobManager-core 13 | 14 | 15 | 16 | org.apache.commons 17 | commons-lang3 18 | 3.4 19 | 20 | 21 | 22 | commons-io 23 | commons-io 24 | 2.4 25 | 26 | 27 | 28 | com.alibaba 29 | fastjson 30 | 1.2.38 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | maven-assembly-plugin 39 | 40 | 41 | jar-with-dependencies 42 | 43 | 44 | 45 | com.cug.intellM.jobManager.driver.CliDriver 46 | 47 | 48 | 49 | 50 | 51 | make-assembly 52 | package 53 | 54 | single 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/50/5096c57bcc1c112f04fd616820903e9b0090619b.svn-base: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jobManager 7 | com.cug.intellM.jobManager 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jobManager-core 13 | 14 | 15 | 16 | org.apache.commons 17 | commons-lang3 18 | 3.4 19 | 20 | 21 | 22 | commons-io 23 | commons-io 24 | 2.4 25 | 26 | 27 | 28 | com.alibaba 29 | fastjson 30 | 1.2.38 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | maven-assembly-plugin 39 | 40 | 41 | jar-with-dependencies 42 | 43 | 44 | 45 | com.cug.intellM.jobManager.driver.CliDriver 46 | 47 | 48 | 49 | 50 | 51 | make-assembly 52 | package 53 | 54 | single 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/b1/b1e21ca54d7a8a5666a35e35aaf6bf8d917c0a7c.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.core; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.cug.intellM.jobManager.util.Configuration; 6 | 7 | import java.io.File; 8 | import java.io.UnsupportedEncodingException; 9 | import java.net.URLDecoder; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * Created by lyc on 2017/9/30. 15 | */ 16 | 17 | //读取配置文件,加载插件配置信息 18 | public class PluginLoader { 19 | 20 | public static final String PLUGIN_JSON = "core.json"; 21 | //public static final String FILE_SEPARATOR = File.separator; 22 | private static Map pluginMap; 23 | 24 | public static String getPluginClassName(String name){ 25 | if (!pluginMap.containsKey(name)){ 26 | throw new RuntimeException("该插件不存在,请仔细核对插件配置文件"); 27 | } 28 | return pluginMap.get(name); 29 | } 30 | 31 | static { 32 | pluginMap = new HashMap(); 33 | String confPath = getConfPath(); 34 | File coreFile = new File(confPath); 35 | Configuration conf = Configuration.from(coreFile); 36 | JSONArray ls = (JSONArray)conf.get("plugins"); 37 | //将所有的插件信息存入pluginMap中 38 | for (Object o : ls){ 39 | JSONObject json = (JSONObject)o; 40 | String pluginName = json.getString("pluginName"); 41 | String pluginClass = json.getString("pluginClass"); 42 | pluginMap.put(pluginName, pluginClass); 43 | } 44 | System.out.println(conf.get("plugins")); 45 | } 46 | 47 | //得到插件的配置文件完整的路径 48 | private static String getConfPath(){ 49 | String dir = PluginLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(); 50 | try { 51 | dir=URLDecoder.decode(dir,"utf-8");//转化成utf-8编码 52 | } catch (UnsupportedEncodingException e) { 53 | // TODO Auto-generated catch block 54 | e.printStackTrace(); 55 | } 56 | 57 | int num; 58 | //通过jar运行时路径的路径处理 59 | if ("jar".equals(dir.substring(dir.length()-3))){ 60 | num = 2; 61 | }else{ 62 | num = 3; 63 | } 64 | for (int i=0; i < num; i++){ 65 | dir = dir.substring(0,dir.lastIndexOf('/')); 66 | } 67 | 68 | System.out.println(dir+"/"+"src"+"/"+"main"+"/"+"conf"); 69 | String confDir = dir+"/"+"src/"+"main/"+"conf/" + "/" + PLUGIN_JSON; 70 | return confDir; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/core/PluginLoader.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.core; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.cug.intellM.jobManager.util.Configuration; 6 | 7 | import java.io.File; 8 | import java.io.UnsupportedEncodingException; 9 | import java.net.URLDecoder; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * Created by lyc on 2017/9/30. 15 | */ 16 | 17 | //读取配置文件,加载插件配置信息 18 | public class PluginLoader { 19 | 20 | public static final String PLUGIN_JSON = "core.json"; 21 | //public static final String FILE_SEPARATOR = File.separator; 22 | private static Map pluginMap; 23 | 24 | public static String getPluginClassName(String name){ 25 | if (!pluginMap.containsKey(name)){ 26 | throw new RuntimeException("该插件不存在,请仔细核对插件配置文件"); 27 | } 28 | return pluginMap.get(name); 29 | } 30 | 31 | static { 32 | pluginMap = new HashMap(); 33 | String confPath = getConfPath(); 34 | File coreFile = new File(confPath); 35 | Configuration conf = Configuration.from(coreFile); 36 | JSONArray ls = (JSONArray)conf.get("plugins"); 37 | //将所有的插件信息存入pluginMap中 38 | for (Object o : ls){ 39 | JSONObject json = (JSONObject)o; 40 | String pluginName = json.getString("pluginName"); 41 | String pluginClass = json.getString("pluginClass"); 42 | pluginMap.put(pluginName, pluginClass); 43 | } 44 | System.out.println(conf.get("plugins")); 45 | } 46 | 47 | //得到插件的配置文件完整的路径 48 | private static String getConfPath(){ 49 | String dir = PluginLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(); 50 | try { 51 | dir=URLDecoder.decode(dir,"utf-8");//转化成utf-8编码 52 | } catch (UnsupportedEncodingException e) { 53 | // TODO Auto-generated catch block 54 | e.printStackTrace(); 55 | } 56 | 57 | int num; 58 | //通过jar运行时路径的路径处理 59 | if ("jar".equals(dir.substring(dir.length()-3))){ 60 | num = 2; 61 | }else{ 62 | num = 3; 63 | } 64 | for (int i=0; i < num; i++){ 65 | dir = dir.substring(0,dir.lastIndexOf('/')); 66 | } 67 | 68 | System.out.println(dir+"/"+"src"+"/"+"main"+"/"+"conf"); 69 | String confDir = dir+"/"+"src/"+"main/"+"conf/" + "/" + PLUGIN_JSON; 70 | return confDir; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/util/PluginUtils.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.util; 2 | 3 | import com.cug.intellM.jobManager.core.PluginLoader; 4 | 5 | import java.io.File; 6 | import java.io.UnsupportedEncodingException; 7 | import java.lang.reflect.Method; 8 | import java.net.URL; 9 | import java.net.URLClassLoader; 10 | import java.net.URLDecoder; 11 | import java.net.MalformedURLException; 12 | import java.util.Map; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | 16 | /** 17 | * Created by lyc on 2017/9/30. 18 | * 根据插件信息,通过反射得到插件类的对象 19 | */ 20 | public class PluginUtils { 21 | 22 | //线程安全的hashMap 23 | private static Map cache = new ConcurrentHashMap(); 24 | 25 | //通过插件名称得到该插件的jar的URL 26 | private static URL listFileByPluginName(String pluginName) throws MalformedURLException { 27 | 28 | String dir = PluginLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(); 29 | try { 30 | dir= URLDecoder.decode(dir,"utf-8");//转化成utf-8编码 31 | } catch (UnsupportedEncodingException e) { 32 | // TODO Auto-generated catch block 33 | e.printStackTrace(); 34 | } 35 | int num; 36 | //通过jar运行时路径的路径处理 37 | if ("jar".equals(dir.substring(dir.length()-3))){ 38 | num = 2; 39 | }else{ 40 | num = 3; 41 | } 42 | for (int i=0; i < num; i++){ 43 | dir = dir.substring(0,dir.lastIndexOf('/')); 44 | } 45 | String confDir = dir+"/"+"src/"+"main/"+"pluginLib/" + "/" + pluginName + ".jar"; 46 | File jar = new File(confDir); 47 | if (!jar.exists()) { 48 | throw new RuntimeException("Plugin not found: " + pluginName); 49 | } 50 | URL url = jar.toURI().toURL(); 51 | return url; 52 | } 53 | 54 | //通过插件名称和类名反射得到java类加载器 55 | public static Class loadClass(String pluginName, String className) throws ClassNotFoundException, MalformedURLException { 56 | URL url = listFileByPluginName(pluginName); 57 | ClassLoader classLoader = cache.get(pluginName); 58 | if (classLoader == null) { 59 | classLoader = new URLClassLoader(new URL[]{url}); 60 | cache.put(pluginName, classLoader); 61 | } 62 | return classLoader.loadClass(className); 63 | } 64 | 65 | public static Class loadClass2(String pluginName, String className) throws Exception { 66 | URL url = listFileByPluginName(pluginName); 67 | 68 | //得到系统类加载器 69 | URLClassLoader urlClassLoader= (URLClassLoader) ClassLoader.getSystemClassLoader(); 70 | //因为URLClassLoader中的addURL方法的权限为protected所以只能采用反射的方法调用addURL方法 71 | Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); 72 | add.setAccessible(true); 73 | add.invoke(urlClassLoader, new Object[] {url}); 74 | Class c =Class.forName(className); 75 | return c; 76 | } 77 | 78 | public static void main(String [] args)throws ClassNotFoundException, MalformedURLException{ 79 | listFileByPluginName("mysqlJobManager"); 80 | 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/00/008d7529df3da45a3254d6e9ad8e020ed0ffe186.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.util; 2 | 3 | import com.cug.intellM.jobManager.core.PluginLoader; 4 | 5 | import java.io.File; 6 | import java.io.UnsupportedEncodingException; 7 | import java.lang.reflect.Method; 8 | import java.net.URL; 9 | import java.net.URLClassLoader; 10 | import java.net.URLDecoder; 11 | import java.net.MalformedURLException; 12 | import java.util.Map; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | 16 | /** 17 | * Created by lyc on 2017/9/30. 18 | * 根据插件信息,通过反射得到插件类的对象 19 | */ 20 | public class PluginUtils { 21 | 22 | //线程安全的hashMap 23 | private static Map cache = new ConcurrentHashMap(); 24 | 25 | //通过插件名称得到该插件的jar的URL 26 | private static URL listFileByPluginName(String pluginName) throws MalformedURLException { 27 | 28 | String dir = PluginLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(); 29 | try { 30 | dir= URLDecoder.decode(dir,"utf-8");//转化成utf-8编码 31 | } catch (UnsupportedEncodingException e) { 32 | // TODO Auto-generated catch block 33 | e.printStackTrace(); 34 | } 35 | int num; 36 | //通过jar运行时路径的路径处理 37 | if ("jar".equals(dir.substring(dir.length()-3))){ 38 | num = 2; 39 | }else{ 40 | num = 3; 41 | } 42 | for (int i=0; i < num; i++){ 43 | dir = dir.substring(0,dir.lastIndexOf('/')); 44 | } 45 | String confDir = dir+"/"+"src/"+"main/"+"pluginLib/" + "/" + pluginName + ".jar"; 46 | File jar = new File(confDir); 47 | if (!jar.exists()) { 48 | throw new RuntimeException("Plugin not found: " + pluginName); 49 | } 50 | URL url = jar.toURI().toURL(); 51 | return url; 52 | } 53 | 54 | //通过插件名称和类名反射得到java类加载器 55 | public static Class loadClass(String pluginName, String className) throws ClassNotFoundException, MalformedURLException { 56 | URL url = listFileByPluginName(pluginName); 57 | ClassLoader classLoader = cache.get(pluginName); 58 | if (classLoader == null) { 59 | classLoader = new URLClassLoader(new URL[]{url}); 60 | cache.put(pluginName, classLoader); 61 | } 62 | return classLoader.loadClass(className); 63 | } 64 | 65 | public static Class loadClass2(String pluginName, String className) throws Exception { 66 | URL url = listFileByPluginName(pluginName); 67 | 68 | //得到系统类加载器 69 | URLClassLoader urlClassLoader= (URLClassLoader) ClassLoader.getSystemClassLoader(); 70 | //因为URLClassLoader中的addURL方法的权限为protected所以只能采用反射的方法调用addURL方法 71 | Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class }); 72 | add.setAccessible(true); 73 | add.invoke(urlClassLoader, new Object[] {url}); 74 | Class c =Class.forName(className); 75 | return c; 76 | } 77 | 78 | public static void main(String [] args)throws ClassNotFoundException, MalformedURLException{ 79 | listFileByPluginName("mysqlJobManager"); 80 | 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /jobManager-core/src/main/java/com/cug/intellM/jobManager/util/Configuration.java: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.util; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.util.Arrays; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.regex.Matcher; 14 | import java.util.regex.Pattern; 15 | 16 | import org.apache.commons.io.IOUtils; 17 | import com.alibaba.fastjson.JSON; 18 | 19 | /** 20 | * Created by lyc on 2017/10/9. 21 | *Configuration 提供多级JSON配置信息无损存储 22 | */ 23 | public class Configuration { 24 | 25 | private static final Pattern VARIABLE_PATTERN = Pattern 26 | .compile("(\\$)\\{?(\\w+)\\}?"); 27 | private Object root = null; 28 | 29 | /** 30 | * 从JSON字符串加载Configuration 31 | */ 32 | public static Configuration from(String json) { 33 | json = replaceVariable(json); 34 | checkJSON(json); 35 | 36 | try { 37 | return new Configuration(json); 38 | } catch (Exception e) { 39 | throw new RuntimeException(e); 40 | } 41 | 42 | } 43 | 44 | /** 45 | * 从包括json的File对象加载Configuration 46 | */ 47 | public static Configuration from(File file) { 48 | try { 49 | return Configuration.from(IOUtils.toString(new FileInputStream(file))); 50 | } catch (FileNotFoundException e) { 51 | throw new RuntimeException( 52 | String.format("配置信息错误,您提供的配置文件[%s]不存在. 请检查您的配置文件.", file.getAbsolutePath())); 53 | } catch (IOException e) { 54 | throw new RuntimeException( 55 | String.format("配置信息错误. 您提供配置文件[%s]读取失败,错误原因: %s. 请检查您的配置文件的权限设置.", 56 | file.getAbsolutePath(), e)); 57 | } 58 | } 59 | 60 | private void checkPath(final String path) { 61 | if (null == path) { 62 | throw new IllegalArgumentException( 63 | "系统编程错误, 该异常代表系统编程错误, 请联系开发团队!."); 64 | } 65 | 66 | for (final String each : StringUtils.split(".")) { 67 | if (StringUtils.isBlank(each)) { 68 | throw new IllegalArgumentException(String.format( 69 | "系统编程错误, 路径[%s]不合法, 路径层次之间不能出现空白字符 .", path)); 70 | } 71 | } 72 | } 73 | 74 | private static void checkJSON(final String json) { 75 | if (StringUtils.isBlank(json)) { 76 | throw new RuntimeException( 77 | "配置信息错误. 因为您提供的配置信息不是合法的JSON格式, JSON不能为空白. 请按照标准json格式提供配置信息. "); 78 | } 79 | } 80 | 81 | public static String replaceVariable(final String param) { 82 | Map mapping = new HashMap(); 83 | 84 | Matcher matcher = VARIABLE_PATTERN.matcher(param); 85 | while (matcher.find()) { 86 | String variable = matcher.group(2); 87 | String value = System.getProperty(variable); 88 | if (StringUtils.isBlank(value)) { 89 | value = matcher.group(); 90 | } 91 | mapping.put(matcher.group(), value); 92 | } 93 | 94 | String retString = param; 95 | for (final String key : mapping.keySet()) { 96 | retString = retString.replace(key, mapping.get(key)); 97 | } 98 | 99 | return retString; 100 | } 101 | 102 | private Configuration(final String json) { 103 | try { 104 | this.root = JSON.parse(json); 105 | } catch (Exception e) { 106 | throw new RuntimeException( 107 | String.format("配置信息错误. 您提供的配置信息不是合法的JSON格式: %s . 请按照标准json格式提供配置信息. ", e.getMessage())); 108 | } 109 | } 110 | 111 | /** 112 | * 根据用户提供的json path,寻址具体的对象。 113 | *

114 | *
115 | *

116 | * NOTE: 目前仅支持Map以及List下标寻址, 例如: 117 | *

118 | *
119 | *

120 | * 对于如下JSON 121 | *

122 | * {"a": {"b": {"c": [0,1,2,3]}}} 123 | *

124 | * config.get("") 返回整个Map
125 | * config.get("a") 返回a下属整个Map
126 | * config.get("a.b.c") 返回c对应的数组List
127 | * config.get("a.b.c[0]") 返回数字0 128 | * 129 | * @return Java表示的JSON对象,如果path不存在或者对象不存在,均返回null。 130 | */ 131 | public Object get(final String path) { 132 | this.checkPath(path); 133 | try { 134 | return this.findObject(path); 135 | } catch (Exception e) { 136 | return null; 137 | } 138 | } 139 | 140 | private Object findObject(final String path) { 141 | boolean isRootQuery = StringUtils.isBlank(path); 142 | if (isRootQuery) { 143 | return this.root; 144 | } 145 | 146 | Object target = this.root; 147 | 148 | for (final String each : split2List(path)) { 149 | if (isPathMap(each)) { 150 | target = findObjectInMap(target, each); 151 | continue; 152 | } else { 153 | target = findObjectInList(target, each); 154 | continue; 155 | } 156 | } 157 | 158 | return target; 159 | } 160 | 161 | private Object findObjectInMap(final Object target, final String index) { 162 | boolean isMap = (target instanceof Map); 163 | if (!isMap) { 164 | throw new IllegalArgumentException(String.format( 165 | "您提供的配置文件有误. 路径[%s]需要配置Json格式的Map对象,但该节点发现实际类型是[%s]. 请检查您的配置并作出修改.", 166 | index, target.getClass().toString())); 167 | } 168 | 169 | Object result = ((Map) target).get(index); 170 | if (null == result) { 171 | throw new IllegalArgumentException(String.format( 172 | "您提供的配置文件有误. 路径[%s]值为null,datax无法识别该配置. 请检查您的配置并作出修改.", index)); 173 | } 174 | 175 | return result; 176 | } 177 | 178 | private Object findObjectInList(final Object target, final String each) { 179 | boolean isList = (target instanceof List); 180 | if (!isList) { 181 | throw new IllegalArgumentException(String.format( 182 | "您提供的配置文件有误. 路径[%s]需要配置Json格式的Map对象,但该节点发现实际类型是[%s]. 请检查您的配置并作出修改.", 183 | each, target.getClass().toString())); 184 | } 185 | 186 | String index = each.replace("[", "").replace("]", ""); 187 | if (!StringUtils.isNumeric(index)) { 188 | throw new IllegalArgumentException( 189 | String.format( 190 | "系统编程错误,列表下标必须为数字类型,但该节点发现实际类型是[%s] ,该异常代表系统编程错误, 请联系DataX开发团队 !", 191 | index)); 192 | } 193 | 194 | return ((List) target).get(Integer.valueOf(index)); 195 | } 196 | 197 | private List split2List(final String path) { 198 | return Arrays.asList(StringUtils.split(split(path), ".")); 199 | } 200 | 201 | private String split(final String path) { 202 | return StringUtils.replace(path, "[", ".["); 203 | } 204 | 205 | private boolean isPathMap(final String path) { 206 | return StringUtils.isNotBlank(path) && !isPathList(path); 207 | } 208 | 209 | private boolean isPathList(final String path) { 210 | return path.contains("[") && path.contains("]"); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /jobManager-core/.svn/pristine/ad/ad92a2f826f08cd367350ece5320a670a115ff8d.svn-base: -------------------------------------------------------------------------------- 1 | package com.cug.intellM.jobManager.util; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.util.Arrays; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.regex.Matcher; 14 | import java.util.regex.Pattern; 15 | 16 | import org.apache.commons.io.IOUtils; 17 | import com.alibaba.fastjson.JSON; 18 | 19 | /** 20 | * Created by lyc on 2017/10/9. 21 | *Configuration 提供多级JSON配置信息无损存储 22 | */ 23 | public class Configuration { 24 | 25 | private static final Pattern VARIABLE_PATTERN = Pattern 26 | .compile("(\\$)\\{?(\\w+)\\}?"); 27 | private Object root = null; 28 | 29 | /** 30 | * 从JSON字符串加载Configuration 31 | */ 32 | public static Configuration from(String json) { 33 | json = replaceVariable(json); 34 | checkJSON(json); 35 | 36 | try { 37 | return new Configuration(json); 38 | } catch (Exception e) { 39 | throw new RuntimeException(e); 40 | } 41 | 42 | } 43 | 44 | /** 45 | * 从包括json的File对象加载Configuration 46 | */ 47 | public static Configuration from(File file) { 48 | try { 49 | return Configuration.from(IOUtils.toString(new FileInputStream(file))); 50 | } catch (FileNotFoundException e) { 51 | throw new RuntimeException( 52 | String.format("配置信息错误,您提供的配置文件[%s]不存在. 请检查您的配置文件.", file.getAbsolutePath())); 53 | } catch (IOException e) { 54 | throw new RuntimeException( 55 | String.format("配置信息错误. 您提供配置文件[%s]读取失败,错误原因: %s. 请检查您的配置文件的权限设置.", 56 | file.getAbsolutePath(), e)); 57 | } 58 | } 59 | 60 | private void checkPath(final String path) { 61 | if (null == path) { 62 | throw new IllegalArgumentException( 63 | "系统编程错误, 该异常代表系统编程错误, 请联系开发团队!."); 64 | } 65 | 66 | for (final String each : StringUtils.split(".")) { 67 | if (StringUtils.isBlank(each)) { 68 | throw new IllegalArgumentException(String.format( 69 | "系统编程错误, 路径[%s]不合法, 路径层次之间不能出现空白字符 .", path)); 70 | } 71 | } 72 | } 73 | 74 | private static void checkJSON(final String json) { 75 | if (StringUtils.isBlank(json)) { 76 | throw new RuntimeException( 77 | "配置信息错误. 因为您提供的配置信息不是合法的JSON格式, JSON不能为空白. 请按照标准json格式提供配置信息. "); 78 | } 79 | } 80 | 81 | public static String replaceVariable(final String param) { 82 | Map mapping = new HashMap(); 83 | 84 | Matcher matcher = VARIABLE_PATTERN.matcher(param); 85 | while (matcher.find()) { 86 | String variable = matcher.group(2); 87 | String value = System.getProperty(variable); 88 | if (StringUtils.isBlank(value)) { 89 | value = matcher.group(); 90 | } 91 | mapping.put(matcher.group(), value); 92 | } 93 | 94 | String retString = param; 95 | for (final String key : mapping.keySet()) { 96 | retString = retString.replace(key, mapping.get(key)); 97 | } 98 | 99 | return retString; 100 | } 101 | 102 | private Configuration(final String json) { 103 | try { 104 | this.root = JSON.parse(json); 105 | } catch (Exception e) { 106 | throw new RuntimeException( 107 | String.format("配置信息错误. 您提供的配置信息不是合法的JSON格式: %s . 请按照标准json格式提供配置信息. ", e.getMessage())); 108 | } 109 | } 110 | 111 | /** 112 | * 根据用户提供的json path,寻址具体的对象。 113 | *

114 | *
115 | *

116 | * NOTE: 目前仅支持Map以及List下标寻址, 例如: 117 | *

118 | *
119 | *

120 | * 对于如下JSON 121 | *

122 | * {"a": {"b": {"c": [0,1,2,3]}}} 123 | *

124 | * config.get("") 返回整个Map
125 | * config.get("a") 返回a下属整个Map
126 | * config.get("a.b.c") 返回c对应的数组List
127 | * config.get("a.b.c[0]") 返回数字0 128 | * 129 | * @return Java表示的JSON对象,如果path不存在或者对象不存在,均返回null。 130 | */ 131 | public Object get(final String path) { 132 | this.checkPath(path); 133 | try { 134 | return this.findObject(path); 135 | } catch (Exception e) { 136 | return null; 137 | } 138 | } 139 | 140 | private Object findObject(final String path) { 141 | boolean isRootQuery = StringUtils.isBlank(path); 142 | if (isRootQuery) { 143 | return this.root; 144 | } 145 | 146 | Object target = this.root; 147 | 148 | for (final String each : split2List(path)) { 149 | if (isPathMap(each)) { 150 | target = findObjectInMap(target, each); 151 | continue; 152 | } else { 153 | target = findObjectInList(target, each); 154 | continue; 155 | } 156 | } 157 | 158 | return target; 159 | } 160 | 161 | private Object findObjectInMap(final Object target, final String index) { 162 | boolean isMap = (target instanceof Map); 163 | if (!isMap) { 164 | throw new IllegalArgumentException(String.format( 165 | "您提供的配置文件有误. 路径[%s]需要配置Json格式的Map对象,但该节点发现实际类型是[%s]. 请检查您的配置并作出修改.", 166 | index, target.getClass().toString())); 167 | } 168 | 169 | Object result = ((Map) target).get(index); 170 | if (null == result) { 171 | throw new IllegalArgumentException(String.format( 172 | "您提供的配置文件有误. 路径[%s]值为null,datax无法识别该配置. 请检查您的配置并作出修改.", index)); 173 | } 174 | 175 | return result; 176 | } 177 | 178 | private Object findObjectInList(final Object target, final String each) { 179 | boolean isList = (target instanceof List); 180 | if (!isList) { 181 | throw new IllegalArgumentException(String.format( 182 | "您提供的配置文件有误. 路径[%s]需要配置Json格式的Map对象,但该节点发现实际类型是[%s]. 请检查您的配置并作出修改.", 183 | each, target.getClass().toString())); 184 | } 185 | 186 | String index = each.replace("[", "").replace("]", ""); 187 | if (!StringUtils.isNumeric(index)) { 188 | throw new IllegalArgumentException( 189 | String.format( 190 | "系统编程错误,列表下标必须为数字类型,但该节点发现实际类型是[%s] ,该异常代表系统编程错误, 请联系DataX开发团队 !", 191 | index)); 192 | } 193 | 194 | return ((List) target).get(Integer.valueOf(index)); 195 | } 196 | 197 | private List split2List(final String path) { 198 | return Arrays.asList(StringUtils.split(split(path), ".")); 199 | } 200 | 201 | private String split(final String path) { 202 | return StringUtils.replace(path, "[", ".["); 203 | } 204 | 205 | private boolean isPathMap(final String path) { 206 | return StringUtils.isNotBlank(path) && !isPathList(path); 207 | } 208 | 209 | private boolean isPathList(final String path) { 210 | return path.contains("[") && path.contains("]"); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 21 | 22 | 24 | 25 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 139 | 140 | 141 | 144 | 145 | 146 | 168 | 169 | 170 | 171 | 172 | true 173 | DEFINITION_ORDER 174 | 175 | 176 | 181 | 186 | 187 | 188 | 189 | 190 | 191 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 231 | 232 | 233 | 234 | 237 | 238 | 241 | 242 | 243 | 244 | 247 | 248 | 251 | 252 | 255 | 256 | 257 | 258 | 261 | 262 | 265 | 266 | 269 | 270 | 273 | 274 | 275 | 276 | 279 | 280 | 283 | 284 | 287 | 288 | 291 | 292 | 295 | 296 | 297 | 298 | 301 | 302 | 305 | 306 | 309 | 310 | 313 | 314 | 317 | 318 | 321 | 322 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 354 | 355 | 368 | 369 | 370 | 389 | 390 | 391 | 392 | 393 | 394 | 413 | 414 | 415 | 416 | 417 | 418 | 437 | 438 | 439 | 440 | 441 | 442 | 461 | 462 | 463 | 464 | 465 | 466 | 470 | 471 | 472 | 494 | 495 | 496 | 517 | 518 | 525 | 526 | 527 | 540 | 541 | 542 | 543 | 548 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 574 | 592 | 599 | 600 | 601 | 602 | 603 | 604 | 621 | 622 | 643 | 656 | 657 | 666 | 670 | 671 | 672 | 679 | 682 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 757 | 758 | 759 | 760 | 761 | 762 | 773 | 774 | 775 | 785 | 786 | 787 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 875 | 882 | 883 | 884 | 885 | 903 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | project 922 | 923 | 924 | true 925 | 926 | 927 | 928 | DIRECTORY 929 | 930 | false 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 975 | 976 | 977 | 979 | 980 | C:\Users\lyc\AppData\Roaming\Subversion 981 | 982 | 983 | 1003 | 1015 | 1016 | 1017 | 1018 | 1019 | 1506734223284 1020 | 1025 | 1026 | 1507620651189 1027 | 1032 | 1033 | 1507620791869 1034 | 1039 | 1040 | 1507620863719 1041 | 1046 | 1047 | 1507620900564 1048 | 1053 | 1056 | 1057 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1094 | 1097 | 1098 | 1099 | 1101 | 1102 | 1104 | 1105 | 1106 | 1108 | 1109 | 1110 | 1111 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 1288 | 1289 | 1290 | 1291 | 1292 | 1293 | 1294 | 1295 | 1296 | 1297 | 1298 | 1299 | 1300 | 1301 | 1302 | 1303 | 1304 | 1305 | 1306 | 1307 | 1308 | 1309 | 1310 | 1311 | 1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | 1324 | 1325 | 1326 | 1327 | 1328 | 1329 | 1330 | 1331 | 1332 | 1333 | 1334 | 1335 | 1336 | 1337 | 1338 | 1339 | 1340 | 1341 | 1342 | 1347 | 1348 | 1349 | 1350 | 1351 | 1352 | No facets are configured 1353 | 1354 | 1359 | 1360 | 1361 | 1362 | 1363 | 1364 | scala-sdk-2.10.4 1365 | 1366 | 1371 | 1372 | 1373 | 1374 | 1375 | 1376 | 1.7 1377 | 1378 | 1383 | 1384 | 1385 | 1386 | 1387 | 1388 | jobManager 1389 | 1390 | 1395 | 1396 | 1397 | 1398 | 1399 | 1400 | Maven: org.apache.commons:commons-lang3:3.4 1401 | 1402 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | --------------------------------------------------------------------------------