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
eda389b1
Commit
eda389b1
authored
Mar 13, 2021
by
mcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
COMMIT
parent
3e16f307
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
291 additions
and
178 deletions
+291
-178
SyncParameters.java
...mdexectool/scheduler/common/task/sync/SyncParameters.java
+37
-12
ParameterUtils.java
...mp/cmdexectool/scheduler/common/utils/ParameterUtils.java
+254
-166
No files found.
src/main/java/com/jz/dmp/cmdexectool/scheduler/common/task/sync/SyncParameters.java
View file @
eda389b1
...
...
@@ -11,6 +11,7 @@ import com.jz.dmp.cmdexectool.mapper.DmpSyncingDatasourceDao;
import
com.jz.dmp.cmdexectool.scheduler.common.enums.MyDbType
;
import
com.jz.dmp.cmdexectool.scheduler.common.process.ResourceInfo
;
import
com.jz.dmp.cmdexectool.scheduler.common.task.AbstractParameters
;
import
com.jz.dmp.cmdexectool.scheduler.common.utils.ParameterUtils
;
import
com.jz.dmp.cmdexectool.scheduler.common.utils.StringUtils
;
import
com.jz.dmp.cmdexectool.scheduler.dao.datasource.MyBaseDataSource
;
import
org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean
;
...
...
@@ -158,7 +159,7 @@ public class SyncParameters extends AbstractParameters {
||
targetTypeId
==
DatasouceTypeConstant
.
PostgreSQL
||
targetTypeId
==
DatasouceTypeConstant
.
Informix
||
targetTypeId
==
DatasouceTypeConstant
.
DB2
))
{
getJdbcSink
(
targetDatasource
,
targetObj
,
freeMarkerConfig
,
publicKey
,
source_table_name
);
getJdbcSink
(
targetDatasource
,
targetObj
,
freeMarkerConfig
,
publicKey
,
source_table_name
,
mappingObj
);
}
if
(
targetTypeId
==
DatasouceTypeConstant
.
SFTP
)
{
getSinkSftp
(
targetDatasource
,
publicKey
,
targetObj
,
freeMarkerConfig
,
source_table_name
);
...
...
@@ -167,8 +168,8 @@ public class SyncParameters extends AbstractParameters {
getSinkKudu
(
targetDatasource
,
freeMarkerConfig
,
source_table_name
);
}
if
(
targetTypeId
==
DatasouceTypeConstant
.
Hive
)
{
//s
ource
getSinkHive
(
freeMarkerConfig
,
sourceObj
,
source_table_name
,
envModel
);
//s
ink
getSinkHive
(
freeMarkerConfig
,
sourceObj
,
source_table_name
,
envModel
);
}
//transform
if
(
mappingObj
.
size
()
>
0
&&
null
!=
mappingObj
)
{
...
...
@@ -184,7 +185,7 @@ public class SyncParameters extends AbstractParameters {
waterdropScript
=
FreeMarkerUtils
.
freemakerNoneWebJson
(
CommConstant
.
WATERDROP_FTL
,
waterdropModel
,
freeMarkerConfig
);
}
private
void
getSinkHive
(
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
Map
<
String
,
Object
>
sourceObj
,
String
source_table_name
,
Map
<
String
,
String
>
envModel
)
{
private
void
getSinkHive
(
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
Map
<
String
,
Object
>
sourceObj
,
String
source_table_name
,
Map
<
String
,
String
>
envModel
)
{
Map
hiveModel
=
new
HashMap
();
hiveModel
.
put
(
"pre_sql"
,
" select * from "
+
source_table_name
);
hiveModel
.
put
(
"result_table_name"
,
source_table_name
);
...
...
@@ -205,7 +206,7 @@ public class SyncParameters extends AbstractParameters {
env
=
FreeMarkerUtils
.
freemakerNoneWebJson
(
CommConstant
.
WATERDROP_FTL_ENV
,
envModel
,
freeMarkerConfig
);
}
private
void
getSinkKudu
(
DmpSyncingDatasource
targetDatasource
,
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
String
source_table_name
)
{
private
void
getSinkKudu
(
DmpSyncingDatasource
targetDatasource
,
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
String
source_table_name
)
{
Map
kuduModel
=
new
HashMap
();
kuduModel
.
put
(
"kuduMaster"
,
targetDatasource
.
getHost
()
+
":"
+
targetDatasource
.
getPort
());
//主机名
kuduModel
.
put
(
"result_table_name"
,
source_table_name
);
//spark生成的临时表名
...
...
@@ -220,7 +221,7 @@ public class SyncParameters extends AbstractParameters {
source
=
source
+
FreeMarkerUtils
.
freemakerNoneWebJson
(
CommConstant
.
WATERDROP_FTL_SINK_KUDU
,
kuduModel
,
freeMarkerConfig
);
}
private
void
getSinkSftp
(
DmpSyncingDatasource
targetDatasource
,
String
publicKey
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
String
source_table_name
)
{
private
void
getSinkSftp
(
DmpSyncingDatasource
targetDatasource
,
String
publicKey
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
String
source_table_name
)
{
Map
sftpModel
=
new
HashMap
();
sftpModel
.
put
(
"host"
,
targetDatasource
.
getHost
());
//主机名
sftpModel
.
put
(
"user"
,
targetDatasource
.
getUserName
());
//用户
...
...
@@ -324,9 +325,10 @@ public class SyncParameters extends AbstractParameters {
}
//sink
public
void
getJdbcSink
(
DmpSyncingDatasource
targetDatasource
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
String
publicKey
,
String
source_table_name
)
{
public
void
getJdbcSink
(
DmpSyncingDatasource
targetDatasource
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurationFactoryBean
freeMarkerConfig
,
String
publicKey
,
String
source_table_name
,
List
<
Map
<
String
,
Object
>>
mappingObj
)
{
String
postImportStatement
=
String
.
valueOf
(
targetObj
.
get
(
"postImportStatement"
));
//导入后语句
String
preImportStatement
=
String
.
valueOf
(
targetObj
.
get
(
"preImportStatement"
));
//导入前语句
String
targetTable
=
String
.
valueOf
(
targetObj
.
get
(
"targetTable"
));
//目标表
preStatements
=
new
ArrayList
<
String
>();
preStatements
.
add
(
preImportStatement
);
posStatements
=
new
ArrayList
<
String
>();
...
...
@@ -340,20 +342,43 @@ public class SyncParameters extends AbstractParameters {
targetBaseDataSource
.
setPassword
(
password
);
targetBaseDataSource
.
setMyDbType
(
myDbType
);
String
saveMode
=
"append"
;
String
primaryKeyConflict
=
""
;
if
(
StringUtils
.
isNotEmpty
(
String
.
valueOf
(
targetObj
.
get
(
"primaryKeyConflict"
))))
{
primaryKeyConflict
=
String
.
valueOf
(
targetObj
.
get
(
"primaryKeyConflict"
));
}
if
(
myDbType
.
PostgreSQL
==
myDbType
){
String
pgSqlWriteMode
=
String
.
valueOf
(
targetObj
.
get
(
"pgSqlWriteMode"
));
//pgsql 导入模式
if
(
StringUtils
.
isNotEmpty
(
pgSqlWriteMode
))
{
saveMode
=
pgSqlWriteMode
;
}
}
if
(
CommConstant
.
PRIMARY_KEY_CONFLICT_REPLACE
.
equals
(
primaryKeyConflict
)
||
CommConstant
.
PRIMARY_KEY_CONFLICT_UPDATE
.
equals
(
primaryKeyConflict
))
{
saveMode
=
"update"
;
}
Map
jdbcSinkModel
=
new
HashMap
();
jdbcSinkModel
.
put
(
"driver"
,
targetDatasource
.
getDriverClassName
());
jdbcSinkModel
.
put
(
"url"
,
targetDatasource
.
getJdbcUrl
());
//存储模式,支持overwrite、append、update、ignore、error
//在save_mode指定为update时配置,用于指定键冲突的更新语句模板
jdbcSinkModel
.
put
(
"save_mode"
,
targetObj
.
get
(
"primaryKeyConflict"
)
);
jdbcSinkModel
.
put
(
"save_mode"
,
saveMode
);
//当存储模式是 overwrite时,仅清除表中数据
if
(
null
!=
targetObj
.
get
(
"primaryKeyConflict"
))
{
//主键冲突
if
(
"overwrite"
.
equals
(
targetObj
.
get
(
"primaryKeyConflict"
)
))
{
if
(
StringUtils
.
isNotEmpty
(
primaryKeyConflict
))
{
//主键冲突
if
(
"overwrite"
.
equals
(
primaryKeyConflict
))
{
jdbcSinkModel
.
put
(
"truncate"
,
"true"
);
}
else
{
jdbcSinkModel
.
put
(
"truncate"
,
"false"
);
}
}
if
(
"update"
.
equals
(
saveMode
))
{
String
customUpdateStmt
=
ParameterUtils
.
syncColumnMappingHandlerConflict
(
targetTable
,
mappingObj
,
myDbType
,
targetObj
);
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotEmpty
(
customUpdateStmt
))
{
jdbcSinkModel
.
put
(
"customUpdateStmt"
,
customUpdateStmt
);
}
}
jdbcSinkModel
.
put
(
"driver"
,
targetDatasource
.
getDriverClassName
());
jdbcSinkModel
.
put
(
"url"
,
targetDatasource
.
getJdbcUrl
());
jdbcSinkModel
.
put
(
"dbtable"
,
targetObj
.
get
(
"targetTable"
));
//目标表
jdbcSinkModel
.
put
(
"user"
,
targetDatasource
.
getUserName
());
jdbcSinkModel
.
put
(
"password"
,
password
);
...
...
src/main/java/com/jz/dmp/cmdexectool/scheduler/common/utils/ParameterUtils.java
View file @
eda389b1
This diff is collapsed.
Click to expand it.
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