Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
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
wangpeng
dinky
Commits
7a4bf38b
Unverified
Commit
7a4bf38b
authored
Nov 04, 2022
by
ZackYoung
Committed by
GitHub
Nov 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix][UDF]修复udf重构后,导致session模式无法使用udf (#1199)
* 修复udf重构后,导致session模式无法使用udf * 修复udf重构后,导致session模式无法使用udf * 修复udf重构后,导致session模式无法使用udf
parent
c7a7f2c4
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
231 additions
and
196 deletions
+231
-196
pom.xml
dlink-admin/pom.xml
+0
-4
UDFService.java
dlink-admin/src/main/java/com/dlink/service/UDFService.java
+3
-9
StudioServiceImpl.java
...c/main/java/com/dlink/service/impl/StudioServiceImpl.java
+45
-45
TaskServiceImpl.java
...src/main/java/com/dlink/service/impl/TaskServiceImpl.java
+2
-4
UDFServiceImpl.java
.../src/main/java/com/dlink/service/impl/UDFServiceImpl.java
+6
-68
Dialect.java
dlink-common/src/main/java/com/dlink/config/Dialect.java
+1
-1
pom.xml
dlink-core/pom.xml
+4
-0
JobConfig.java
dlink-core/src/main/java/com/dlink/job/JobConfig.java
+34
-18
JobManager.java
dlink-core/src/main/java/com/dlink/job/JobManager.java
+75
-32
pom.xml
dlink-function/pom.xml
+17
-9
FunctionFactory.java
...ion/src/main/java/com/dlink/function/FunctionFactory.java
+6
-5
JVMPackage.java
...src/main/java/com/dlink/function/compiler/JVMPackage.java
+1
-1
UDFPath.java
.../src/main/java/com/dlink/function/data/model/UDFPath.java
+4
-0
UDFUtil.java
...nction/src/main/java/com/dlink/function/util/UDFUtil.java
+33
-0
No files found.
dlink-admin/pom.xml
View file @
7a4bf38b
...
...
@@ -145,10 +145,6 @@
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-function
</artifactId>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-common
</artifactId>
...
...
dlink-admin/src/main/java/com/dlink/service/UDFService.java
View file @
7a4bf38b
...
...
@@ -19,8 +19,6 @@
package
com
.
dlink
.
service
;
import
com.dlink.executor.Executor
;
import
com.dlink.gateway.GatewayType
;
import
com.dlink.job.JobConfig
;
/**
...
...
@@ -30,12 +28,8 @@ import com.dlink.job.JobConfig;
public
interface
UDFService
{
/**
*
* @param statement sql语句
* @param gatewayType flink 网关提交类型
* @param missionId 任务id
* @param executor flink执行器
* @param config job配置
* @param statement sql语句
* @param config job配置
*/
void
init
UDF
(
String
statement
,
GatewayType
gatewayType
,
Integer
missionId
,
Executor
executor
,
JobConfig
config
);
void
init
(
String
statement
,
JobConfig
config
);
}
dlink-admin/src/main/java/com/dlink/service/impl/StudioServiceImpl.java
View file @
7a4bf38b
...
...
@@ -31,7 +31,6 @@ import com.dlink.dto.StudioExecuteDTO;
import
com.dlink.dto.StudioMetaStoreDTO
;
import
com.dlink.explainer.lineage.LineageBuilder
;
import
com.dlink.explainer.lineage.LineageResult
;
import
com.dlink.gateway.GatewayType
;
import
com.dlink.gateway.model.JobInfo
;
import
com.dlink.gateway.result.SavePointResult
;
import
com.dlink.job.JobConfig
;
...
...
@@ -168,9 +167,9 @@ public class StudioServiceImpl implements StudioService {
public
JobResult
executeSql
(
StudioExecuteDTO
studioExecuteDTO
)
{
if
(
Dialect
.
notFlinkSql
(
studioExecuteDTO
.
getDialect
()))
{
return
executeCommonSql
(
SqlDTO
.
build
(
studioExecuteDTO
.
getStatement
(),
studioExecuteDTO
.
getDatabaseId
(),
studioExecuteDTO
.
getMaxRowNum
()));
studioExecuteDTO
.
getStatement
(),
studioExecuteDTO
.
getDatabaseId
(),
studioExecuteDTO
.
getMaxRowNum
()));
}
else
{
return
executeFlinkSql
(
studioExecuteDTO
);
}
...
...
@@ -180,10 +179,10 @@ public class StudioServiceImpl implements StudioService {
addFlinkSQLEnv
(
studioExecuteDTO
);
JobConfig
config
=
studioExecuteDTO
.
getJobConfig
();
buildSession
(
config
);
JobManager
jobManager
=
JobManager
.
build
(
config
);
// init UDF
udfService
.
init
(
studioExecuteDTO
.
getStatement
(),
config
);
// initUDF
udfService
.
initUDF
(
studioExecuteDTO
.
getStatement
(),
GatewayType
.
get
(
config
.
getType
()),
studioExecuteDTO
.
getTaskId
(),
jobManager
.
getExecutor
(),
config
);
JobManager
jobManager
=
JobManager
.
build
(
config
);
JobResult
jobResult
=
jobManager
.
executeSql
(
studioExecuteDTO
.
getStatement
());
RunTimeUtil
.
recovery
(
jobManager
);
...
...
@@ -240,7 +239,7 @@ public class StudioServiceImpl implements StudioService {
JobConfig
config
=
studioDDLDTO
.
getJobConfig
();
if
(!
config
.
isUseSession
())
{
config
.
setAddress
(
clusterService
.
buildEnvironmentAddress
(
config
.
isUseRemote
(),
studioDDLDTO
.
getClusterId
()));
clusterService
.
buildEnvironmentAddress
(
config
.
isUseRemote
(),
studioDDLDTO
.
getClusterId
()));
}
JobManager
jobManager
=
JobManager
.
build
(
config
);
return
jobManager
.
executeDDL
(
studioDDLDTO
.
getStatement
());
...
...
@@ -257,7 +256,7 @@ public class StudioServiceImpl implements StudioService {
private
List
<
SqlExplainResult
>
explainFlinkSql
(
StudioExecuteDTO
studioExecuteDTO
)
{
ProcessEntity
process
=
ProcessContextHolder
.
registerProcess
(
ProcessEntity
.
init
(
ProcessType
.
FLINKEXPLAIN
,
SaManager
.
getStpLogic
(
null
).
getLoginIdAsInt
(),
"admin"
));
ProcessEntity
.
init
(
ProcessType
.
FLINKEXPLAIN
,
SaManager
.
getStpLogic
(
null
).
getLoginIdAsInt
(),
"admin"
));
addFlinkSQLEnv
(
studioExecuteDTO
);
...
...
@@ -269,13 +268,13 @@ public class StudioServiceImpl implements StudioService {
process
.
infoSuccess
();
process
.
start
();
JobManager
jobManager
=
JobManager
.
buildPlanMode
(
config
);
// init UDF
udfService
.
init
(
studioExecuteDTO
.
getStatement
(),
config
);
// initUDF
udfService
.
initUDF
(
studioExecuteDTO
.
getStatement
(),
GatewayType
.
get
(
config
.
getType
()),
studioExecuteDTO
.
getTaskId
(),
jobManager
.
getExecutor
(),
config
);
JobManager
jobManager
=
JobManager
.
build
(
config
);
List
<
SqlExplainResult
>
sqlExplainResults
=
jobManager
.
explainSql
(
studioExecuteDTO
.
getStatement
()).
getSqlExplainResults
();
jobManager
.
explainSql
(
studioExecuteDTO
.
getStatement
()).
getSqlExplainResults
();
process
.
finish
();
return
sqlExplainResults
;
}
...
...
@@ -313,10 +312,10 @@ public class StudioServiceImpl implements StudioService {
// If you are using explainSql | getStreamGraph | getJobPlan, make the dialect change to local.
config
.
buildLocal
();
buildSession
(
config
);
JobManager
jobManager
=
JobManager
.
buildPlanMode
(
config
);
// init UDF
udfService
.
init
(
studioExecuteDTO
.
getStatement
(),
config
);
// initUDF
udfService
.
initUDF
(
studioExecuteDTO
.
getStatement
(),
GatewayType
.
get
(
config
.
getType
()),
studioExecuteDTO
.
getTaskId
(),
jobManager
.
getExecutor
(),
config
);
JobManager
jobManager
=
JobManager
.
build
(
config
);
String
planJson
=
jobManager
.
getJobPlanJson
(
studioExecuteDTO
.
getStatement
());
ObjectMapper
mapper
=
new
ObjectMapper
();
...
...
@@ -340,15 +339,15 @@ public class StudioServiceImpl implements StudioService {
if
(
sessionDTO
.
isUseRemote
())
{
Cluster
cluster
=
clusterService
.
getById
(
sessionDTO
.
getClusterId
());
SessionConfig
sessionConfig
=
SessionConfig
.
build
(
sessionDTO
.
getType
(),
true
,
cluster
.
getId
(),
cluster
.
getAlias
(),
clusterService
.
buildEnvironmentAddress
(
true
,
sessionDTO
.
getClusterId
()));
sessionDTO
.
getType
(),
true
,
cluster
.
getId
(),
cluster
.
getAlias
(),
clusterService
.
buildEnvironmentAddress
(
true
,
sessionDTO
.
getClusterId
()));
return
JobManager
.
createSession
(
sessionDTO
.
getSession
(),
sessionConfig
,
createUser
);
}
else
{
SessionConfig
sessionConfig
=
SessionConfig
.
build
(
sessionDTO
.
getType
(),
false
,
null
,
null
,
clusterService
.
buildEnvironmentAddress
(
false
,
null
));
sessionDTO
.
getType
(),
false
,
null
,
null
,
clusterService
.
buildEnvironmentAddress
(
false
,
null
));
return
JobManager
.
createSession
(
sessionDTO
.
getSession
(),
sessionConfig
,
createUser
);
}
}
...
...
@@ -366,7 +365,7 @@ public class StudioServiceImpl implements StudioService {
@Override
public
LineageResult
getLineage
(
StudioCADTO
studioCADTO
)
{
if
(
Asserts
.
isNotNullString
(
studioCADTO
.
getDialect
())
&&
!
studioCADTO
.
getDialect
().
equalsIgnoreCase
(
"flinksql"
))
{
&&
!
studioCADTO
.
getDialect
().
equalsIgnoreCase
(
"flinksql"
))
{
if
(
Asserts
.
isNull
(
studioCADTO
.
getDatabaseId
()))
{
return
null
;
}
...
...
@@ -376,10 +375,10 @@ public class StudioServiceImpl implements StudioService {
}
if
(
studioCADTO
.
getDialect
().
equalsIgnoreCase
(
"doris"
))
{
return
com
.
dlink
.
explainer
.
sqllineage
.
LineageBuilder
.
getSqlLineage
(
studioCADTO
.
getStatement
(),
"mysql"
,
dataBase
.
getDriverConfig
());
dataBase
.
getDriverConfig
());
}
else
{
return
com
.
dlink
.
explainer
.
sqllineage
.
LineageBuilder
.
getSqlLineage
(
studioCADTO
.
getStatement
(),
studioCADTO
.
getDialect
().
toLowerCase
(),
dataBase
.
getDriverConfig
());
studioCADTO
.
getDialect
().
toLowerCase
(),
dataBase
.
getDriverConfig
());
}
}
else
{
addFlinkSQLEnv
(
studioCADTO
);
...
...
@@ -411,7 +410,7 @@ public class StudioServiceImpl implements StudioService {
jobConfig
.
setAddress
(
cluster
.
getJobManagerHost
());
if
(
Asserts
.
isNotNull
(
cluster
.
getClusterConfigurationId
()))
{
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
getGatewayConfig
(
cluster
.
getClusterConfigurationId
());
clusterConfigurationService
.
getGatewayConfig
(
cluster
.
getClusterConfigurationId
());
jobConfig
.
buildGatewayConfig
(
gatewayConfig
);
}
JobManager
jobManager
=
JobManager
.
build
(
jobConfig
);
...
...
@@ -429,7 +428,8 @@ public class StudioServiceImpl implements StudioService {
jobConfig
.
setType
(
cluster
.
getType
());
if
(
Asserts
.
isNotNull
(
cluster
.
getClusterConfigurationId
()))
{
// 如果用户选择用dlink平台来托管集群信息 说明任务一定是从dlink发起提交的
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
getGatewayConfig
(
cluster
.
getClusterConfigurationId
());
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
getGatewayConfig
(
cluster
.
getClusterConfigurationId
());
jobConfig
.
buildGatewayConfig
(
gatewayConfig
);
jobConfig
.
getGatewayConfig
().
getClusterConfig
().
setAppId
(
cluster
.
getName
());
jobConfig
.
setTaskId
(
cluster
.
getTaskId
());
...
...
@@ -480,14 +480,14 @@ public class StudioServiceImpl implements StudioService {
if
(
result
instanceof
DDLResult
)
{
DDLResult
ddlResult
=
(
DDLResult
)
result
;
ddlResult
.
getColumns
().
stream
().
findFirst
().
ifPresent
(
key
->
{
for
(
Map
<
String
,
Object
>
item
:
ddlResult
.
getRowData
())
{
catalogs
.
add
(
Catalog
.
build
(
item
.
get
(
key
).
toString
()));
}
for
(
Map
<
String
,
Object
>
item
:
ddlResult
.
getRowData
())
{
catalogs
.
add
(
Catalog
.
build
(
item
.
get
(
key
).
toString
()));
}
);
}
);
for
(
Catalog
catalog
:
catalogs
)
{
String
statement
=
FlinkQuery
.
useCatalog
(
catalog
.
getName
())
+
FlinkQuery
.
separator
()
+
FlinkQuery
.
showDatabases
();
String
statement
=
FlinkQuery
.
useCatalog
(
catalog
.
getName
())
+
FlinkQuery
.
separator
()
+
FlinkQuery
.
showDatabases
();
studioMetaStoreDTO
.
setStatement
(
statement
);
IResult
tableResult
=
executeMSFlinkSql
(
studioMetaStoreDTO
);
DDLResult
tableDDLResult
=
(
DDLResult
)
tableResult
;
...
...
@@ -517,9 +517,9 @@ public class StudioServiceImpl implements StudioService {
}
}
else
{
String
baseStatement
=
FlinkQuery
.
useCatalog
(
studioMetaStoreDTO
.
getCatalog
())
+
FlinkQuery
.
separator
()
+
FlinkQuery
.
useDatabase
(
studioMetaStoreDTO
.
getDatabase
())
+
FlinkQuery
.
separator
();
+
FlinkQuery
.
separator
()
+
FlinkQuery
.
useDatabase
(
studioMetaStoreDTO
.
getDatabase
())
+
FlinkQuery
.
separator
();
// show tables
String
tableStatement
=
baseStatement
+
FlinkQuery
.
showTables
();
...
...
@@ -554,10 +554,10 @@ public class StudioServiceImpl implements StudioService {
List
<
FlinkColumn
>
columns
=
new
ArrayList
<>();
if
(!
Dialect
.
notFlinkSql
(
studioMetaStoreDTO
.
getDialect
()))
{
String
baseStatement
=
FlinkQuery
.
useCatalog
(
studioMetaStoreDTO
.
getCatalog
())
+
FlinkQuery
.
separator
()
+
FlinkQuery
.
useDatabase
(
studioMetaStoreDTO
.
getDatabase
())
+
FlinkQuery
.
separator
();
studioMetaStoreDTO
.
getCatalog
())
+
FlinkQuery
.
separator
()
+
FlinkQuery
.
useDatabase
(
studioMetaStoreDTO
.
getDatabase
())
+
FlinkQuery
.
separator
();
// desc tables
String
tableStatement
=
baseStatement
+
FlinkQuery
.
descTable
(
studioMetaStoreDTO
.
getTable
());
...
...
@@ -569,12 +569,12 @@ public class StudioServiceImpl implements StudioService {
int
i
=
1
;
for
(
Map
<
String
,
Object
>
item
:
rowData
)
{
FlinkColumn
column
=
FlinkColumn
.
build
(
i
,
item
.
get
(
FlinkQuery
.
columnName
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnType
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnKey
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnNull
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnExtras
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnWatermark
()).
toString
());
item
.
get
(
FlinkQuery
.
columnName
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnType
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnKey
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnNull
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnExtras
()).
toString
(),
item
.
get
(
FlinkQuery
.
columnWatermark
()).
toString
());
columns
.
add
(
column
);
i
++;
}
...
...
dlink-admin/src/main/java/com/dlink/service/impl/TaskServiceImpl.java
View file @
7a4bf38b
...
...
@@ -209,12 +209,10 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
task
.
getDatabaseId
(),
null
));
}
JobConfig
config
=
buildJobConfig
(
task
);
// init UDF
udfService
.
init
(
task
.
getStatement
(),
config
);
JobManager
jobManager
=
JobManager
.
build
(
config
);
// initUDF
udfService
.
initUDF
(
task
.
getStatement
(),
GatewayType
.
get
(
config
.
getType
()),
id
,
jobManager
.
getExecutor
(),
config
);
if
(!
config
.
isJarTask
())
{
return
jobManager
.
executeSql
(
task
.
getStatement
());
}
else
{
...
...
dlink-admin/src/main/java/com/dlink/service/impl/UDFServiceImpl.java
View file @
7a4bf38b
...
...
@@ -19,32 +19,12 @@
package
com
.
dlink
.
service
.
impl
;
import
com.dlink.exception.BusException
;
import
com.dlink.executor.Executor
;
import
com.dlink.function.FunctionFactory
;
import
com.dlink.function.data.model.Env
;
import
com.dlink.function.data.model.UDF
;
import
com.dlink.function.data.model.UDFPath
;
import
com.dlink.gateway.GatewayType
;
import
com.dlink.job.JobConfig
;
import
com.dlink.process.context.ProcessContextHolder
;
import
com.dlink.process.model.ProcessEntity
;
import
com.dlink.service.TaskService
;
import
com.dlink.service.UDFService
;
import
com.dlink.utils.UDFUtils
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
javax.annotation.Resource
;
import
org.springframework.stereotype.Service
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.ArrayUtil
;
/**
* @author ZackYoung
* @since 0.6.8
...
...
@@ -52,56 +32,14 @@ import cn.hutool.core.util.ArrayUtil;
@Service
public
class
UDFServiceImpl
implements
UDFService
{
private
static
final
String
YARN
=
"YARN"
;
private
static
final
String
APPLICATION
=
"APPLICATION"
;
/**
* 网关类型 map
* 快速获取 session 与 application 等类型,为了减少判断
*/
private
static
final
Map
<
String
,
List
<
GatewayType
>>
GATEWAY_TYPE_MAP
=
MapUtil
.
builder
(
"session"
,
Arrays
.
asList
(
GatewayType
.
YARN_SESSION
,
GatewayType
.
KUBERNETES_SESSION
,
GatewayType
.
STANDALONE
))
.
put
(
YARN
,
Arrays
.
asList
(
GatewayType
.
YARN_APPLICATION
,
GatewayType
.
YARN_PER_JOB
))
.
put
(
APPLICATION
,
Arrays
.
asList
(
GatewayType
.
YARN_APPLICATION
,
GatewayType
.
KUBERNETES_APPLICATION
))
.
build
();
@Resource
TaskService
taskService
;
/**
* @param statement sql语句
* @param gatewayType flink 网关提交类型
* @param missionId 任务id
* @param executor flink执行器
* @param config job配置
* 获取所有udf相关的代码
*
* @param statement sql语句
* @return jobManage
*/
@Override
public
void
initUDF
(
String
statement
,
GatewayType
gatewayType
,
Integer
missionId
,
Executor
executor
,
JobConfig
config
)
{
ProcessEntity
process
=
ProcessContextHolder
.
getProcess
();
process
.
info
(
"Initializing Flink UDF...Start"
);
List
<
UDF
>
udf
=
UDFUtils
.
getUDF
(
statement
);
if
(
CollUtil
.
isNotEmpty
(
udf
))
{
if
(
gatewayType
==
GatewayType
.
KUBERNETES_APPLICATION
)
{
throw
new
BusException
(
"udf 暂不支持k8s application"
);
}
}
else
{
return
;
}
UDFPath
udfPath
=
FunctionFactory
.
initUDF
(
udf
,
missionId
,
executor
);
executor
.
initUDF
(
udfPath
.
getJarPaths
());
executor
.
initPyUDF
(
Env
.
getPath
(),
udfPath
.
getPyPaths
());
//
if
(
GATEWAY_TYPE_MAP
.
get
(
YARN
).
contains
(
gatewayType
))
{
config
.
getGatewayConfig
().
setJarPaths
(
ArrayUtil
.
append
(
udfPath
.
getJarPaths
(),
udfPath
.
getPyPaths
()));
}
process
.
info
(
"Initializing Flink UDF...Finish"
);
public
void
init
(
String
statement
,
JobConfig
config
)
{
config
.
setUdfList
(
UDFUtils
.
getUDF
(
statement
));
}
}
dlink-co
re
/src/main/java/com/dlink/config/Dialect.java
→
dlink-co
mmon
/src/main/java/com/dlink/config/Dialect.java
View file @
7a4bf38b
...
...
@@ -28,6 +28,7 @@ import com.dlink.assertion.Asserts;
* @since 2021/12/13
**/
public
enum
Dialect
{
FLINKSQL
(
"FlinkSql"
),
FLINKJAR
(
"FlinkJar"
),
FLINKSQLENV
(
"FlinkSqlEnv"
),
...
...
@@ -110,4 +111,3 @@ public enum Dialect {
}
}
}
dlink-core/pom.xml
View file @
7a4bf38b
...
...
@@ -182,5 +182,9 @@
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-process
</artifactId>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-function
</artifactId>
</dependency>
</dependencies>
</project>
dlink-core/src/main/java/com/dlink/job/JobConfig.java
View file @
7a4bf38b
...
...
@@ -21,6 +21,7 @@ package com.dlink.job;
import
com.dlink.assertion.Asserts
;
import
com.dlink.executor.ExecutorSetting
;
import
com.dlink.function.data.model.UDF
;
import
com.dlink.gateway.GatewayType
;
import
com.dlink.gateway.config.AppConfig
;
import
com.dlink.gateway.config.ClusterConfig
;
...
...
@@ -64,6 +65,7 @@ public class JobConfig {
private
boolean
isJarTask
=
false
;
private
String
address
;
private
Integer
taskId
;
private
List
<
UDF
>
udfList
;
private
String
[]
jarFiles
;
private
String
[]
pyFiles
;
private
String
jobName
;
...
...
@@ -82,7 +84,8 @@ public class JobConfig {
public
JobConfig
()
{
}
public
JobConfig
(
String
type
,
boolean
useSession
,
boolean
useRemote
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
Integer
parallelism
,
Map
<
String
,
String
>
config
)
{
public
JobConfig
(
String
type
,
boolean
useSession
,
boolean
useRemote
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
Integer
parallelism
,
Map
<
String
,
String
>
config
)
{
this
.
type
=
type
;
this
.
useSession
=
useSession
;
this
.
useRemote
=
useRemote
;
...
...
@@ -92,10 +95,14 @@ public class JobConfig {
this
.
config
=
config
;
}
public
JobConfig
(
String
type
,
boolean
useResult
,
boolean
useChangeLog
,
boolean
useAutoCancel
,
boolean
useSession
,
String
session
,
Integer
clusterId
,
Integer
clusterConfigurationId
,
Integer
jarId
,
Integer
taskId
,
String
jobName
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
boolean
useBatchModel
,
Integer
maxRowNum
,
Integer
checkpoint
,
Integer
parallelism
,
Integer
savePointStrategyValue
,
String
savePointPath
,
Map
<
String
,
String
>
variables
,
Map
<
String
,
String
>
config
)
{
public
JobConfig
(
String
type
,
boolean
useResult
,
boolean
useChangeLog
,
boolean
useAutoCancel
,
boolean
useSession
,
String
session
,
Integer
clusterId
,
Integer
clusterConfigurationId
,
Integer
jarId
,
Integer
taskId
,
String
jobName
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
boolean
useBatchModel
,
Integer
maxRowNum
,
Integer
checkpoint
,
Integer
parallelism
,
Integer
savePointStrategyValue
,
String
savePointPath
,
Map
<
String
,
String
>
variables
,
Map
<
String
,
String
>
config
)
{
this
.
type
=
type
;
this
.
useResult
=
useResult
;
this
.
useChangeLog
=
useChangeLog
;
...
...
@@ -120,10 +127,12 @@ public class JobConfig {
this
.
config
=
config
;
}
public
JobConfig
(
String
type
,
boolean
useResult
,
boolean
useChangeLog
,
boolean
useAutoCancel
,
boolean
useSession
,
String
session
,
boolean
useRemote
,
String
address
,
public
JobConfig
(
String
type
,
boolean
useResult
,
boolean
useChangeLog
,
boolean
useAutoCancel
,
boolean
useSession
,
String
session
,
boolean
useRemote
,
String
address
,
String
jobName
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
Integer
maxRowNum
,
Integer
checkpoint
,
Integer
parallelism
,
Integer
savePointStrategyValue
,
String
savePointPath
,
Map
<
String
,
String
>
config
,
GatewayConfig
gatewayConfig
)
{
Integer
savePointStrategyValue
,
String
savePointPath
,
Map
<
String
,
String
>
config
,
GatewayConfig
gatewayConfig
)
{
this
.
type
=
type
;
this
.
useResult
=
useResult
;
this
.
useChangeLog
=
useChangeLog
;
...
...
@@ -144,7 +153,8 @@ public class JobConfig {
this
.
gatewayConfig
=
gatewayConfig
;
}
public
JobConfig
(
String
type
,
boolean
useResult
,
boolean
useSession
,
String
session
,
boolean
useRemote
,
Integer
clusterId
,
Integer
maxRowNum
)
{
public
JobConfig
(
String
type
,
boolean
useResult
,
boolean
useSession
,
String
session
,
boolean
useRemote
,
Integer
clusterId
,
Integer
maxRowNum
)
{
this
.
type
=
type
;
this
.
useResult
=
useResult
;
this
.
useSession
=
useSession
;
...
...
@@ -154,9 +164,12 @@ public class JobConfig {
this
.
maxRowNum
=
maxRowNum
;
}
public
JobConfig
(
String
type
,
Integer
step
,
boolean
useResult
,
boolean
useSession
,
boolean
useRemote
,
Integer
clusterId
,
Integer
clusterConfigurationId
,
Integer
jarId
,
Integer
taskId
,
String
jobName
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
boolean
useBatchModel
,
Integer
checkpoint
,
Integer
parallelism
,
Integer
savePointStrategyValue
,
public
JobConfig
(
String
type
,
Integer
step
,
boolean
useResult
,
boolean
useSession
,
boolean
useRemote
,
Integer
clusterId
,
Integer
clusterConfigurationId
,
Integer
jarId
,
Integer
taskId
,
String
jobName
,
boolean
useSqlFragment
,
boolean
useStatementSet
,
boolean
useBatchModel
,
Integer
checkpoint
,
Integer
parallelism
,
Integer
savePointStrategyValue
,
String
savePointPath
,
Map
<
String
,
String
>
config
)
{
this
.
type
=
type
;
this
.
step
=
step
;
...
...
@@ -179,7 +192,8 @@ public class JobConfig {
}
public
ExecutorSetting
getExecutorSetting
()
{
return
new
ExecutorSetting
(
checkpoint
,
parallelism
,
useSqlFragment
,
useStatementSet
,
useBatchModel
,
savePointPath
,
jobName
,
config
);
return
new
ExecutorSetting
(
checkpoint
,
parallelism
,
useSqlFragment
,
useStatementSet
,
useBatchModel
,
savePointPath
,
jobName
,
config
);
}
public
void
setSessionConfig
(
SessionConfig
sessionConfig
)
{
...
...
@@ -194,19 +208,20 @@ public class JobConfig {
gatewayConfig
=
new
GatewayConfig
();
if
(
config
.
containsKey
(
"hadoopConfigPath"
))
{
gatewayConfig
.
setClusterConfig
(
ClusterConfig
.
build
(
config
.
get
(
"flinkConfigPath"
).
toString
(),
config
.
get
(
"flinkLibPath"
).
toString
(),
config
.
get
(
"hadoopConfigPath"
).
toString
()));
config
.
get
(
"flinkLibPath"
).
toString
(),
config
.
get
(
"hadoopConfigPath"
).
toString
()));
}
else
{
gatewayConfig
.
setClusterConfig
(
ClusterConfig
.
build
(
config
.
get
(
"flinkConfigPath"
).
toString
()));
}
AppConfig
appConfig
=
new
AppConfig
();
if
(
config
.
containsKey
(
"userJarPath"
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
"userJarPath"
)))
{
appConfig
.
setUserJarPath
(
config
.
get
(
"userJarPath"
).
toString
());
if
(
config
.
containsKey
(
"userJarMainAppClass"
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
"userJarMainAppClass"
)))
{
if
(
config
.
containsKey
(
"userJarMainAppClass"
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
"userJarMainAppClass"
)))
{
appConfig
.
setUserJarMainAppClass
(
config
.
get
(
"userJarMainAppClass"
).
toString
());
}
if
(
config
.
containsKey
(
"userJarParas"
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
"userJarParas"
)))
{
//There may be multiple spaces between the parameter and value during user input,
//
There may be multiple spaces between the parameter and value during user input,
// which will directly lead to a parameter passing error and needs to be eliminated
String
[]
temp
=
config
.
get
(
"userJarParas"
).
toString
().
split
(
" "
);
List
<
String
>
paraSplit
=
new
ArrayList
<>();
...
...
@@ -219,12 +234,13 @@ public class JobConfig {
}
gatewayConfig
.
setAppConfig
(
appConfig
);
}
if
(
config
.
containsKey
(
"flinkConfig"
)
&&
Asserts
.
isNotNullMap
((
Map
<
String
,
String
>)
config
.
get
(
"flinkConfig"
)))
{
if
(
config
.
containsKey
(
"flinkConfig"
)
&&
Asserts
.
isNotNullMap
((
Map
<
String
,
String
>)
config
.
get
(
"flinkConfig"
)))
{
gatewayConfig
.
setFlinkConfig
(
FlinkConfig
.
build
((
Map
<
String
,
String
>)
config
.
get
(
"flinkConfig"
)));
}
if
(
config
.
containsKey
(
"kubernetesConfig"
))
{
Map
<
String
,
Object
>
kubernetesConfig
=
(
Map
<
String
,
Object
>)
config
.
get
(
"kubernetesConfig"
);
//构建GatewayConfig时,将k8s集群默认配置和自定义参数配置加载到FlinkConfig里
//
构建GatewayConfig时,将k8s集群默认配置和自定义参数配置加载到FlinkConfig里
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
kubernetesConfig
.
entrySet
())
{
gatewayConfig
.
getFlinkConfig
().
getConfiguration
().
put
(
entry
.
getKey
(),
entry
.
getValue
().
toString
());
}
...
...
dlink-core/src/main/java/com/dlink/job/JobManager.java
View file @
7a4bf38b
...
...
@@ -19,6 +19,10 @@
package
com
.
dlink
.
job
;
import
static
com
.
dlink
.
function
.
util
.
UDFUtil
.
GATEWAY_TYPE_MAP
;
import
static
com
.
dlink
.
function
.
util
.
UDFUtil
.
SESSION
;
import
static
com
.
dlink
.
function
.
util
.
UDFUtil
.
YARN
;
import
com.dlink.api.FlinkAPI
;
import
com.dlink.assertion.Asserts
;
import
com.dlink.constant.FlinkSQLConstant
;
...
...
@@ -26,6 +30,9 @@ import com.dlink.executor.EnvironmentSetting;
import
com.dlink.executor.Executor
;
import
com.dlink.executor.ExecutorSetting
;
import
com.dlink.explainer.Explainer
;
import
com.dlink.function.data.model.Env
;
import
com.dlink.function.data.model.UDF
;
import
com.dlink.function.util.UDFUtil
;
import
com.dlink.gateway.Gateway
;
import
com.dlink.gateway.GatewayType
;
import
com.dlink.gateway.config.ActionType
;
...
...
@@ -39,6 +46,7 @@ import com.dlink.interceptor.FlinkInterceptorResult;
import
com.dlink.model.SystemConfiguration
;
import
com.dlink.parser.SqlType
;
import
com.dlink.process.context.ProcessContextHolder
;
import
com.dlink.process.model.ProcessEntity
;
import
com.dlink.result.ErrorResult
;
import
com.dlink.result.ExplainResult
;
import
com.dlink.result.IResult
;
...
...
@@ -78,6 +86,9 @@ import org.slf4j.LoggerFactory;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ArrayUtil
;
/**
* JobManager
*
...
...
@@ -182,7 +193,7 @@ public class JobManager {
public
static
boolean
useGateway
(
String
type
)
{
return
(
GatewayType
.
YARN_PER_JOB
.
equalsValue
(
type
)
||
GatewayType
.
YARN_APPLICATION
.
equalsValue
(
type
)
||
GatewayType
.
KUBERNETES_APPLICATION
.
equalsValue
(
type
));
||
GatewayType
.
KUBERNETES_APPLICATION
.
equalsValue
(
type
));
}
private
Executor
createExecutor
()
{
...
...
@@ -217,7 +228,7 @@ public class JobManager {
private
void
initEnvironmentSetting
()
{
if
(
Asserts
.
isNotNullString
(
config
.
getAddress
()))
{
environmentSetting
=
EnvironmentSetting
.
build
(
config
.
getAddress
());
environmentSetting
=
EnvironmentSetting
.
build
(
config
.
getAddress
()
,
config
.
getJarFiles
()
);
}
}
...
...
@@ -234,11 +245,43 @@ public class JobManager {
useStatementSet
=
config
.
isUseStatementSet
();
useRestAPI
=
SystemConfiguration
.
getInstances
().
isUseRestAPI
();
sqlSeparator
=
SystemConfiguration
.
getInstances
().
getSqlSeparator
();
initExecutorSetting
();
createExecutorWithSession
();
initUDF
();
return
false
;
}
private
void
initUDF
()
{
ProcessEntity
process
=
ProcessContextHolder
.
getProcess
();
// 这里要分开
// 1. 得到jar包路径,注入remote环境
List
<
UDF
>
udfList
=
config
.
getUdfList
();
if
(
CollUtil
.
isEmpty
(
udfList
))
{
createExecutorWithSession
();
return
;
}
else
if
(
runMode
==
GatewayType
.
KUBERNETES_APPLICATION
)
{
throw
new
RuntimeException
(
"UDF 暂不支持k8s模式"
);
}
String
[]
jarPaths
=
UDFUtil
.
initJavaUDF
(
udfList
,
runMode
,
config
.
getTaskId
());
if
(
GATEWAY_TYPE_MAP
.
get
(
SESSION
).
contains
(
runMode
))
{
config
.
setJarFiles
(
jarPaths
);
}
// 2.实例化remote环境
createExecutorWithSession
();
// 3.编译python
String
[]
pyPaths
=
UDFUtil
.
initPythonUDF
(
udfList
,
runMode
,
config
.
getTaskId
(),
executor
.
getTableConfig
().
getConfiguration
());
executor
.
initUDF
(
jarPaths
);
executor
.
initPyUDF
(
Env
.
getPath
(),
pyPaths
);
if
(
GATEWAY_TYPE_MAP
.
get
(
YARN
).
contains
(
runMode
))
{
config
.
getGatewayConfig
().
setJarPaths
(
ArrayUtil
.
append
(
jarPaths
,
pyPaths
));
}
process
.
info
(
"Initializing Flink UDF...Finish"
);
}
private
boolean
ready
()
{
return
handler
.
init
();
}
...
...
@@ -265,7 +308,7 @@ public class JobManager {
ready
();
String
currentSql
=
""
;
JobParam
jobParam
=
Explainer
.
build
(
executor
,
useStatementSet
,
sqlSeparator
)
.
pretreatStatements
(
SqlUtil
.
getStatements
(
statement
,
sqlSeparator
));
.
pretreatStatements
(
SqlUtil
.
getStatements
(
statement
,
sqlSeparator
));
try
{
for
(
StatementParam
item
:
jobParam
.
getDdl
())
{
currentSql
=
item
.
getValue
();
...
...
@@ -310,10 +353,10 @@ public class JobManager {
if
(
config
.
isUseResult
())
{
// Build insert result.
IResult
result
=
ResultBuilder
.
build
(
SqlType
.
INSERT
,
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
())
.
getResult
(
tableResult
);
ResultBuilder
.
build
(
SqlType
.
INSERT
,
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
())
.
getResult
(
tableResult
);
job
.
setResult
(
result
);
}
}
...
...
@@ -334,13 +377,13 @@ public class JobManager {
for
(
StatementParam
item
:
jobParam
.
getTrans
())
{
currentSql
=
item
.
getValue
();
FlinkInterceptorResult
flinkInterceptorResult
=
FlinkInterceptor
.
build
(
executor
,
item
.
getValue
());
FlinkInterceptor
.
build
(
executor
,
item
.
getValue
());
if
(
Asserts
.
isNotNull
(
flinkInterceptorResult
.
getTableResult
()))
{
if
(
config
.
isUseResult
())
{
IResult
result
=
ResultBuilder
.
build
(
item
.
getType
(),
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
())
.
getResult
(
flinkInterceptorResult
.
getTableResult
());
.
build
(
item
.
getType
(),
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
())
.
getResult
(
flinkInterceptorResult
.
getTableResult
());
job
.
setResult
(
result
);
}
}
else
{
...
...
@@ -357,9 +400,9 @@ public class JobManager {
}
if
(
config
.
isUseResult
())
{
IResult
result
=
ResultBuilder
.
build
(
item
.
getType
(),
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
()).
getResult
(
tableResult
);
ResultBuilder
.
build
(
item
.
getType
(),
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
()).
getResult
(
tableResult
);
job
.
setResult
(
result
);
}
}
...
...
@@ -387,7 +430,7 @@ public class JobManager {
JobGraph
jobGraph
=
streamGraph
.
getJobGraph
();
if
(
Asserts
.
isNotNullString
(
config
.
getSavePointPath
()))
{
jobGraph
.
setSavepointRestoreSettings
(
SavepointRestoreSettings
.
forPath
(
config
.
getSavePointPath
(),
true
));
SavepointRestoreSettings
.
forPath
(
config
.
getSavePointPath
(),
true
));
}
gatewayResult
=
Gateway
.
build
(
config
.
getGatewayConfig
()).
submitJobGraph
(
jobGraph
);
}
...
...
@@ -414,8 +457,8 @@ public class JobManager {
}
if
(
config
.
isUseResult
())
{
IResult
result
=
ResultBuilder
.
build
(
SqlType
.
EXECUTE
,
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
()).
getResult
(
null
);
ResultBuilder
.
build
(
SqlType
.
EXECUTE
,
config
.
getMaxRowNum
(),
config
.
isUseChangeLog
(),
config
.
isUseAutoCancel
(),
executor
.
getTimeZone
()).
getResult
(
null
);
job
.
setResult
(
result
);
}
}
...
...
@@ -480,7 +523,7 @@ public class JobManager {
LocalDateTime
startTime
=
LocalDateTime
.
now
();
TableResult
tableResult
=
executor
.
executeSql
(
newStatement
);
result
=
ResultBuilder
.
build
(
operationType
,
config
.
getMaxRowNum
(),
false
,
false
,
executor
.
getTimeZone
())
.
getResult
(
tableResult
);
.
getResult
(
tableResult
);
result
.
setStartTime
(
startTime
);
}
return
result
;
...
...
@@ -501,12 +544,12 @@ public class JobManager {
Executor
sessionExecutor
=
null
;
if
(
sessionConfig
.
isUseRemote
())
{
sessionExecutor
=
Executor
.
buildRemoteExecutor
(
EnvironmentSetting
.
build
(
sessionConfig
.
getAddress
()),
ExecutorSetting
.
DEFAULT
);
ExecutorSetting
.
DEFAULT
);
}
else
{
sessionExecutor
=
Executor
.
buildLocalExecutor
(
sessionConfig
.
getExecutorSetting
());
}
ExecutorEntity
executorEntity
=
new
ExecutorEntity
(
session
,
sessionConfig
,
createUser
,
LocalDateTime
.
now
(),
sessionExecutor
);
new
ExecutorEntity
(
session
,
sessionConfig
,
createUser
,
LocalDateTime
.
now
(),
sessionExecutor
);
SessionPool
.
push
(
executorEntity
);
return
SessionInfo
.
build
(
executorEntity
);
}
...
...
@@ -530,7 +573,7 @@ public class JobManager {
public
boolean
cancel
(
String
jobId
)
{
if
(
useGateway
&&
!
useRestAPI
)
{
config
.
getGatewayConfig
().
setFlinkConfig
(
FlinkConfig
.
build
(
jobId
,
ActionType
.
CANCEL
.
getValue
(),
null
,
null
));
null
,
null
));
Gateway
.
build
(
config
.
getGatewayConfig
()).
savepointJob
();
return
true
;
}
else
{
...
...
@@ -546,7 +589,7 @@ public class JobManager {
public
SavePointResult
savepoint
(
String
jobId
,
String
savePointType
,
String
savePoint
)
{
if
(
useGateway
&&
!
useRestAPI
)
{
config
.
getGatewayConfig
().
setFlinkConfig
(
FlinkConfig
.
build
(
jobId
,
ActionType
.
SAVEPOINT
.
getValue
(),
savePointType
,
null
));
savePointType
,
null
));
return
Gateway
.
build
(
config
.
getGatewayConfig
()).
savepointJob
(
savePoint
);
}
else
{
return
FlinkAPI
.
build
(
config
.
getAddress
()).
savepoints
(
jobId
,
savePointType
);
...
...
@@ -568,7 +611,7 @@ public class JobManager {
success
();
}
catch
(
Exception
e
)
{
String
error
=
LogUtil
.
getError
(
"Exception in executing Jar:\n"
+
config
.
getGatewayConfig
().
getAppConfig
().
getUserJarPath
(),
e
);
"Exception in executing Jar:\n"
+
config
.
getGatewayConfig
().
getAppConfig
().
getUserJarPath
(),
e
);
job
.
setEndTime
(
LocalDateTime
.
now
());
job
.
setStatus
(
Job
.
JobStatus
.
FAILED
);
job
.
setError
(
error
);
...
...
@@ -594,15 +637,15 @@ public class JobManager {
}
if
(
Asserts
.
isNotNull
(
config
.
getCheckpoint
()))
{
sb
.
append
(
"set "
+
ExecutionCheckpointingOptions
.
CHECKPOINTING_INTERVAL
.
key
()
+
" = "
+
config
.
getCheckpoint
()
+
";\r\n"
);
+
config
.
getCheckpoint
()
+
";\r\n"
);
}
if
(
Asserts
.
isNotNullString
(
config
.
getSavePointPath
()))
{
sb
.
append
(
"set "
+
SavepointConfigOptions
.
SAVEPOINT_PATH
+
" = "
+
config
.
getSavePointPath
()
+
";\r\n"
);
}
if
(
Asserts
.
isNotNull
(
config
.
getGatewayConfig
())
&&
Asserts
.
isNotNull
(
config
.
getGatewayConfig
().
getFlinkConfig
().
getConfiguration
()))
{
&&
Asserts
.
isNotNull
(
config
.
getGatewayConfig
().
getFlinkConfig
().
getConfiguration
()))
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
config
.
getGatewayConfig
().
getFlinkConfig
().
getConfiguration
()
.
entrySet
())
{
.
entrySet
())
{
sb
.
append
(
"set "
+
entry
.
getKey
()
+
" = "
+
entry
.
getValue
()
+
";\r\n"
);
}
}
...
...
@@ -611,16 +654,16 @@ public class JobManager {
case
YARN_PER_JOB:
case
YARN_APPLICATION:
sb
.
append
(
"set "
+
DeploymentOptions
.
TARGET
.
key
()
+
" = "
+
GatewayType
.
get
(
config
.
getType
()).
getLongValue
()
+
";\r\n"
);
+
GatewayType
.
get
(
config
.
getType
()).
getLongValue
()
+
";\r\n"
);
if
(
Asserts
.
isNotNull
(
config
.
getGatewayConfig
()))
{
sb
.
append
(
"set "
+
YarnConfigOptions
.
PROVIDED_LIB_DIRS
.
key
()
+
" = "
+
Collections
.
singletonList
(
config
.
getGatewayConfig
().
getClusterConfig
().
getFlinkLibPath
())
+
";\r\n"
);
+
Collections
.
singletonList
(
config
.
getGatewayConfig
().
getClusterConfig
().
getFlinkLibPath
())
+
";\r\n"
);
}
if
(
Asserts
.
isNotNull
(
config
.
getGatewayConfig
())
&&
Asserts
.
isNotNullString
(
config
.
getGatewayConfig
().
getFlinkConfig
().
getJobName
()))
{
&&
Asserts
.
isNotNullString
(
config
.
getGatewayConfig
().
getFlinkConfig
().
getJobName
()))
{
sb
.
append
(
"set "
+
YarnConfigOptions
.
APPLICATION_NAME
.
key
()
+
" = "
+
config
.
getGatewayConfig
().
getFlinkConfig
().
getJobName
()
+
";\r\n"
);
+
config
.
getGatewayConfig
().
getFlinkConfig
().
getJobName
()
+
";\r\n"
);
}
break
;
default
:
...
...
dlink-function/pom.xml
View file @
7a4bf38b
...
...
@@ -15,16 +15,14 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<artifactId>
dlink
</artifactId>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink
</artifactId>
<version>
0.6.8-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
dlink-function
</artifactId>
...
...
@@ -46,14 +44,25 @@
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-
core
</artifactId>
<artifactId>
dlink-
gateway
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-executor
</artifactId>
<artifactId>
dlink-process
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.codehaus.groovy
</groupId>
<artifactId>
groovy
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
dlink-function/src/main/java/com/dlink/function/FunctionFactory.java
View file @
7a4bf38b
...
...
@@ -19,12 +19,13 @@
package
com
.
dlink
.
function
;
import
com.dlink.executor.Executor
;
import
com.dlink.function.compiler.FunctionCompiler
;
import
com.dlink.function.compiler.FunctionPackage
;
import
com.dlink.function.data.model.UDF
;
import
com.dlink.function.data.model.UDFPath
;
import
org.apache.flink.configuration.Configuration
;
import
java.util.List
;
/**
...
...
@@ -35,15 +36,15 @@ public class FunctionFactory {
/**
* udf编译 & 打包 初始化
*
* @param udfClassList udf列表
* @param missionId 当前任务id
* @param executor flink执行器
* @param missionId 当前任务id
* @return 打包过后的路径
*/
public
static
UDFPath
initUDF
(
List
<
UDF
>
udfClassList
,
Integer
missionId
,
Executor
executor
)
{
public
static
UDFPath
initUDF
(
List
<
UDF
>
udfClassList
,
Integer
missionId
,
Configuration
configuration
)
{
// 编译
FunctionCompiler
.
getCompiler
(
udfClassList
,
executor
.
getTableConfig
().
getConfiguration
()
,
missionId
);
FunctionCompiler
.
getCompiler
(
udfClassList
,
configuration
,
missionId
);
// 打包
return
FunctionPackage
.
bale
(
udfClassList
,
missionId
);
...
...
dlink-function/src/main/java/com/dlink/function/compiler/JVMPackage.java
View file @
7a4bf38b
...
...
@@ -66,7 +66,7 @@ public class JVMPackage implements FunctionPackage {
fileInputStreams
[
i
]
=
FileUtil
.
getInputStream
(
absoluteFilePath
);
}
String
jarPath
=
PathConstant
.
getUdfPackagePath
(
missionId
,
PathConstant
.
UDF_JAR_NAME
)
;
String
jarPath
=
PathConstant
.
getUdfPackagePath
(
missionId
)
+
PathConstant
.
UDF_JAR_NAME
;
// 编译好的文件打包jar
File
file
=
FileUtil
.
file
(
jarPath
);
FileUtil
.
del
(
file
);
...
...
dlink-function/src/main/java/com/dlink/function/data/model/UDFPath.java
View file @
7a4bf38b
...
...
@@ -19,8 +19,10 @@
package
com
.
dlink
.
function
.
data
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
/**
...
...
@@ -30,6 +32,8 @@ import lombok.Setter;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
UDFPath
{
String
[]
jarPaths
;
...
...
dlink-function/src/main/java/com/dlink/function/util/UDFUtil.java
View file @
7a4bf38b
...
...
@@ -21,13 +21,16 @@ package com.dlink.function.util;
import
com.dlink.assertion.Asserts
;
import
com.dlink.config.Dialect
;
import
com.dlink.function.FunctionFactory
;
import
com.dlink.function.compiler.CustomStringJavaCompiler
;
import
com.dlink.function.compiler.CustomStringScalaCompiler
;
import
com.dlink.function.constant.PathConstant
;
import
com.dlink.function.data.model.UDF
;
import
com.dlink.gateway.GatewayType
;
import
com.dlink.pool.ClassEntity
;
import
com.dlink.pool.ClassPool
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.table.catalog.FunctionLanguage
;
import
java.io.InputStream
;
...
...
@@ -65,6 +68,23 @@ import groovy.lang.GroovyClassLoader;
*/
public
class
UDFUtil
{
public
static
final
String
SESSION
=
"SESSION"
;
public
static
final
String
YARN
=
"YARN"
;
public
static
final
String
APPLICATION
=
"APPLICATION"
;
/**
* 网关类型 map
* 快速获取 session 与 application 等类型,为了减少判断
*/
public
static
final
Map
<
String
,
List
<
GatewayType
>>
GATEWAY_TYPE_MAP
=
MapUtil
.
builder
(
SESSION
,
Arrays
.
asList
(
GatewayType
.
YARN_SESSION
,
GatewayType
.
KUBERNETES_SESSION
,
GatewayType
.
STANDALONE
))
.
put
(
YARN
,
Arrays
.
asList
(
GatewayType
.
YARN_APPLICATION
,
GatewayType
.
YARN_PER_JOB
))
.
put
(
APPLICATION
,
Arrays
.
asList
(
GatewayType
.
YARN_APPLICATION
,
GatewayType
.
KUBERNETES_APPLICATION
))
.
build
();
protected
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
UDFUtil
.
class
);
/**
* 存放 udf md5与版本对应的k,v值
...
...
@@ -108,6 +128,19 @@ public class UDFUtil {
}
}
public
static
String
[]
initJavaUDF
(
List
<
UDF
>
udf
,
GatewayType
gatewayType
,
Integer
missionId
)
{
return
FunctionFactory
.
initUDF
(
CollUtil
.
newArrayList
(
CollUtil
.
filterNew
(
udf
,
x
->
x
.
getFunctionLanguage
()
!=
FunctionLanguage
.
PYTHON
)),
missionId
,
null
).
getJarPaths
();
}
public
static
String
[]
initPythonUDF
(
List
<
UDF
>
udf
,
GatewayType
gatewayType
,
Integer
missionId
,
Configuration
configuration
)
{
return
FunctionFactory
.
initUDF
(
CollUtil
.
newArrayList
(
CollUtil
.
filterNew
(
udf
,
x
->
x
.
getFunctionLanguage
()
==
FunctionLanguage
.
PYTHON
)),
missionId
,
configuration
).
getPyPaths
();
}
public
static
String
getPyFileName
(
String
className
)
{
Asserts
.
checkNullString
(
className
,
"类名不能为空"
);
return
StrUtil
.
split
(
className
,
"."
).
get
(
0
);
...
...
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