├── .gitignore
├── README.md
├── assembly
├── pom.xml
└── src
│ └── build
│ └── package.xml
├── bin
├── hdata
└── hdata.bat
├── conf
├── hdata.xml
├── log4j2.xml
└── plugins.xml
├── doc
└── img
│ ├── 1.png
│ └── 2.png
├── hdata-api
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ ├── api
│ ├── AbstractPlugin.java
│ ├── Configuration.java
│ ├── DefaultRecord.java
│ ├── EngineConfig.java
│ ├── Fields.java
│ ├── JobConfig.java
│ ├── JobContext.java
│ ├── JobStatus.java
│ ├── Metric.java
│ ├── OutputFieldsDeclarer.java
│ ├── PluginConfig.java
│ ├── Pluginable.java
│ ├── Reader.java
│ ├── Record.java
│ ├── RecordCollector.java
│ ├── Splitter.java
│ ├── Storage.java
│ └── Writer.java
│ └── exception
│ └── HDataException.java
├── hdata-console
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── reader
│ └── console
│ │ └── ConsoleReader.java
│ └── writer
│ └── console
│ └── ConsoleWriter.java
├── hdata-core
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ ├── CliDriver.java
│ ├── common
│ ├── Constants.java
│ └── HDataConfigConstants.java
│ ├── config
│ ├── DefaultEngineConfig.java
│ └── DefaultJobConfig.java
│ ├── core
│ ├── DefaultRecord.java
│ ├── DefaultRecordCollector.java
│ ├── DefaultStorage.java
│ ├── HData.java
│ ├── PluginClassLoader.java
│ ├── PluginLoader.java
│ ├── ReaderWorker.java
│ ├── RecordEvent.java
│ ├── RecordEventExceptionHandler.java
│ ├── RecordWorkHandler.java
│ └── WaitStrategyFactory.java
│ └── util
│ ├── NumberUtils.java
│ ├── PluginUtils.java
│ ├── TypeConvertUtils.java
│ └── Utils.java
├── hdata-csv
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── FormatConf.java
│ ├── reader
│ └── csv
│ │ ├── CSVReader.java
│ │ ├── CSVReaderProperties.java
│ │ └── CSVSplitter.java
│ └── writer
│ └── csv
│ ├── CSVWriter.java
│ └── CSVWriterProperties.java
├── hdata-excel
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ └── excel
│ ├── ExcelProperties.java
│ ├── reader
│ └── ExcelReader.java
│ └── writer
│ └── ExcelWriter.java
├── hdata-ftp
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ ├── ftp
│ └── FTPUtils.java
│ └── plugin
│ ├── reader
│ └── ftp
│ │ ├── FTPReader.java
│ │ ├── FTPReaderProperties.java
│ │ └── FTPSplitter.java
│ └── writer
│ └── ftp
│ ├── FTPWriter.java
│ └── FTPWriterProperties.java
├── hdata-hbase
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── reader
│ └── hbase
│ │ ├── HBaseReader.java
│ │ ├── HBaseReaderProperties.java
│ │ └── HBaseSplitter.java
│ └── writer
│ └── hbase
│ ├── HBaseWriter.java
│ └── HBaseWriterProperties.java
├── hdata-hdfs
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── reader
│ └── hdfs
│ │ ├── HDFSReader.java
│ │ ├── HDFSReaderProperties.java
│ │ └── HDFSSplitter.java
│ └── writer
│ └── hdfs
│ ├── HDFSWriter.java
│ └── HDFSWriterProperties.java
├── hdata-hive
├── pom.xml
└── src
│ └── main
│ └── java
│ ├── com
│ └── github
│ │ └── stuxuhai
│ │ └── hdata
│ │ └── plugin
│ │ ├── hive
│ │ ├── HiveMetaStoreUtils.java
│ │ └── HiveTypeUtils.java
│ │ ├── reader
│ │ └── hive
│ │ │ ├── HiveReader.java
│ │ │ ├── HiveReaderProperties.java
│ │ │ └── HiveSplitter.java
│ │ └── writer
│ │ └── hive
│ │ ├── HiveWriter.java
│ │ └── HiveWriterProperties.java
│ └── org
│ └── apache
│ └── hive
│ └── hcatalog
│ └── mapreduce
│ └── PartInfo.java
├── hdata-http
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ └── reader
│ └── http
│ ├── HttpReader.java
│ ├── HttpReaderProperties.java
│ └── HttpSplitter.java
├── hdata-jdbc
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── jdbc
│ └── JdbcUtils.java
│ ├── reader
│ └── jdbc
│ │ ├── JDBCIterator.java
│ │ ├── JDBCReader.java
│ │ ├── JDBCReaderProperties.java
│ │ └── JDBCSplitter.java
│ └── writer
│ └── jdbc
│ ├── JDBCWriter.java
│ └── JDBCWriterProperties.java
├── hdata-kafka
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── reader
│ └── kafka
│ │ ├── KafkaConsumer.java
│ │ ├── KafkaReader.java
│ │ └── KafkaReaderProperties.java
│ └── writer
│ └── kafka
│ ├── KafkaWriter.java
│ └── KafkaWriterProperties.java
├── hdata-mongodb
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── stuxuhai
│ └── hdata
│ └── plugin
│ ├── reader
│ └── mongodb
│ │ ├── MongoDBReader.java
│ │ ├── MongoDBReaderProperties.java
│ │ └── MongoDBSplitter.java
│ └── writer
│ └── mongodb
│ ├── MongoDBWriter.java
│ └── MongoDBWriterProperties.java
├── hdata-wit
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── stuxuhai
│ │ └── hdata
│ │ └── plugin
│ │ └── wit
│ │ ├── Methods.java
│ │ ├── WitDynamicRecord.java
│ │ ├── resolvers
│ │ └── RecordResolver.java
│ │ └── writer
│ │ ├── WitWriter.java
│ │ └── WitWriterProperties.java
│ └── resources
│ ├── META-INF
│ └── services
│ │ └── org.febit.wit.plugin.EnginePlugin
│ └── hdata-wit-writer.wim
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | /build/
--------------------------------------------------------------------------------
/assembly/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.stuxuhai
6 | hdata
7 | 0.2.8
8 | ../pom.xml
9 |
10 | assembly
11 | hdata-assembly
12 |
13 | ${project.basedir}/..
14 |
15 |
16 |
17 |
18 | org.apache.maven.plugins
19 | maven-assembly-plugin
20 |
21 |
22 | make-package
23 | package
24 |
25 | single
26 |
27 |
28 | ${topdir}/build
29 | hdata-${project.version}
30 | false
31 |
32 | src/build/package.xml
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/assembly/src/build/package.xml:
--------------------------------------------------------------------------------
1 |
5 | package
6 |
7 | tar.gz
8 |
9 |
10 |
11 |
12 | ${topdir}/bin
13 | bin
14 |
15 |
16 |
17 | ${topdir}/conf
18 | conf
19 |
20 |
21 |
22 | ${topdir}/target/all-modules/hdata-api
23 | lib
24 |
25 |
26 | ${topdir}/target/all-modules/hdata-core
27 | lib
28 |
29 |
30 |
31 | ${topdir}/target/all-modules/hdata-console
32 | plugins/console
33 |
34 |
35 | ${topdir}/target/all-modules/hdata-csv
36 | plugins/csv
37 |
38 |
39 | ${topdir}/target/all-modules/hdata-excel
40 | plugins/excel
41 |
42 |
43 | ${topdir}/target/all-modules/hdata-ftp
44 | plugins/ftp
45 |
46 |
47 | ${topdir}/target/all-modules/hdata-hbase
48 | plugins/hbase
49 |
50 |
51 | ${topdir}/target/all-modules/hdata-hdfs
52 | plugins/hdfs
53 |
54 |
55 | ${topdir}/target/all-modules/hdata-hive
56 | plugins/hive
57 |
58 |
59 | ${topdir}/target/all-modules/hdata-http
60 | plugins/http
61 |
62 |
63 | ${topdir}/target/all-modules/hdata-jdbc
64 | plugins/jdbc
65 |
66 |
67 | ${topdir}/target/all-modules/hdata-kafka
68 | plugins/kafka
69 |
70 |
71 | ${topdir}/target/all-modules/hdata-mongodb
72 | plugins/mongodb
73 |
74 |
75 | ${topdir}/target/all-modules/hdata-wit
76 | plugins/wit
77 |
78 |
79 |
--------------------------------------------------------------------------------
/bin/hdata:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | CDPATH=""
5 | SCRIPT="$0"
6 |
7 | while [ -h "$SCRIPT" ] ; do
8 | ls=$(ls -ld "$SCRIPT")
9 | link=$(expr "$ls" : '.*-> \(.*\)$')
10 | if expr "$link" : '/.*' > /dev/null; then
11 | SCRIPT="$link"
12 | else
13 | SCRIPT=$(dirname "$SCRIPT")/"$link"
14 | fi
15 | done
16 |
17 | HDATA_HOME=$(cd "$(dirname "$SCRIPT")/.."; pwd)
18 | HDATA_LIB_DIR=$HDATA_HOME/lib
19 | HDATA_CONF_DIR=$HDATA_HOME/conf
20 |
21 | if [ -x "$JAVA_HOME/bin/java" ]; then
22 | JAVA="$JAVA_HOME/bin/java"
23 | else
24 | JAVA=$(which java)
25 | fi
26 |
27 | if [ ! -x "$JAVA" ]; then
28 | echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
29 | exit 1
30 | fi
31 |
32 | HDATA_CLASSPATH_APPEND="$HDATA_CLASSPATH"
33 | HDATA_CLASSPATH='.'
34 |
35 | for f in $HDATA_LIB_DIR/*.jar; do
36 | HDATA_CLASSPATH="${HDATA_CLASSPATH}:$f";
37 | done
38 |
39 | if [ ! -z "$HDATA_CLASSPATH_APPEND" ]; then
40 | HDATA_CLASSPATH="${HDATA_CLASSPATH}:$HDATA_CLASSPATH_APPEND";
41 | fi
42 |
43 | JAVA_OPTS="$JAVA_OPTS -Xss256k"
44 | JAVA_OPTS="$JAVA_OPTS -Xms1G -Xmx1G -Xmn512M"
45 | JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
46 | JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
47 | JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled"
48 | JAVA_OPTS="$JAVA_OPTS -XX:+CMSParallelRemarkEnabled"
49 | JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC"
50 | JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75"
51 | JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
52 | JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
53 | JAVA_OPTS="$JAVA_OPTS -XX:SoftRefLRUPolicyMSPerMB=0"
54 |
55 | JAVA_OPTS="$JAVA_OPTS -Dhdata.conf.dir=$HDATA_CONF_DIR"
56 | JAVA_OPTS="$JAVA_OPTS -Dlog4j.configurationFile=file:///$HDATA_CONF_DIR/log4j2.xml"
57 |
58 | MAIN_CLASS="com.github.stuxuhai.hdata.CliDriver"
59 |
60 | exec "$JAVA" $JAVA_OPTS -cp "$HDATA_CLASSPATH" $MAIN_CLASS "$@"
61 |
--------------------------------------------------------------------------------
/bin/hdata.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | cd /d %~dp0..
3 | setlocal ENABLEDELAYEDEXPANSION
4 | set HDATA_HOME=%cd%
5 | set HDATA_LIB_DIR=%HDATA_HOME%\lib
6 | set HDATA_CONF_DIR=%HDATA_HOME%\conf
7 | set HDATA_PLUGINS_DIR=%HDATA_HOME%\plugins
8 |
9 | if not defined java_home (
10 | echo "Not defined JAVA_HOME,Please install java in your PATH and set JAVA_HOME"
11 | call :timeoutAndExit
12 | )
13 | set JAVA="%JAVA_HOME%\bin\java.exe"
14 |
15 | if not exist %JAVA% (
16 | echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
17 | call :timeoutAndExit
18 | )
19 |
20 | set HDATA_CLASSPATH=.;%HDATA_LIB_DIR%\*
21 | ::add plugins to class_path
22 | ::for /f %%i in ('dir /b /ad %HDATA_PLUGINS_DIR%') do (
23 | ::set HDATA_CLASSPATH=!HDATA_CLASSPATH!;!HDATA_PLUGINS_DIR!\%%i\*
24 | ::)
25 | echo %HDATA_CLASSPATH%
26 |
27 | set JAVA_OPTS=%JAVA_OPTS% -Xss256k
28 | set JAVA_OPTS=%JAVA_OPTS% -Xms1G -Xmx1G -Xmn512M
29 | set JAVA_OPTS=%JAVA_OPTS% -XX:+UseParNewGC
30 | set JAVA_OPTS=%JAVA_OPTS% -XX:+UseConcMarkSweepGC
31 | set JAVA_OPTS=%JAVA_OPTS% -XX:+CMSClassUnloadingEnabled
32 | set JAVA_OPTS=%JAVA_OPTS% -XX:+CMSParallelRemarkEnabled
33 | set JAVA_OPTS=%JAVA_OPTS% -XX:+DisableExplicitGC
34 | set JAVA_OPTS=%JAVA_OPTS% -XX:CMSInitiatingOccupancyFraction=75
35 | set JAVA_OPTS=%JAVA_OPTS% -XX:+UseCMSInitiatingOccupancyOnly
36 | set JAVA_OPTS=%JAVA_OPTS% -XX:+HeapDumpOnOutOfMemoryError
37 | set JAVA_OPTS=%JAVA_OPTS% -XX:SoftRefLRUPolicyMSPerMB=0
38 |
39 | set JAVA_OPTS=%JAVA_OPTS% -Dhdata.conf.dir="%HDATA_CONF_DIR%"
40 | set JAVA_OPTS=%JAVA_OPTS% -Dlog4j.configurationFile=file:///%HDATA_CONF_DIR%\log4j2.xml
41 |
42 | set MAIN_CLASS="com.github.stuxuhai.hdata.CliDriver"
43 |
44 | echo %JAVA% %JAVA_OPTS% -classpath "%HDATA_CLASSPATH%" %MAIN_CLASS% %1 %2 %3 %4 %5 %6 %7 %8 %9
45 | %JAVA% %JAVA_OPTS% -classpath "%HDATA_CLASSPATH%" %MAIN_CLASS% %1 %2 %3 %4 %5 %6 %7 %8 %9
46 |
47 | goto :EOF
48 |
49 | :timeoutAndExit
50 | timeout /t 10&&exit
51 |
--------------------------------------------------------------------------------
/conf/hdata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | hdata.storage.default.buffer.size
6 | 16384
7 | 默认storage缓冲区大小,值必须为2^n
8 |
9 |
10 | hdata.storage.disruptor.wait.strategy
11 | com.lmax.disruptor.BlockingWaitStrategy
12 | 线程等待策略
13 |
14 |
15 | hdata.hive.writer.tmp.dir
16 | /tmp
17 | Hive Writer写入HDFS文件的临时目录
18 |
19 |
20 | jdbc.reader.sql.metric.time.ms
21 | 3000
22 | 设定SQL执行时间阈值,超过该值将记录日志中
23 |
24 |
25 |
--------------------------------------------------------------------------------
/conf/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/conf/plugins.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | jdbc
7 | com.github.stuxuhai.hdata.plugin.reader.jdbc.JDBCReader
8 |
9 |
10 | hive
11 | com.github.stuxuhai.hdata.plugin.reader.hive.HiveReader
12 |
13 |
14 | hdfs
15 | com.github.stuxuhai.hdata.plugin.reader.hdfs.HDFSReader
16 |
17 |
18 | ftp
19 | com.github.stuxuhai.hdata.plugin.reader.ftp.FTPReader
20 |
21 |
22 | mongodb
23 | com.github.stuxuhai.hdata.plugin.reader.mongodb.MongoDBReader
24 |
25 |
26 | hbase
27 | com.github.stuxuhai.hdata.plugin.reader.hbase.HBaseReader
28 |
29 |
30 | http
31 | com.github.stuxuhai.hdata.plugin.reader.http.HttpReader
32 |
33 |
34 | csv
35 | com.github.stuxuhai.hdata.plugin.reader.csv.CSVReader
36 |
37 |
38 | kafka
39 | com.github.stuxuhai.hdata.plugin.reader.kafka.KafkaReader
40 |
41 |
42 | console
43 | com.github.stuxuhai.hdata.plugin.reader.console.ConsoleReader
44 |
45 |
46 | excel
47 | com.github.stuxuhai.hdata.plugin.excel.reader.ExcelReader
48 |
49 |
50 |
51 |
52 |
53 | console
54 | com.github.stuxuhai.hdata.plugin.writer.console.ConsoleWriter
55 |
56 |
57 | jdbc
58 | com.github.stuxuhai.hdata.plugin.writer.jdbc.JDBCWriter
59 |
60 |
61 | hive
62 | com.github.stuxuhai.hdata.plugin.writer.hive.HiveWriter
63 |
64 |
65 | hdfs
66 | com.github.stuxuhai.hdata.plugin.writer.hdfs.HDFSWriter
67 |
68 |
69 | ftp
70 | com.github.stuxuhai.hdata.plugin.writer.ftp.FTPWriter
71 |
72 |
73 | mongodb
74 | com.github.stuxuhai.hdata.plugin.writer.mongodb.MongoDBWriter
75 |
76 |
77 | hbase
78 | com.github.stuxuhai.hdata.plugin.writer.hbase.HBaseWriter
79 |
80 |
81 | csv
82 | com.github.stuxuhai.hdata.plugin.writer.csv.CSVWriter
83 |
84 |
85 | kafka
86 | com.github.stuxuhai.hdata.plugin.writer.kafka.KafkaWriter
87 |
88 |
89 | excel
90 | com.github.stuxuhai.hdata.plugin.excel.writer.ExcelWriter
91 |
92 |
93 | wit
94 | com.github.stuxuhai.hdata.plugin.wit.writer.WitWriter
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/doc/img/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fork-archive-hub/hdata/5fdaf9d9e2e21c1ae704db4579c13753be23bd0a/doc/img/1.png
--------------------------------------------------------------------------------
/doc/img/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fork-archive-hub/hdata/5fdaf9d9e2e21c1ae704db4579c13753be23bd0a/doc/img/2.png
--------------------------------------------------------------------------------
/hdata-api/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.stuxuhai
6 | hdata
7 | 0.2.8
8 | ../pom.xml
9 |
10 | hdata-api
11 | hdata-api
12 |
13 |
14 |
15 | 2.5
16 |
17 |
18 |
19 |
20 | org.apache.logging.log4j
21 | log4j-api
22 | ${log4j.version}
23 |
24 |
25 | org.apache.logging.log4j
26 | log4j-core
27 | ${log4j.version}
28 |
29 |
30 | org.apache.logging.log4j
31 | log4j-slf4j-impl
32 | ${log4j.version}
33 |
34 |
35 | org.apache.logging.log4j
36 | log4j-1.2-api
37 | ${log4j.version}
38 |
39 |
40 | org.apache.logging.log4j
41 | log4j-jul
42 | ${log4j.version}
43 |
44 |
45 | org.apache.logging.log4j
46 | log4j-jcl
47 | ${log4j.version}
48 |
49 |
50 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/AbstractPlugin.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public abstract class AbstractPlugin implements Pluginable {
4 |
5 | private String pluginName;
6 |
7 | @Override
8 | public String getPluginName() {
9 | return this.pluginName;
10 | }
11 |
12 | @Override
13 | public void setPluginName(String name) {
14 | this.pluginName = name;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Configuration.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | import java.util.Properties;
4 |
5 | public abstract class Configuration extends Properties {
6 |
7 | private static final long serialVersionUID = 8606831740240321865L;
8 |
9 | public String getString(String key, String defaultValue) {
10 | String value = getProperty(key);
11 | return value != null ? value : defaultValue;
12 | }
13 |
14 | public String getString(String key) {
15 | return getProperty(key);
16 | }
17 |
18 | public void setString(String key, String value) {
19 | setProperty(key, value);
20 | }
21 |
22 | public int getInt(String key, int defaultValue) {
23 | String value = getProperty(key);
24 | return value != null ? Integer.parseInt(value) : defaultValue;
25 | }
26 |
27 | public void setInt(String key, int value) {
28 | setString(key, Integer.toString(value));
29 | }
30 |
31 | public long getLong(String key, long defaultValue) {
32 | String value = getProperty(key);
33 | return value != null ? Long.parseLong(value) : defaultValue;
34 | }
35 |
36 | public void setLong(String key, long value) {
37 | setString(key, Long.toString(value));
38 | }
39 |
40 | public double getDouble(String key, double defaultValue) {
41 | String value = getProperty(key);
42 | return value != null ? Double.parseDouble(value) : defaultValue;
43 | }
44 |
45 | public void setDouble(String key, double value) {
46 | setString(key, Double.toString(value));
47 | }
48 |
49 | public boolean getBoolean(String key, boolean defaultValue) {
50 | String value = getProperty(key);
51 | return value != null ? Boolean.parseBoolean(value) : defaultValue;
52 | }
53 |
54 | public void setBoolean(String key, boolean value) {
55 | setString(key, Boolean.toString(value));
56 | }
57 |
58 | public float getFloat(String key, float defaultValue) {
59 | String value = getProperty(key);
60 | return value != null ? Float.parseFloat(value) : defaultValue;
61 | }
62 |
63 | public void setFloat(String key, float value) {
64 | setString(key, Float.toString(value));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/DefaultRecord.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public class DefaultRecord implements Record {
4 |
5 | private final Object[] fields;
6 | private int cursor;
7 |
8 | public DefaultRecord(int fieldCount) {
9 | fields = new Object[fieldCount];
10 | }
11 |
12 | @Override
13 | public void add(int index, Object field) {
14 | fields[index] = field;
15 | this.cursor++;
16 | }
17 |
18 | @Override
19 | public void add(Object field) {
20 | add(cursor, field);
21 | }
22 |
23 | @Override
24 | public Object get(int index) {
25 | return fields[index];
26 | }
27 |
28 | @Override
29 | public int size() {
30 | return fields.length;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | StringBuilder sb = new StringBuilder();
36 | sb.append("{");
37 | for (int i = 0, len = fields.length; i < len; i++) {
38 | if (i > 0) {
39 | sb.append(", ");
40 | }
41 | sb.append(fields[i]);
42 | }
43 | sb.append("}");
44 | return sb.toString();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/EngineConfig.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.stuxuhai.hdata.api;
3 |
4 | public abstract class EngineConfig extends Configuration {
5 |
6 | private static final long serialVersionUID = 1L;
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Fields.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 |
6 | public class Fields extends ArrayList {
7 |
8 | private static final long serialVersionUID = -174064216143075549L;
9 |
10 | public Fields() {
11 | super();
12 | }
13 |
14 | public Fields(String... fields) {
15 | super();
16 | Collections.addAll(this, fields);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/JobConfig.java:
--------------------------------------------------------------------------------
1 |
2 | package com.github.stuxuhai.hdata.api;
3 |
4 | public abstract class JobConfig extends Configuration {
5 |
6 | private static final long serialVersionUID = 1L;
7 |
8 | public abstract PluginConfig getReaderConfig();
9 |
10 | public abstract PluginConfig getWriterConfig();
11 |
12 | public abstract String getReaderName();
13 |
14 | public abstract String getWriterName();
15 |
16 | public abstract Reader newReader();
17 |
18 | public abstract Splitter newSplitter();
19 |
20 | public abstract Writer newWriter();
21 | }
22 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/JobContext.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public class JobContext {
4 |
5 | private EngineConfig engineConfig;
6 | private JobConfig jobConfig;
7 | private OutputFieldsDeclarer declarer;
8 | private Storage storage;
9 | private Metric metric;
10 | private Reader[] readers;
11 | private Writer[] writers;
12 | private boolean isReaderFinished;
13 | private boolean isReaderError;
14 | private boolean isWriterFinished;
15 | private boolean isWriterError;
16 | private JobStatus jobStatus = JobStatus.SUCCESS;
17 |
18 | public Fields getFields() {
19 | return declarer.getFields();
20 | }
21 |
22 | public void setFields(Fields fields) {
23 | declarer.declare(fields);
24 | }
25 |
26 | public EngineConfig getEngineConfig() {
27 | return engineConfig;
28 | }
29 |
30 | public void setEngineConfig(EngineConfig engineConfig) {
31 | this.engineConfig = engineConfig;
32 | }
33 |
34 | public OutputFieldsDeclarer getDeclarer() {
35 | return declarer;
36 | }
37 |
38 | public void setDeclarer(OutputFieldsDeclarer declarer) {
39 | this.declarer = declarer;
40 | }
41 |
42 | public Storage getStorage() {
43 | return storage;
44 | }
45 |
46 | public void setStorage(Storage storage) {
47 | this.storage = storage;
48 | }
49 |
50 | public Metric getMetric() {
51 | return metric;
52 | }
53 |
54 | public void setMetric(Metric metric) {
55 | this.metric = metric;
56 | }
57 |
58 | public JobConfig getJobConfig() {
59 | return jobConfig;
60 | }
61 |
62 | public void setJobConfig(JobConfig jobConfig) {
63 | this.jobConfig = jobConfig;
64 | }
65 |
66 | public boolean isWriterError() {
67 | return isWriterError;
68 | }
69 |
70 | public void setWriterError(boolean isWriterError) {
71 | this.isWriterError = isWriterError;
72 | }
73 |
74 | public boolean isReaderFinished() {
75 | return isReaderFinished;
76 | }
77 |
78 | public void setReaderFinished(boolean isReaderFinished) {
79 | this.isReaderFinished = isReaderFinished;
80 | }
81 |
82 | public boolean isReaderError() {
83 | return isReaderError;
84 | }
85 |
86 | public void setReaderError(boolean isReaderError) {
87 | this.isReaderError = isReaderError;
88 | }
89 |
90 | public boolean isWriterFinished() {
91 | return isWriterFinished;
92 | }
93 |
94 | public void setWriterFinished(boolean isWriterFinished) {
95 | this.isWriterFinished = isWriterFinished;
96 | }
97 |
98 | public Reader[] getReaders() {
99 | return readers;
100 | }
101 |
102 | public void setReaders(Reader[] readers) {
103 | this.readers = readers;
104 | }
105 |
106 | public Writer[] getWriters() {
107 | return writers;
108 | }
109 |
110 | public void setWriters(Writer[] writers) {
111 | this.writers = writers;
112 | }
113 |
114 | public JobStatus getJobStatus() {
115 | return jobStatus;
116 | }
117 |
118 | public void setJobStatus(JobStatus jobStatus) {
119 | this.jobStatus = jobStatus;
120 | }
121 |
122 | public void declareOutputFields() {
123 | for (Reader reader : readers) {
124 | if (getFields() == null) {
125 | reader.declareOutputFields(getDeclarer());
126 | } else {
127 | break;
128 | }
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/JobStatus.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public enum JobStatus {
4 |
5 | SUCCESS(0), FAILED(1);
6 |
7 | private int status;
8 |
9 | JobStatus(int status) {
10 | this.status = status;
11 | }
12 |
13 | public int getStatus() {
14 | return this.status;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Metric.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | import java.util.concurrent.atomic.AtomicLong;
4 |
5 | public class Metric {
6 |
7 | private AtomicLong readCount = new AtomicLong(0);
8 | private AtomicLong writeCount = new AtomicLong(0);
9 | private AtomicLong readBytes = new AtomicLong(0);
10 |
11 | private long readerStartTime;
12 | private long readerEndTime;
13 | private long writerStartTime;
14 | private long writerEndTime;
15 |
16 | public AtomicLong getReadCount() {
17 | return readCount;
18 | }
19 |
20 | public void setReadCount(AtomicLong readCount) {
21 | this.readCount = readCount;
22 | }
23 |
24 | public AtomicLong getWriteCount() {
25 | return writeCount;
26 | }
27 |
28 | public void setWriteCount(AtomicLong writeCount) {
29 | this.writeCount = writeCount;
30 | }
31 |
32 | public long getReaderStartTime() {
33 | return readerStartTime;
34 | }
35 |
36 | public void setReaderStartTime(long readerStartTime) {
37 | this.readerStartTime = readerStartTime;
38 | }
39 |
40 | public long getReaderEndTime() {
41 | return readerEndTime;
42 | }
43 |
44 | public void setReaderEndTime(long readerEndTime) {
45 | this.readerEndTime = readerEndTime;
46 | }
47 |
48 | public long getWriterStartTime() {
49 | return writerStartTime;
50 | }
51 |
52 | public void setWriterStartTime(long writerStartTime) {
53 | this.writerStartTime = writerStartTime;
54 | }
55 |
56 | public long getWriterEndTime() {
57 | return writerEndTime;
58 | }
59 |
60 | public void setWriterEndTime(long writerEndTime) {
61 | this.writerEndTime = writerEndTime;
62 | }
63 |
64 | public AtomicLong getReadBytes() {
65 | return readBytes;
66 | }
67 |
68 | public void setReadBytes(AtomicLong readBytes) {
69 | this.readBytes = readBytes;
70 | }
71 |
72 | public long getSpeed() {
73 | long distance = (System.currentTimeMillis() - this.readerStartTime) / 1000;
74 | if (distance == 0) {
75 | return 0;
76 | }
77 | return this.readBytes.get() / distance;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/OutputFieldsDeclarer.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public class OutputFieldsDeclarer {
4 | private Fields fields;
5 |
6 | public void declare(Fields fields) {
7 | this.fields = fields;
8 | }
9 |
10 | public Fields getFields() {
11 | return fields;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/PluginConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public class PluginConfig extends Configuration {
4 |
5 | private static final String PARALLELISM_KEY = "parallelism";
6 | private static final int DEFAULT_PARALLELISM = 1;
7 |
8 | private static final String FLOWLIMIT_KEY = "flow.limit";
9 | private static final long DEFAULT_FLOWLIMIT = 0;
10 |
11 | private static final long serialVersionUID = 3311331304791946068L;
12 |
13 | public PluginConfig() {
14 | super();
15 | }
16 |
17 | public int getParallelism() {
18 | int parallelism = getInt(PARALLELISM_KEY, DEFAULT_PARALLELISM);
19 | if (parallelism < 1) {
20 | throw new IllegalArgumentException("Reader and Writer parallelism must be >= 1.");
21 | }
22 | return parallelism;
23 | }
24 |
25 | public long getFlowLimit() {
26 | long flowLimit = getLong(FLOWLIMIT_KEY, DEFAULT_FLOWLIMIT);
27 | if (flowLimit < 0) {
28 | throw new IllegalArgumentException("Reader and Writer FLowLimit must be >= 0.");
29 | }
30 | return flowLimit;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Pluginable.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public interface Pluginable {
4 |
5 | public String getPluginName();
6 |
7 | public void setPluginName(String name);
8 | }
9 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Reader.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public abstract class Reader extends AbstractPlugin {
4 |
5 | public void prepare(JobContext context, PluginConfig readerConfig) {
6 | }
7 |
8 | public void execute(RecordCollector recordCollector) {
9 | }
10 |
11 | public void close() {
12 | }
13 |
14 | public void declareOutputFields(OutputFieldsDeclarer declarer) {
15 | }
16 |
17 | public abstract Splitter newSplitter();
18 | }
19 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Record.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public interface Record {
4 |
5 | public void add(Object object);
6 |
7 | public void add(int index, Object object);
8 |
9 | public Object get(int index);
10 |
11 | public int size();
12 | }
13 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/RecordCollector.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public interface RecordCollector {
4 |
5 | public void send(Record record);
6 |
7 | public void send(Record[] records);
8 | }
9 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Splitter.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | import java.util.List;
4 |
5 | public abstract class Splitter extends AbstractPlugin {
6 |
7 | public abstract List split(JobConfig jobConfig);
8 | }
9 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Storage.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public interface Storage {
4 |
5 | public void put(Record record);
6 |
7 | public void put(Record[] records);
8 |
9 | public boolean isEmpty();
10 |
11 | public int size();
12 |
13 | public void close();
14 | }
15 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/api/Writer.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.api;
2 |
3 | public abstract class Writer extends AbstractPlugin {
4 |
5 | public void prepare(JobContext context, PluginConfig writerConfig) {
6 | }
7 |
8 | public void execute(Record record) {
9 | }
10 |
11 | public void close() {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/hdata-api/src/main/java/com/github/stuxuhai/hdata/exception/HDataException.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.exception;
2 |
3 | public class HDataException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = 2510267358921118998L;
6 |
7 | private String message;
8 |
9 | public HDataException() {
10 | super();
11 | }
12 |
13 | public HDataException(final String message) {
14 | super(message);
15 | }
16 |
17 | public HDataException(final Exception e) {
18 | super(e);
19 | }
20 |
21 | public HDataException(Throwable cause) {
22 | super(cause);
23 | }
24 |
25 | public HDataException(final String message, final Throwable cause) {
26 | super(message, cause);
27 | }
28 |
29 | @Override
30 | public String getMessage() {
31 | return this.message == null ? super.getMessage() : this.message;
32 | }
33 |
34 | public void setMessage(String message) {
35 | this.message = message;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return this.message;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/hdata-console/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.stuxuhai
6 | hdata
7 | 0.2.8
8 |
9 | hdata-console
10 |
11 |
12 |
13 | com.github.stuxuhai
14 | hdata-api
15 | provided
16 |
17 |
18 |
--------------------------------------------------------------------------------
/hdata-console/src/main/java/com/github/stuxuhai/hdata/plugin/reader/console/ConsoleReader.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.plugin.reader.console;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 |
7 | import com.github.stuxuhai.hdata.api.DefaultRecord;
8 | import com.github.stuxuhai.hdata.api.JobContext;
9 | import com.github.stuxuhai.hdata.api.PluginConfig;
10 | import com.github.stuxuhai.hdata.api.Reader;
11 | import com.github.stuxuhai.hdata.api.Record;
12 | import com.github.stuxuhai.hdata.api.RecordCollector;
13 | import com.github.stuxuhai.hdata.api.Splitter;
14 | import com.github.stuxuhai.hdata.exception.HDataException;
15 |
16 | public class ConsoleReader extends Reader {
17 |
18 | private BufferedReader br = null;
19 |
20 | @Override
21 | public void prepare(JobContext context, PluginConfig readerConfig) {
22 | br = new BufferedReader(new InputStreamReader(System.in));
23 | }
24 |
25 | @Override
26 | public void execute(RecordCollector recordCollector) {
27 | try {
28 | String line = null;
29 | while ((line = br.readLine()) != null) {
30 | Record record = new DefaultRecord(1);
31 | record.add(line);
32 | recordCollector.send(record);
33 | }
34 | br.close();
35 | } catch (IOException e) {
36 | new HDataException(e);
37 | }
38 | }
39 |
40 | @Override
41 | public Splitter newSplitter() {
42 | return null;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/hdata-console/src/main/java/com/github/stuxuhai/hdata/plugin/writer/console/ConsoleWriter.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata.plugin.writer.console;
2 |
3 | import java.sql.Timestamp;
4 | import java.text.DateFormat;
5 | import java.text.SimpleDateFormat;
6 |
7 | import com.github.stuxuhai.hdata.api.Record;
8 | import com.github.stuxuhai.hdata.api.Writer;
9 |
10 | public class ConsoleWriter extends Writer {
11 |
12 | private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
13 |
14 | @Override
15 | public void execute(Record record) {
16 | StringBuilder sb = new StringBuilder();
17 | sb.append("{");
18 | for (int i = 0, len = record.size(); i < len; i++) {
19 | if (i > 0) {
20 | sb.append(", ");
21 | }
22 | Object obj = record.get(i);
23 | if (obj instanceof Timestamp) {
24 | sb.append(dateFormat.format(obj));
25 | } else {
26 | sb.append(obj);
27 | }
28 | }
29 | sb.append("}");
30 | System.out.println(sb.toString());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/hdata-core/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.stuxuhai
6 | hdata
7 | 0.2.8
8 | ../pom.xml
9 |
10 | hdata-core
11 | hdata-core
12 |
13 |
14 |
15 | com.github.stuxuhai
16 | hdata-api
17 |
18 |
19 | com.google.guava
20 | guava
21 |
22 |
23 | com.lmax
24 | disruptor
25 | 3.3.4
26 |
27 |
28 | commons-cli
29 | commons-cli
30 | 1.3.1
31 |
32 |
33 | com.carrotsearch
34 | java-sizeof
35 | 0.0.5
36 |
37 |
38 | org.apache.commons
39 | commons-lang3
40 | 3.4
41 |
42 |
43 | commons-configuration
44 | commons-configuration
45 | 1.10
46 |
47 |
48 | commons-collections
49 | commons-collections
50 | 3.2.2
51 |
52 |
53 | commons-beanutils
54 | commons-beanutils
55 | 1.9.2
56 |
57 |
58 | net.hydromatic
59 | eigenbase-properties
60 | 1.1.5
61 |
62 |
63 | org.apache.commons
64 | commons-digester3
65 | 3.2
66 |
67 |
68 |
--------------------------------------------------------------------------------
/hdata-core/src/main/java/com/github/stuxuhai/hdata/CliDriver.java:
--------------------------------------------------------------------------------
1 | package com.github.stuxuhai.hdata;
2 |
3 | import com.github.stuxuhai.hdata.api.JobConfig;
4 | import java.util.Map.Entry;
5 | import java.util.Properties;
6 |
7 | import org.apache.commons.cli.CommandLine;
8 | import org.apache.commons.cli.CommandLineParser;
9 | import org.apache.commons.cli.DefaultParser;
10 | import org.apache.commons.cli.HelpFormatter;
11 | import org.apache.commons.cli.Option;
12 | import org.apache.commons.cli.Options;
13 | import org.apache.commons.cli.ParseException;
14 | import org.apache.logging.log4j.Level;
15 | import org.apache.logging.log4j.LogManager;
16 | import org.apache.logging.log4j.Logger;
17 | import org.apache.logging.log4j.core.LoggerContext;
18 | import org.apache.logging.log4j.core.config.Configuration;
19 |
20 | import com.github.stuxuhai.hdata.api.PluginConfig;
21 | import com.github.stuxuhai.hdata.config.DefaultJobConfig;
22 | import com.github.stuxuhai.hdata.core.HData;
23 | import com.github.stuxuhai.hdata.exception.HDataException;
24 | import com.google.common.base.Throwables;
25 |
26 | public class CliDriver {
27 |
28 | private static final String XML_FILE_OPTION = "f";
29 | private static final String HDATA_VARS_OPTION = "D";
30 | private static final String QUIET_OPTION = "q";
31 | private static final String READER_OPTION = "reader";
32 | private static final String WRITER_OPTION = "writer";
33 | private static final String READER_VARS_OPTION = "R";
34 | private static final String WRITER_VARS_OPTION = "W";
35 |
36 | private static final Logger LOGGER = LogManager.getLogger();
37 |
38 | /**
39 | * 创建命令行选项
40 | *
41 | * @return
42 | */
43 | public Options createOptions() {
44 | Options options = new Options();
45 | options.addOption(XML_FILE_OPTION, null, true, "job xml path");
46 | options.addOption(QUIET_OPTION, null, false, "quiet");
47 | options.addOption(Option.builder(HDATA_VARS_OPTION).hasArgs().build());
48 |
49 | options.addOption(null, READER_OPTION, true, "reader name");
50 | options.addOption(Option.builder(READER_VARS_OPTION).hasArgs().build());
51 |
52 | options.addOption(null, WRITER_OPTION, true, "writer name");
53 | options.addOption(Option.builder(WRITER_VARS_OPTION).hasArgs().build());
54 | return options;
55 | }
56 |
57 | /**
58 | * 打印命令行帮助信息
59 | *
60 | * @param options
61 | */
62 | public void printHelp(Options options) {
63 | HelpFormatter formatter = new HelpFormatter();
64 | formatter.printHelp(" ", options);
65 | }
66 |
67 | /**
68 | * 替换命令行变量
69 | *
70 | * @param config
71 | * @param vars
72 | */
73 | public void replaceConfigVars(PluginConfig config, Properties vars) {
74 | for (Entry