Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jz-dmp-cmdexectool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚本章
jz-dmp-cmdexectool
Commits
a6e69722
Commit
a6e69722
authored
Mar 11, 2021
by
mcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
526f94fa
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
85 deletions
+120
-85
SyncParameters.java
...mdexectool/scheduler/common/task/sync/SyncParameters.java
+114
-77
env.ftl
src/main/resources/templates/env.ftl
+2
-1
source_hive.ftl
src/main/resources/templates/source_hive.ftl
+0
-5
source_jdbc.ftl
src/main/resources/templates/source_jdbc.ftl
+2
-1
transform_sql.ftl
src/main/resources/templates/transform_sql.ftl
+2
-1
No files found.
src/main/java/com/jz/dmp/cmdexectool/scheduler/common/task/sync/SyncParameters.java
View file @
a6e69722
...
...
@@ -91,7 +91,6 @@ public class SyncParameters extends AbstractParameters {
sink
=
""
;
transform
=
""
;
this
.
script
=
script
;
//Map<String, Object> scriptObj = (Map<String, Object>) JSONObject.parse(script);
JSONObject
scriptObj
=
JSONObject
.
parseObject
(
script
);
Map
<
String
,
Object
>
scripts
=
(
Map
<
String
,
Object
>)
scriptObj
.
get
(
"scripts"
);
Map
<
String
,
Object
>
sourceObj
=
(
Map
<
String
,
Object
>)
scripts
.
get
(
"reader"
);
//来源数据
...
...
@@ -102,19 +101,26 @@ public class SyncParameters extends AbstractParameters {
envModel
.
put
(
"sparkappname"
,
"Waterdrop"
);
env
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_ENV
,
envModel
,
freeMarkerConfig
);
//source information
Integer
sourceId
=
Integer
.
valueOf
((
String
)
sourceObj
.
get
(
"sourceDbId"
));
DmpSyncingDatasource
dmpSyncingDatasource
=
dmpSyncingDatasourceDao
.
queryById
(
sourceId
);
Integer
sourceTypeId
=
dmpSyncingDatasource
.
getDatasourceType
();
String
source_table_name
=
String
.
valueOf
(
sourceObj
.
get
(
"registerTableName"
));
String
[]
registerTableName
=
((
String
)
sourceObj
.
get
(
"registerTableName"
)).
split
(
","
);
//target information
Integer
targetDbId
=
Integer
.
valueOf
((
String
)
targetObj
.
get
(
"targetDbId"
));
DmpSyncingDatasource
targetDatasource
=
dmpSyncingDatasourceDao
.
queryById
(
targetDbId
);
Integer
targetTypeId
=
dmpSyncing
Datasource
.
getDatasourceType
();
Integer
targetTypeId
=
target
Datasource
.
getDatasourceType
();
String
targetTable
=
String
.
valueOf
(
targetObj
.
get
(
"targetTable"
));
//目标表
//source information
String
sourceIds
=
(
String
)
sourceObj
.
get
(
"sourceDbId"
);
String
[]
sourceIdArr
=
sourceIds
.
split
(
","
);
//Integer sourceId = Integer.valueOf(sourceIdArr[0]);
String
source_table_name
=
String
.
valueOf
(
sourceObj
.
get
(
"registerTableName"
));
//来源表
String
[]
registerTableName
=
source_table_name
.
split
(
","
);
//分库分表
//***** source ******
for
(
int
i
=
0
;
i
<
sourceIdArr
.
length
;
i
++)
{
String
id
=
sourceIdArr
[
i
];
DmpSyncingDatasource
dmpSyncingDatasource
=
dmpSyncingDatasourceDao
.
queryById
(
Integer
.
valueOf
(
id
));
Integer
sourceTypeId
=
dmpSyncingDatasource
.
getDatasourceType
();
//产生 Jdbc(MySQL、Oracle、SqlServer、PostgreSQL、Informix、DB2) source
if
((
sourceTypeId
==
DatasouceTypeConstant
.
MySQL
||
sourceTypeId
==
DatasouceTypeConstant
.
Oracle
...
...
@@ -123,8 +129,26 @@ public class SyncParameters extends AbstractParameters {
||
sourceTypeId
==
DatasouceTypeConstant
.
Informix
||
sourceTypeId
==
DatasouceTypeConstant
.
DB2
))
{
//source
getJdbcSource
(
dmpSyncingDatasource
,
registerTableName
,
freeMarkerConfig
,
publicKey
);
getJdbcSource
(
dmpSyncingDatasource
,
registerTableName
,
freeMarkerConfig
,
publicKey
,
i
);
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
Hive
)
{
//source
getSourceHive
(
envModel
,
freeMarkerConfig
,
registerTableName
,
i
);
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
Kudu
)
{
//source
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
SFTP
)
{
//source
getSourceSftp
(
registerTableName
,
dmpSyncingDatasource
,
publicKey
,
sourceObj
,
freeMarkerConfig
,
i
);
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
Elasticsearch
)
{
//source
getsourceElasticsearch
(
registerTableName
,
dmpSyncingDatasource
,
freeMarkerConfig
,
i
);
}
}
//产生 Jdbc(MySQL、Oracle、SqlServer、PostgreSQL、Informix、DB2) sink
if
((
targetTypeId
==
DatasouceTypeConstant
.
MySQL
||
targetTypeId
==
DatasouceTypeConstant
.
Oracle
...
...
@@ -132,7 +156,7 @@ public class SyncParameters extends AbstractParameters {
||
targetTypeId
==
DatasouceTypeConstant
.
PostgreSQL
||
targetTypeId
==
DatasouceTypeConstant
.
Informix
||
targetTypeId
==
DatasouceTypeConstant
.
DB2
))
{
getJdbcSink
(
targetDatasource
,
targetObj
,
freeMarkerConfig
,
publicKey
);
getJdbcSink
(
targetDatasource
,
targetObj
,
freeMarkerConfig
,
publicKey
,
source_table_name
);
}
//transform
if
(
mappingObj
.
size
()
>
0
&&
null
!=
mappingObj
)
{
...
...
@@ -164,9 +188,19 @@ public class SyncParameters extends AbstractParameters {
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
Elasticsearch
)
{
//waterdrop script
Map
<
String
,
String
>
waterdropModel
=
new
HashMap
<
String
,
String
>();
waterdropModel
.
put
(
"env"
,
env
);
waterdropModel
.
put
(
"source"
,
source
);
waterdropModel
.
put
(
"transform"
,
transform
);
waterdropModel
.
put
(
"sink"
,
sink
);
waterdropScript
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL
,
waterdropModel
,
freeMarkerConfig
);
}
private
void
getsourceElasticsearch
(
String
[]
registerTableName
,
DmpSyncingDatasource
dmpSyncingDatasource
,
FreeMarkerConfigurer
freeMarkerConfig
,
int
i
)
{
//source
for
(
String
tableName
:
registerTableName
)
{
String
tableName
=
registerTableName
[
i
];
//for (String tableName : registerTableName) {
List
<
String
>
list
=
new
ArrayList
<>();
String
hosts
=
dmpSyncingDatasource
.
getHost
()
+
":"
+
dmpSyncingDatasource
.
getPort
();
list
.
add
(
hosts
);
...
...
@@ -176,46 +210,27 @@ public class SyncParameters extends AbstractParameters {
//jdbcModel.put("index", "");
//jdbcModel.put("name_age", "");
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_ELASTICSEARCH
,
jdbcModel
,
freeMarkerConfig
);
}
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
Hive
)
{
//source
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
Kudu
)
{
//source
}
if
(
sourceTypeId
==
DatasouceTypeConstant
.
SFTP
)
{
//source
for
(
String
tableName
:
registerTableName
)
{
Map
sftpModel
=
new
HashMap
();
sftpModel
.
put
(
"host"
,
dmpSyncingDatasource
.
getHost
());
//主机名
sftpModel
.
put
(
"user"
,
dmpSyncingDatasource
.
getUserName
());
//用户
sftpModel
.
put
(
"password"
,
EncryptionUtils
.
decode
(
targetDatasource
.
getPassword
(),
publicKey
));
sftpModel
.
put
(
"port"
,
dmpSyncingDatasource
.
getPort
());
//端口
if
(
null
!=
sourceObj
.
get
(
"fileType"
))
{
sftpModel
.
put
(
"fileType"
,
sourceObj
.
get
(
"ftpFileType"
));
//文件类型
}
sftpModel
.
put
(
"delimiter"
,
sourceObj
.
get
(
"sourceFtpCsvDelimiter"
));
//分隔符
sftpModel
.
put
(
"head"
,
"true"
);
//是否加载第一行
sftpModel
.
put
(
"multiLine"
,
"true"
);
//多行解析
if
(
null
!=
sourceObj
.
get
(
"sourceFtpDir"
))
{
sftpModel
.
put
(
"path"
,
sourceObj
.
get
(
"sourceFtpDir"
).
toString
());
//文件路径
}
sftpModel
.
put
(
"result_table_name"
,
tableName
);
//spark生成的临时表名
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_SFTP
,
sftpModel
,
freeMarkerConfig
);
}
}
//waterdrop script
Map
<
String
,
String
>
waterdropModel
=
new
HashMap
<
String
,
String
>();
waterdropModel
.
put
(
"env"
,
env
);
waterdropModel
.
put
(
"source"
,
source
);
waterdropModel
.
put
(
"transform"
,
transform
);
waterdropModel
.
put
(
"sink"
,
sink
);
waterdropScript
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL
,
waterdropModel
,
freeMarkerConfig
);
//}
}
public
void
getJdbcSource
(
DmpSyncingDatasource
dmpSyncingDatasource
,
String
[]
registerTableName
,
FreeMarkerConfigurer
freeMarkerConfig
,
String
publicKey
)
{
for
(
String
tableName
:
registerTableName
)
{
public
void
getSourceHive
(
Map
<
String
,
String
>
envModel
,
FreeMarkerConfigurer
freeMarkerConfig
,
String
[]
registerTableName
,
int
i
)
{
//evn
envModel
.
put
(
"sparkSqlCatalogImplementation"
,
"hive"
);
env
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_ENV
,
envModel
,
freeMarkerConfig
);
//source
String
tableName
=
registerTableName
[
i
];
//for (String tableName : registerTableName) {
Map
hiveModel
=
new
HashMap
();
hiveModel
.
put
(
"pre_sql"
,
" select * from "
+
tableName
);
hiveModel
.
put
(
"result_table_name"
,
tableName
);
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_JDBC
,
hiveModel
,
freeMarkerConfig
);
//}
}
public
void
getJdbcSource
(
DmpSyncingDatasource
dmpSyncingDatasource
,
String
[]
registerTableName
,
FreeMarkerConfigurer
freeMarkerConfig
,
String
publicKey
,
int
i
)
{
//int tableLength =registerTableName.length-1;
String
tableName
=
registerTableName
[
i
];
//for (String tableName : registerTableName) {
Map
jdbcModel
=
new
HashMap
();
jdbcModel
.
put
(
"driver"
,
dmpSyncingDatasource
.
getDriverClassName
());
jdbcModel
.
put
(
"url"
,
dmpSyncingDatasource
.
getJdbcUrl
());
...
...
@@ -223,15 +238,15 @@ public class SyncParameters extends AbstractParameters {
jdbcModel
.
put
(
"result_table_name"
,
tableName
);
jdbcModel
.
put
(
"user"
,
dmpSyncingDatasource
.
getUserName
());
jdbcModel
.
put
(
"password"
,
EncryptionUtils
.
decode
(
dmpSyncingDatasource
.
getPassword
(),
publicKey
));
jdbcModel
.
put
(
"partitionColumn"
,
""
);
jdbcModel
.
put
(
"numPartitions"
,
""
);
//
jdbcModel.put("partitionColumn", "");
//
jdbcModel.put("numPartitions", "");
//jdbcModel.put("lowerBound", "");
//jdbcModel.put("upperBound", "");
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_JDBC
,
jdbcModel
,
freeMarkerConfig
);
}
//
}
}
public
void
getJdbcSink
(
DmpSyncingDatasource
targetDatasource
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurer
freeMarkerConfig
,
String
publicKey
)
{
public
void
getJdbcSink
(
DmpSyncingDatasource
targetDatasource
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurer
freeMarkerConfig
,
String
publicKey
,
String
source_table_name
)
{
String
postImportStatement
=
String
.
valueOf
(
targetObj
.
get
(
"postImportStatement"
));
//导入后语句
String
preImportStatement
=
String
.
valueOf
(
targetObj
.
get
(
"preImportStatement"
));
//导入前语句
preStatements
=
new
ArrayList
<
String
>();
...
...
@@ -264,10 +279,32 @@ public class SyncParameters extends AbstractParameters {
jdbcSinkModel
.
put
(
"dbtable"
,
targetObj
.
get
(
"targetTable"
));
//目标表
jdbcSinkModel
.
put
(
"user"
,
targetDatasource
.
getUserName
());
jdbcSinkModel
.
put
(
"password"
,
password
);
jdbcSinkModel
.
put
(
"source_table_name"
,
targetObj
.
get
(
"targetTable"
)
);
jdbcSinkModel
.
put
(
"source_table_name"
,
source_table_name
);
sink
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SINK_JDBC
,
jdbcSinkModel
,
freeMarkerConfig
);
}
public
void
getSourceSftp
(
String
[]
registerTableName
,
DmpSyncingDatasource
dmpSyncingDatasource
,
String
publicKey
,
Map
<
String
,
Object
>
sourceObj
,
FreeMarkerConfigurer
freeMarkerConfig
,
int
i
)
{
String
tableName
=
registerTableName
[
i
];
//for (String tableName : registerTableName) {
Map
sftpModel
=
new
HashMap
();
sftpModel
.
put
(
"host"
,
dmpSyncingDatasource
.
getHost
());
//主机名
sftpModel
.
put
(
"user"
,
dmpSyncingDatasource
.
getUserName
());
//用户
sftpModel
.
put
(
"password"
,
EncryptionUtils
.
decode
(
dmpSyncingDatasource
.
getPassword
(),
publicKey
));
sftpModel
.
put
(
"port"
,
dmpSyncingDatasource
.
getPort
());
//端口
if
(
null
!=
sourceObj
.
get
(
"fileType"
))
{
sftpModel
.
put
(
"fileType"
,
sourceObj
.
get
(
"ftpFileType"
));
//文件类型
}
sftpModel
.
put
(
"delimiter"
,
sourceObj
.
get
(
"sourceFtpCsvDelimiter"
));
//分隔符
sftpModel
.
put
(
"head"
,
"true"
);
//是否加载第一行
sftpModel
.
put
(
"multiLine"
,
"true"
);
//多行解析
if
(
null
!=
sourceObj
.
get
(
"sourceFtpDir"
))
{
sftpModel
.
put
(
"path"
,
sourceObj
.
get
(
"sourceFtpDir"
).
toString
());
//文件路径
}
sftpModel
.
put
(
"result_table_name"
,
tableName
);
//spark生成的临时表名
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_SFTP
,
sftpModel
,
freeMarkerConfig
);
//}
}
@Override
public
boolean
checkParameters
()
{
return
waterdropScript
!=
null
&&
!
waterdropScript
.
isEmpty
();
...
...
src/main/resources/templates/env.ftl
View file @
a6e69722
...
...
@@ -10,3 +10,4 @@
<#if sparkexecutormemory??>
spark.executor.memory = "${sparkexecutormemory!}"
</#if>
src/main/resources/templates/source_hive.ftl
View file @
a6e69722
spark {
<#if catalogImplementation??>
spark.sql.catalogImplementation = "${catalogImplementation!}"
</#if>
}
hive {
<#if pre_sql??>
...
...
src/main/resources/templates/source_jdbc.ftl
View file @
a6e69722
...
...
@@ -39,3 +39,4 @@ jdbc {
jdbc.upperBound = ${upperBound!}
</#if>
}
src/main/resources/templates/transform_sql.ftl
View file @
a6e69722
...
...
@@ -11,3 +11,4 @@ sql {
table_name = "${table_name!}"
</#if>
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment