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
eb41090f
Unverified
Commit
eb41090f
authored
Jul 19, 2023
by
gaoyan
Committed by
GitHub
Jul 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Gateway Submit (#2132)
* Refactor Gateway Submit * revert SqlUtil.java * fix code style * refacotr k8s gateway * refacotr k8s gateway * fix code style * fix packge err
parent
8956a2d3
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
352 additions
and
560 deletions
+352
-560
ClusterConfiguration.java
.../main/java/org/dinky/data/model/ClusterConfiguration.java
+6
-28
Task.java
dinky-admin/src/main/java/org/dinky/data/model/Task.java
+9
-3
ClusterConfigurationService.java
...n/java/org/dinky/service/ClusterConfigurationService.java
+2
-2
ClusterConfigurationServiceImpl.java
...g/dinky/service/impl/ClusterConfigurationServiceImpl.java
+8
-76
ClusterInstanceServiceImpl.java
...va/org/dinky/service/impl/ClusterInstanceServiceImpl.java
+6
-10
StudioServiceImpl.java
...c/main/java/org/dinky/service/impl/StudioServiceImpl.java
+5
-7
TaskServiceImpl.java
...src/main/java/org/dinky/service/impl/TaskServiceImpl.java
+100
-133
Submitter.java
...-base/src/main/java/org/dinky/app/flinksql/Submitter.java
+0
-29
Dialect.java
dinky-common/src/main/java/org/dinky/config/Dialect.java
+11
-0
CommonConstant.java
...src/main/java/org/dinky/data/constant/CommonConstant.java
+3
-0
JSONUtil.java
dinky-common/src/main/java/org/dinky/utils/JSONUtil.java
+23
-0
JobConfig.java
dinky-core/src/main/java/org/dinky/job/JobConfig.java
+12
-24
JobManager.java
dinky-core/src/main/java/org/dinky/job/JobManager.java
+1
-28
AbstractGateway.java
...eway/src/main/java/org/dinky/gateway/AbstractGateway.java
+1
-1
AppConfig.java
...way/src/main/java/org/dinky/gateway/config/AppConfig.java
+4
-25
FlinkConfig.java
...y/src/main/java/org/dinky/gateway/config/FlinkConfig.java
+4
-1
GatewayConfig.java
...src/main/java/org/dinky/gateway/config/GatewayConfig.java
+16
-94
K8sConfig.java
...way/src/main/java/org/dinky/gateway/config/K8sConfig.java
+34
-0
GatewayType.java
...ay/src/main/java/org/dinky/gateway/enums/GatewayType.java
+2
-9
KubernetesApplicationGateway.java
...inky/gateway/kubernetes/KubernetesApplicationGateway.java
+1
-1
KubernetesGateway.java
.../java/org/dinky/gateway/kubernetes/KubernetesGateway.java
+34
-18
KubernetsOperatorGateway.java
...gateway/kubernetes/operator/KubernetsOperatorGateway.java
+35
-29
FlinkClusterConfig.java
...main/java/org/dinky/gateway/model/FlinkClusterConfig.java
+12
-19
YarnGateway.java
...way/src/main/java/org/dinky/gateway/yarn/YarnGateway.java
+0
-5
index.tsx
...rationModal/ConfigurationForm/ApplicationConfig/index.tsx
+1
-1
index.tsx
...s/ConfigurationModal/ConfigurationForm/FlinkK8s/index.tsx
+10
-10
index.tsx
...ationModal/ConfigurationForm/HighPriorityConfig/index.tsx
+6
-1
constants.ts
dinky-web/src/pages/RegCenter/Cluster/constants.ts
+6
-6
No files found.
dinky-admin/src/main/java/org/dinky/data/model/ClusterConfiguration.java
View file @
eb41090f
...
...
@@ -19,16 +19,11 @@
package
org
.
dinky
.
data
.
model
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.dinky.mybatis.model.SuperEntity
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
cn.hutool.json.JSONObject
;
import
lombok.Data
;
...
...
@@ -55,27 +50,10 @@ public class ClusterConfiguration extends SuperEntity {
private
String
note
;
@TableField
(
exist
=
false
)
private
Map
<
String
,
Object
>
config
=
new
HashMap
<>();
public
Map
<
String
,
Object
>
parseConfig
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
if
(
Asserts
.
isNotNullString
(
configJson
))
{
config
=
objectMapper
.
readValue
(
configJson
,
HashMap
.
class
);
}
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
return
config
;
}
public
FlinkClusterConfiguration
parse
()
{
public
FlinkClusterConfig
getFlinkClusterCfg
()
{
JSONObject
json
=
new
JSONObject
(
getConfigJson
());
config
=
json
;
FlinkClusterConfiguration
flinkClusterConfiguration
=
json
.
toBean
(
FlinkClusterConfiguration
.
class
);
flinkClusterConfiguration
.
setType
(
FlinkClusterConfiguration
.
Type
.
valueOf
(
type
));
return
flinkClusterConfiguration
;
FlinkClusterConfig
flinkClusterConfig
=
json
.
toBean
(
FlinkClusterConfig
.
class
);
flinkClusterConfig
.
setType
(
GatewayType
.
get
(
type
));
return
flinkClusterConfig
;
}
}
dinky-admin/src/main/java/org/dinky/data/model/Task.java
View file @
eb41090f
...
...
@@ -20,6 +20,7 @@
package
org
.
dinky
.
data
.
model
;
import
org.dinky.assertion.Asserts
;
import
org.dinky.config.Dialect
;
import
org.dinky.job.JobConfig
;
import
org.dinky.mybatis.model.SuperEntity
;
...
...
@@ -142,11 +143,11 @@ public class Task extends SuperEntity<Task> {
public
JobConfig
buildSubmitConfig
()
{
boolean
useRemote
=
clusterId
!=
null
&&
clusterId
!=
0
;
Map
<
String
,
String
>
map
=
config
.
stream
()
parseConfig
()
.
stream
()
.
filter
(
Asserts:
:
isNotNull
)
.
collect
(
Collectors
.
toMap
(
item
->
item
.
get
(
"
key
"
),
item
->
item
.
get
(
"
name
"
),
item
->
item
.
get
(
"value"
),
(
a
,
b
)
->
b
));
...
...
@@ -171,7 +172,8 @@ public class Task extends SuperEntity<Task> {
parallelism
,
savePointStrategy
,
savePointPath
,
map
);
map
,
isJarTask
());
}
public
JsonNode
parseJsonNode
(
ObjectMapper
mapper
)
{
...
...
@@ -194,4 +196,8 @@ public class Task extends SuperEntity<Task> {
jsonNode
.
put
(
"enabled"
,
this
.
getEnabled
());
return
jsonNode
;
}
public
boolean
isJarTask
()
{
return
Dialect
.
isJarDialect
(
dialect
);
}
}
dinky-admin/src/main/java/org/dinky/service/ClusterConfigurationService.java
View file @
eb41090f
...
...
@@ -20,11 +20,11 @@
package
org
.
dinky
.
service
;
import
org.dinky.data.model.ClusterConfiguration
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.dinky.gateway.result.TestResult
;
import
org.dinky.mybatis.service.ISuperService
;
import
java.util.List
;
import
java.util.Map
;
/**
* ClusterConfigService
...
...
@@ -37,7 +37,7 @@ public interface ClusterConfigurationService extends ISuperService<ClusterConfig
List
<
ClusterConfiguration
>
listEnabledAll
();
Map
<
String
,
Object
>
getGatewayConfi
g
(
Integer
id
);
FlinkClusterConfig
getFlinkClusterCf
g
(
Integer
id
);
TestResult
testGateway
(
ClusterConfiguration
clusterConfiguration
);
...
...
dinky-admin/src/main/java/org/dinky/service/impl/ClusterConfigurationServiceImpl.java
View file @
eb41090f
...
...
@@ -19,37 +19,23 @@
package
org
.
dinky
.
service
.
impl
;
import
static
org
.
dinky
.
gateway
.
config
.
GatewayConfig
.
FLINK_VERSION
;
import
org.dinky.config.Docker
;
import
org.dinky.data.model.ClusterConfiguration
;
import
org.dinky.data.model.FlinkClusterConfiguration
;
import
org.dinky.data.model.FlinkClusterConfiguration.Type
;
import
org.dinky.gateway.config.ClusterConfig
;
import
org.dinky.gateway.config.FlinkConfig
;
import
org.dinky.gateway.config.GatewayConfig
;
import
org.dinky.gateway.
enums.GatewayType
;
import
org.dinky.gateway.
model.FlinkClusterConfig
;
import
org.dinky.gateway.result.TestResult
;
import
org.dinky.job.JobManager
;
import
org.dinky.mapper.ClusterConfigurationMapper
;
import
org.dinky.mybatis.service.impl.SuperServiceImpl
;
import
org.dinky.service.ClusterConfigurationService
;
import
org.dinky.utils.DockerClientUtils
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.lang.Opt
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.lang.Assert
;
/**
* ClusterConfigServiceImpl
...
...
@@ -66,9 +52,7 @@ public class ClusterConfigurationServiceImpl
@Override
public
ClusterConfiguration
getClusterConfigById
(
Integer
id
)
{
ClusterConfiguration
clusterConfiguration
=
baseMapper
.
selectById
(
id
);
clusterConfiguration
.
parseConfig
();
return
clusterConfiguration
;
return
baseMapper
.
selectById
(
id
);
}
@Override
...
...
@@ -77,68 +61,16 @@ public class ClusterConfigurationServiceImpl
}
@Override
public
Map
<
String
,
Object
>
getGatewayConfi
g
(
Integer
id
)
{
public
FlinkClusterConfig
getFlinkClusterCf
g
(
Integer
id
)
{
ClusterConfiguration
clusterConfiguration
=
this
.
getClusterConfigById
(
id
);
return
clusterConfiguration
.
getConfig
();
Assert
.
notNull
(
clusterConfiguration
,
"The clusterConfiguration not exists!"
);
return
clusterConfiguration
.
getFlinkClusterCfg
();
}
@Override
public
TestResult
testGateway
(
ClusterConfiguration
clusterConfiguration
)
{
FlinkClusterConfiguration
config
=
clusterConfiguration
.
parse
();
GatewayConfig
gatewayConfig
=
new
GatewayConfig
();
Opt
.
ofBlankAble
(
config
.
getHadoopConfigPath
())
.
ifPresentOrElse
(
hadoopConfigPath
->
gatewayConfig
.
setClusterConfig
(
ClusterConfig
.
build
(
config
.
getFlinkConfigPath
(),
config
.
getFlinkLibPath
(),
hadoopConfigPath
)),
()
->
gatewayConfig
.
setClusterConfig
(
ClusterConfig
.
build
(
config
.
getFlinkConfigPath
())));
FlinkConfig
flinkConfig
=
CollUtil
.
isEmpty
(
config
.
getFlinkConfig
())
?
FlinkConfig
.
build
(
new
HashMap
<>(
8
))
:
FlinkConfig
.
build
(
config
.
getFlinkConfig
());
Map
<
String
,
String
>
flinkConfigMap
=
flinkConfig
.
getConfiguration
();
gatewayConfig
.
setFlinkConfig
(
flinkConfig
);
if
(
config
.
getType
()
==
FlinkClusterConfiguration
.
Type
.
Yarn
)
{
gatewayConfig
.
setType
(
GatewayType
.
YARN_APPLICATION
);
}
else
if
(
config
.
getType
()
==
FlinkClusterConfiguration
.
Type
.
Kubernetes
)
{
gatewayConfig
.
setType
(
GatewayType
.
KUBERNETES_APPLICATION
);
Map
<
String
,
String
>
kubernetesConfig
=
config
.
getKubernetesConfig
();
// filter str blank value
kubernetesConfig
=
MapUtil
.
filter
(
kubernetesConfig
,
entry
->
!
StrUtil
.
isBlank
(
entry
.
getValue
()));
// set default value
kubernetesConfig
.
putIfAbsent
(
"kubernetes.cluster-id"
,
UUID
.
randomUUID
().
toString
());
flinkConfigMap
.
putAll
(
kubernetesConfig
);
try
{
Docker
docker
=
Docker
.
build
(
(
Map
<
String
,
Object
>)
clusterConfiguration
.
getConfig
().
get
(
"dockerConfig"
));
if
(
docker
!=
null
&&
clusterConfiguration
.
getId
()
!=
null
)
{
new
DockerClientUtils
(
docker
).
initImage
();
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
else
if
(
config
.
getType
()
==
Type
.
KubernetesOperator
)
{
gatewayConfig
.
setType
(
GatewayType
.
KUBERNETES_APPLICATION_OPERATOR
);
config
.
getKubernetesConfig
().
put
(
FLINK_VERSION
,
config
.
getFlinkVersion
());
flinkConfig
.
setFlinkKubetnetsConfig
(
config
.
getKubernetesConfig
());
}
FlinkClusterConfig
config
=
clusterConfiguration
.
getFlinkClusterCfg
();
GatewayConfig
gatewayConfig
=
GatewayConfig
.
build
(
config
);
return
JobManager
.
testGateway
(
gatewayConfig
);
}
...
...
dinky-admin/src/main/java/org/dinky/service/impl/ClusterInstanceServiceImpl.java
View file @
eb41090f
...
...
@@ -27,8 +27,8 @@ import org.dinky.constant.FlinkConstant;
import
org.dinky.data.model.Cluster
;
import
org.dinky.data.model.ClusterConfiguration
;
import
org.dinky.gateway.config.GatewayConfig
;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.exception.GatewayException
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.dinky.gateway.result.GatewayResult
;
import
org.dinky.job.JobManager
;
import
org.dinky.mapper.ClusterInstanceMapper
;
...
...
@@ -168,13 +168,9 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance
throw
new
GatewayException
(
"The cluster has been killed."
);
}
Integer
clusterConfigurationId
=
cluster
.
getClusterConfigurationId
();
ClusterConfiguration
clusterConfiguration
=
clusterConfigurationService
.
getClusterConfigById
(
clusterConfigurationId
);
if
(
Asserts
.
isNull
(
clusterConfiguration
))
{
throw
new
GatewayException
(
"The cluster configuration does not exist."
);
}
GatewayConfig
gatewayConfig
=
GatewayConfig
.
build
(
clusterConfiguration
.
getConfig
());
gatewayConfig
.
setType
(
GatewayType
.
get
(
cluster
.
getType
()));
FlinkClusterConfig
flinkClusterConfig
=
clusterConfigurationService
.
getFlinkClusterCfg
(
clusterConfigurationId
);
GatewayConfig
gatewayConfig
=
GatewayConfig
.
build
(
flinkClusterConfig
);
JobManager
.
killCluster
(
gatewayConfig
,
cluster
.
getName
());
}
...
...
@@ -185,8 +181,8 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance
if
(
Asserts
.
isNull
(
clusterConfiguration
))
{
throw
new
GatewayException
(
"The cluster configuration does not exist."
);
}
GatewayConfig
gatewayConfig
=
GatewayConfig
.
build
(
clusterConfiguration
.
getConfig
());
gatewayConfig
.
setType
(
GatewayType
.
getSessionType
(
clusterConfiguration
.
getType
()
));
GatewayConfig
gatewayConfig
=
GatewayConfig
.
build
(
clusterConfiguration
.
getFlinkClusterCfg
(
));
GatewayResult
gatewayResult
=
JobManager
.
deploySessionCluster
(
gatewayConfig
);
return
registersCluster
(
Cluster
.
autoRegistersCluster
(
...
...
dinky-admin/src/main/java/org/dinky/service/impl/StudioServiceImpl.java
View file @
eb41090f
...
...
@@ -44,6 +44,7 @@ import org.dinky.data.result.SelectResult;
import
org.dinky.data.result.SqlExplainResult
;
import
org.dinky.explainer.lineage.LineageBuilder
;
import
org.dinky.explainer.lineage.LineageResult
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.dinky.gateway.model.JobInfo
;
import
org.dinky.gateway.result.SavePointResult
;
import
org.dinky.job.JobConfig
;
...
...
@@ -398,8 +399,8 @@ public class StudioServiceImpl implements StudioService {
JobConfig
jobConfig
=
new
JobConfig
();
jobConfig
.
setAddress
(
cluster
.
getJobManagerHost
());
if
(
Asserts
.
isNotNull
(
cluster
.
getClusterConfigurationId
()))
{
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
get
GatewayConfi
g
(
FlinkClusterConfig
gatewayConfig
=
clusterConfigurationService
.
get
FlinkClusterCf
g
(
cluster
.
getClusterConfigurationId
());
jobConfig
.
buildGatewayConfig
(
gatewayConfig
);
}
...
...
@@ -413,25 +414,22 @@ public class StudioServiceImpl implements StudioService {
Cluster
cluster
=
clusterInstanceService
.
getById
(
clusterId
);
Asserts
.
checkNotNull
(
cluster
,
"该集群不存在"
);
boolean
useGateway
=
false
;
JobConfig
jobConfig
=
new
JobConfig
();
jobConfig
.
setAddress
(
cluster
.
getJobManagerHost
());
jobConfig
.
setType
(
cluster
.
getType
());
if
(
Asserts
.
isNotNull
(
cluster
.
getClusterConfigurationId
()))
{
// 如果用户选择用dinky平台来托管集群信息 说明任务一定是从dinky发起提交的
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
get
GatewayConfi
g
(
FlinkClusterConfig
gatewayConfig
=
clusterConfigurationService
.
get
FlinkClusterCf
g
(
cluster
.
getClusterConfigurationId
());
jobConfig
.
buildGatewayConfig
(
gatewayConfig
);
jobConfig
.
getGatewayConfig
().
getClusterConfig
().
setAppId
(
cluster
.
getName
());
jobConfig
.
setTaskId
(
cluster
.
getTaskId
());
useGateway
=
true
;
}
else
{
// 用户选择外部的平台来托管集群信息,但是集群上的任务不一定是通过dinky提交的
jobConfig
.
setTaskId
(
taskId
);
}
JobManager
jobManager
=
JobManager
.
build
(
jobConfig
);
jobManager
.
setUseGateway
(
useGateway
);
SavePointResult
savePointResult
=
jobManager
.
savepoint
(
jobId
,
savePointType
,
null
);
if
(
Asserts
.
isNotNull
(
savePointResult
))
{
...
...
dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java
View file @
eb41090f
...
...
@@ -32,6 +32,7 @@ import org.dinky.context.RowLevelPermissionsContext;
import
org.dinky.context.TenantContextHolder
;
import
org.dinky.daemon.task.DaemonFactory
;
import
org.dinky.daemon.task.DaemonTaskConfig
;
import
org.dinky.data.constant.CommonConstant
;
import
org.dinky.data.constant.FlinkRestResultConstant
;
import
org.dinky.data.dto.SqlDTO
;
import
org.dinky.data.dto.TaskRollbackVersionDTO
;
...
...
@@ -74,6 +75,7 @@ import org.dinky.gateway.config.GatewayConfig;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.enums.SavePointStrategy
;
import
org.dinky.gateway.enums.SavePointType
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.dinky.gateway.model.JobInfo
;
import
org.dinky.gateway.result.SavePointResult
;
import
org.dinky.job.FlinkJobTask
;
...
...
@@ -88,7 +90,6 @@ import org.dinky.metadata.result.JdbcSelectResult;
import
org.dinky.mybatis.service.impl.SuperServiceImpl
;
import
org.dinky.process.context.ProcessContextHolder
;
import
org.dinky.process.enums.ProcessType
;
import
org.dinky.process.exception.DinkyException
;
import
org.dinky.process.model.ProcessEntity
;
import
org.dinky.service.AlertGroupService
;
import
org.dinky.service.AlertHistoryService
;
...
...
@@ -152,11 +153,11 @@ import cn.dev33.satoken.stp.StpUtil;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.lang.Opt
;
import
cn.hutool.core.lang.tree.Tree
;
import
cn.hutool.core.lang.tree.TreeNode
;
import
cn.hutool.core.lang.tree.TreeUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONObject
;
import
lombok.RequiredArgsConstructor
;
/** TaskServiceImpl */
...
...
@@ -166,7 +167,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
private
final
StatementService
statementService
;
private
final
ClusterInstanceService
clusterInstanceService
;
private
final
ClusterConfigurationService
clusterC
onfiguration
Service
;
private
final
ClusterConfigurationService
clusterC
fg
Service
;
private
final
SavepointsService
savepointsService
;
private
final
JarService
jarService
;
private
final
DataBaseService
dataBaseService
;
...
...
@@ -204,14 +205,15 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Value
(
"server.port"
)
private
String
serverPort
;
private
String
buildParas
(
Integer
id
)
{
private
String
[]
buildParas
(
Integer
id
)
{
return
buildParas
(
id
,
StrUtil
.
NULL
);
}
private
String
buildParas
(
Integer
id
,
String
dinkyAddr
)
{
private
String
[]
buildParas
(
Integer
id
,
String
dinkyAddr
)
{
return
String
.
format
(
"--id %d --driver %s --url %s --username %s --password %s --dinkyAddr %s"
,
id
,
driver
(),
url
(),
username
(),
password
(),
dinkyAddr
);
"--id %d --driver %s --url %s --username %s --password %s --dinkyAddr %s"
,
id
,
driver
(),
url
(),
username
(),
password
(),
dinkyAddr
)
.
split
(
" "
);
}
@Override
...
...
@@ -233,9 +235,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
process
.
info
(
"Initializing Flink job config..."
);
JobConfig
config
=
buildJobConfig
(
task
);
if
(
GatewayType
.
KUBERNETES_APPLICATION
.
equalsValue
(
config
.
getType
()))
{
loadDocker
(
id
,
config
.
getClusterConfigurationId
(),
config
.
getGatewayConfig
());
}
//
if (GatewayType.KUBERNETES_APPLICATION.equalsValue(config.getType())) {
//
loadDocker(id, config.getClusterConfigurationId(), config.getGatewayConfig());
//
}
JobManager
jobManager
=
JobManager
.
build
(
config
);
process
.
start
();
...
...
@@ -253,20 +255,20 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
private
void
loadDocker
(
Integer
taskId
,
Integer
clusterConfigurationId
,
GatewayConfig
gatewayConfig
)
{
Map
<
String
,
Object
>
dockerConfig
=
(
Map
<
String
,
Object
>)
clusterConfigurationService
.
getClusterConfigById
(
clusterConfigurationId
)
.
get
Config
()
.
get
(
"dockerConfig"
);
clusterCfgService
.
getClusterConfigById
(
clusterConfigurationId
)
.
getFlinkClusterCfg
(
)
.
getKubernetes
Config
()
.
getDockerConfig
(
);
if
(
dockerConfig
==
null
)
{
return
;
}
String
params
=
String
[]
params
=
buildParas
(
taskId
,
dockerConfig
.
getOrDefault
(
"dinky.remote.addr"
,
""
).
toString
());
gatewayConfig
.
getAppConfig
().
setUserJarParas
(
params
.
split
(
" "
)
);
gatewayConfig
.
getAppConfig
().
setUserJarParas
(
params
);
Docker
docker
=
Docker
.
build
(
dockerConfig
);
if
(
docker
==
null
||
StringUtils
.
isBlank
(
docker
.
getInstance
()))
{
...
...
@@ -588,8 +590,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override
public
Task
getTaskByNameAndTenantId
(
String
name
,
Integer
tenantId
)
{
Task
task
=
baseMapper
.
getTaskByNameAndTenantId
(
name
,
tenantId
);
return
task
;
return
baseMapper
.
getTaskByNameAndTenantId
(
name
,
tenantId
);
}
@Override
...
...
@@ -598,18 +599,15 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
return
JobStatus
.
UNKNOWN
;
}
Map
<
String
,
Object
>
gatewayConfigMap
=
clusterConfigurationService
.
getGatewayConfig
(
jobInfoDetail
.
getClusterConfiguration
().
getId
());
Integer
clusterId
=
jobInfoDetail
.
getClusterConfiguration
().
getId
();
String
appId
=
jobInfoDetail
.
getCluster
().
getName
();
JobConfig
jobConfig
=
new
JobConfig
();
jobConfig
.
buildGatewayConfig
(
gatewayConfigMap
);
GatewayConfig
gatewayConfig
=
jobConfig
.
getGatewayConfig
();
gatewayConfig
.
setType
(
GatewayType
.
get
(
jobInfoDetail
.
getCluster
().
getType
()));
gatewayConfig
.
getClusterConfig
().
setAppId
(
jobInfoDetail
.
getCluster
().
getName
());
FlinkClusterConfig
clusterConfig
=
clusterCfgService
.
getFlinkClusterCfg
(
clusterId
);
GatewayConfig
gatewayConfig
=
GatewayConfig
.
build
(
clusterConfig
);
gatewayConfig
.
getClusterConfig
().
setAppId
(
appId
);
Gateway
gateway
=
Gateway
.
build
(
gatewayConfig
);
return
gateway
.
getJobStatusById
(
jobInfoDetail
.
getCluster
().
getName
()
);
return
gateway
.
getJobStatusById
(
appId
);
}
@Override
...
...
@@ -900,27 +898,13 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
JobConfig
jobConfig
=
task
.
buildSubmitConfig
();
jobConfig
.
setType
(
cluster
.
getType
());
boolean
useGateway
=
false
;
if
(
Asserts
.
isNotNull
(
cluster
.
getClusterConfigurationId
()))
{
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
getGatewayConfig
(
cluster
.
getClusterConfigurationId
());
// 如果是k8s application 模式,且不是sql任务,则需要补齐statement 内的自定义配置
if
(
Dialect
.
KUBERNETES_APPLICATION
.
equalsVal
(
task
.
getDialect
()))
{
Statement
statement
=
statementService
.
getById
(
cluster
.
getTaskId
());
Map
<
String
,
Object
>
statementConfig
=
JSONUtil
.
toMap
(
statement
.
getStatement
(),
String
.
class
,
Object
.
class
);
gatewayConfig
.
putAll
(
statementConfig
);
}
jobConfig
.
buildGatewayConfig
(
gatewayConfig
);
jobConfig
.
getGatewayConfig
().
getClusterConfig
().
setAppId
(
cluster
.
getName
());
useGateway
=
true
;
FlinkClusterConfig
flinkClusterConfig
=
buildGatewayCfgObj
(
jobConfig
);
jobConfig
.
buildGatewayConfig
(
flinkClusterConfig
);
}
jobConfig
.
setTaskId
(
jobInstance
.
getTaskId
());
jobConfig
.
setAddress
(
cluster
.
getJobManagerHost
());
JobManager
jobManager
=
JobManager
.
build
(
jobConfig
);
jobManager
.
setUseGateway
(
useGateway
);
String
jobId
=
jobInstance
.
getJid
();
if
(
"canceljob"
.
equals
(
savePointType
))
{
...
...
@@ -952,97 +936,85 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
}
private
JobConfig
buildJobConfig
(
Task
task
)
{
boolean
isJarTask
=
Dialect
.
FLINK_JAR
.
equalsVal
(
task
.
getDialect
())
||
Dialect
.
KUBERNETES_APPLICATION
.
equalsVal
(
task
.
getDialect
());
boolean
fragment
=
Asserts
.
isNotNull
(
task
.
getFragment
())
?
task
.
getFragment
()
:
false
;
if
(!
isJarTask
&&
fragment
)
{
String
flinkWithSql
=
dataBaseService
.
getEnabledFlinkWithSql
();
if
(
Asserts
.
isNotNullString
(
flinkWithSql
))
{
task
.
setStatement
(
flinkWithSql
+
"\r\n"
+
task
.
getStatement
());
}
if
(!
task
.
isJarTask
())
{
String
envSql
=
buildEnvSql
(
task
);
task
.
setStatement
(
envSql
+
task
.
getStatement
());
}
boolean
isEnvIdValid
=
Asserts
.
isNotNull
(
task
.
getEnvId
())
&&
task
.
getEnvId
()
!=
0
;
if
(!
isJarTask
&&
isEnvIdValid
)
{
Task
envTask
=
getTaskInfoById
(
task
.
getEnvId
()
);
if
(
Asserts
.
isNotNull
(
envTask
)
&&
Asserts
.
isNotNullString
(
envTask
.
getStatement
()
))
{
task
.
setStatement
(
envTask
.
getStatement
()
+
"\r\n"
+
task
.
getStatement
());
}
JobConfig
config
=
task
.
buildSubmitConfig
()
;
Savepoints
savepoints
=
buildSavepoint
(
config
);
if
(
Asserts
.
isNotNull
(
savepoints
))
{
config
.
setSavePointPath
(
savepoints
.
getPath
());
config
.
getConfig
().
put
(
"execution.savepoint.path"
,
savepoints
.
getPath
());
}
JobConfig
config
=
task
.
buildSubmitConfig
();
config
.
setJarTask
(
isJarTask
);
if
(!
JobManager
.
useGateway
(
config
.
getType
()))
{
config
.
setAddress
(
if
(!
GatewayType
.
get
(
task
.
getType
()).
isDeployCluster
())
{
String
address
=
clusterInstanceService
.
buildEnvironmentAddress
(
config
.
isUseRemote
(),
task
.
getClusterId
()));
}
else
if
(
Dialect
.
KUBERNETES_APPLICATION
.
equalsVal
(
task
.
getDialect
())
// support custom K8s app submit, rather than clusterConfiguration
&&
(
GatewayType
.
KUBERNETES_APPLICATION
.
equalsValue
(
config
.
getType
())
||
GatewayType
.
KUBERNETES_APPLICATION_OPERATOR
.
equalsValue
(
config
.
getType
())))
{
Map
<
String
,
Object
>
taskConfig
=
JSONUtil
.
toMap
(
task
.
getStatement
(),
String
.
class
,
Object
.
class
);
Map
<
String
,
Object
>
clusterConfiguration
=
clusterConfigurationService
.
getGatewayConfig
(
task
.
getClusterConfigurationId
());
clusterConfiguration
.
putAll
((
Map
<
String
,
Object
>)
taskConfig
.
get
(
"appConfig"
));
clusterConfiguration
.
put
(
"taskCustomConfig"
,
taskConfig
);
config
.
buildGatewayConfig
(
clusterConfiguration
);
config
.
isUseRemote
(),
task
.
getClusterId
());
config
.
setAddress
(
address
);
}
else
{
Map
<
String
,
Object
>
gatewayConfig
=
clusterConfigurationService
.
getGatewayConfig
(
task
.
getClusterConfigurationId
());
// submit application type with clusterConfiguration
if
(
GatewayType
.
YARN_APPLICATION
.
equalsValue
(
config
.
getType
())
||
GatewayType
.
KUBERNETES_APPLICATION
.
equalsValue
(
config
.
getType
())
||
GatewayType
.
KUBERNETES_APPLICATION_OPERATOR
.
equalsValue
(
config
.
getType
()))
{
if
(
isJarTask
)
{
Jar
jar
=
jarService
.
getById
(
task
.
getJarId
());
Assert
.
check
(
jar
);
gatewayConfig
.
put
(
"userJarPath"
,
jar
.
getPath
());
gatewayConfig
.
put
(
"userJarParas"
,
jar
.
getParas
());
gatewayConfig
.
put
(
"userJarMainAppClass"
,
jar
.
getMainClass
());
}
else
{
Opt
.
ofBlankAble
(
gatewayConfig
.
get
(
"userJarPath"
))
.
orElseThrow
(
()
->
new
DinkyException
(
"application 模式支持需要在 注册中心->集群管理->集群配置管理 填写jar路径。"
));
gatewayConfig
.
put
(
"userJarParas"
,
buildParas
(
config
.
getTaskId
()));
gatewayConfig
.
put
(
"userJarMainAppClass"
,
"org.dinky.app.MainApp"
);
}
}
config
.
buildGatewayConfig
(
gatewayConfig
);
config
.
addGatewayConfig
(
task
.
parseConfig
());
config
.
buildGatewayConfig
(
buildGatewayCfgObj
(
config
));
}
config
.
setVariables
(
fragmentVariableService
.
listEnabledVariables
());
buildRowPermission
();
return
config
;
}
private
Savepoints
buildSavepoint
(
JobConfig
config
)
{
switch
(
config
.
getSavePointStrategy
())
{
case
LATEST:
Savepoints
latestSavepoints
=
savepointsService
.
getLatestSavepointByTaskId
(
task
.
getId
());
if
(
Asserts
.
isNotNull
(
latestSavepoints
))
{
config
.
setSavePointPath
(
latestSavepoints
.
getPath
());
config
.
getConfig
().
put
(
"execution.savepoint.path"
,
latestSavepoints
.
getPath
());
}
break
;
return
savepointsService
.
getLatestSavepointByTaskId
(
config
.
getTaskId
());
case
EARLIEST:
Savepoints
earliestSavepoints
=
savepointsService
.
getEarliestSavepointByTaskId
(
task
.
getId
());
if
(
Asserts
.
isNotNull
(
earliestSavepoints
))
{
config
.
setSavePointPath
(
earliestSavepoints
.
getPath
());
config
.
getConfig
()
.
put
(
"execution.savepoint.path"
,
earliestSavepoints
.
getPath
());
}
break
;
return
savepointsService
.
getEarliestSavepointByTaskId
(
config
.
getTaskId
());
case
CUSTOM:
config
.
setSavePointPath
(
config
.
getSavePointPath
());
config
.
getConfig
().
put
(
"execution.savepoint.path"
,
config
.
getSavePointPath
());
break
;
return
new
Savepoints
()
{
{
setPath
(
config
.
getSavePointPath
());
}
};
default
:
config
.
setSavePointPath
(
null
)
;
return
null
;
}
config
.
setVariables
(
fragmentVariableService
.
listEnabledVariables
());
}
private
FlinkClusterConfig
buildGatewayCfgObj
(
JobConfig
config
)
{
FlinkClusterConfig
flinkClusterCfg
=
clusterCfgService
.
getFlinkClusterCfg
(
config
.
getClusterConfigurationId
());
flinkClusterCfg
.
getAppConfig
().
setUserJarParas
(
buildParas
(
config
.
getTaskId
()));
flinkClusterCfg
.
getFlinkConfig
().
getConfiguration
().
putAll
(
config
.
getConfig
());
// if (config.isJarTask()) {
// JSONObject clusterObj = new JSONObject(flinkClusterCfg);
// JSONObject taskObj = new JSONObject(task.getStatement());
// return JSONUtil.merge(clusterObj,taskObj).toBean(FlinkClusterConfig.class);
// }
return
flinkClusterCfg
;
}
private
String
buildEnvSql
(
Task
task
)
{
String
sql
=
CommonConstant
.
LineSep
;
boolean
fragment
=
Asserts
.
isNotNull
(
task
.
getFragment
())
?
task
.
getFragment
()
:
false
;
if
(
fragment
)
{
String
flinkWithSql
=
dataBaseService
.
getEnabledFlinkWithSql
();
if
(
Asserts
.
isNotNullString
(
flinkWithSql
))
{
sql
+=
flinkWithSql
+
CommonConstant
.
LineSep
;
}
}
boolean
isEnvIdValid
=
Asserts
.
isNotNull
(
task
.
getEnvId
())
&&
task
.
getEnvId
()
!=
0
;
if
(
isEnvIdValid
)
{
Task
envTask
=
getTaskInfoById
(
task
.
getEnvId
());
if
(
Asserts
.
isNotNull
(
envTask
)
&&
Asserts
.
isNotNullString
(
envTask
.
getStatement
()))
{
sql
+=
envTask
.
getStatement
()
+
CommonConstant
.
LineSep
;
}
}
return
sql
;
}
private
void
buildRowPermission
()
{
List
<
RowPermissions
>
currentRoleSelectPermissions
=
userService
.
getCurrentRoleSelectPermissions
();
if
(
Asserts
.
isNotNullCollection
(
currentRoleSelectPermissions
))
{
...
...
@@ -1058,7 +1030,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
}
RowLevelPermissionsContext
.
set
(
permission
);
}
return
config
;
}
@Override
...
...
@@ -1081,8 +1052,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
history
.
setConfig
(
JSONUtil
.
parseObject
(
history
.
getConfigJson
()));
if
(
Asserts
.
isNotNull
(
history
.
getClusterConfigurationId
()))
{
ClusterConfiguration
clusterConfigById
=
clusterConfigurationService
.
getClusterConfigById
(
history
.
getClusterConfigurationId
());
clusterCfgService
.
getClusterConfigById
(
history
.
getClusterConfigurationId
());
jobInfoDetail
.
setClusterConfiguration
(
clusterConfigById
);
jobInfoDetail
.
getInstance
().
setType
(
history
.
getType
());
}
...
...
@@ -1198,7 +1168,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// clusterConfigurationName
if
(
Asserts
.
isNotNull
(
task
.
getClusterConfigurationId
()))
{
ClusterConfiguration
clusterConfiguration
=
clusterC
onfiguration
Service
.
getById
(
task
.
getClusterConfigurationId
());
clusterC
fg
Service
.
getById
(
task
.
getClusterConfigurationId
());
jsonNode
.
put
(
"clusterConfigurationName"
,
Asserts
.
isNotNull
(
clusterConfiguration
)
...
...
@@ -1287,7 +1257,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
if
(
Asserts
.
isNotNull
(
task
.
getClusterConfigurationName
()))
{
ClusterConfiguration
clusterConfiguration
=
clusterC
onfiguration
Service
.
getOne
(
clusterC
fg
Service
.
getOne
(
new
QueryWrapper
<
ClusterConfiguration
>()
.
eq
(
"name"
,
task
.
getClusterConfigurationName
()));
if
(
Asserts
.
isNotNull
(
clusterConfiguration
))
{
...
...
@@ -1430,7 +1400,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
Task
updateTask
=
new
Task
();
updateTask
.
setId
(
jobInstance
.
getTaskId
());
updateTask
.
setJobInstanceId
(
0
);
updateTask
.
setJobInstanceId
(
jobInstance
.
getId
()
);
Integer
jobInstanceId
=
jobInstance
.
getId
();
// 获取任务历史信息
...
...
@@ -1438,12 +1408,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// some job need do something on Done, example flink-kubernets-operator
if
(
GatewayType
.
isDeployCluster
(
jobInstance
.
getType
()))
{
JobConfig
jobConfig
=
new
JobConfig
();
Map
<
String
,
Object
>
clusterConfig
=
JSONUtil
.
toMap
(
jobHistory
.
getClusterConfiguration
().
get
(
"configJson"
).
asText
(),
String
.
class
,
Object
.
class
);
jobConfig
.
buildGatewayConfig
(
clusterConfig
);
String
configJson
=
jobHistory
.
getClusterConfiguration
().
get
(
"configJson"
).
asText
();
jobConfig
.
buildGatewayConfig
(
new
JSONObject
(
configJson
).
toBean
(
FlinkClusterConfig
.
class
));
jobConfig
.
getGatewayConfig
().
setType
(
GatewayType
.
get
(
jobInstance
.
getType
()));
jobConfig
.
getGatewayConfig
().
getFlinkConfig
().
setJobName
(
jobInstance
.
getName
());
Gateway
.
build
(
jobConfig
.
getGatewayConfig
())
...
...
dinky-app/dinky-app-base/src/main/java/org/dinky/app/flinksql/Submitter.java
View file @
eb41090f
...
...
@@ -33,7 +33,6 @@ import org.dinky.utils.ZipUtils;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.flink.configuration.CheckpointingOptions
;
import
org.apache.flink.configuration.PipelineOptions
;
import
org.apache.flink.python.PythonOptions
;
...
...
@@ -53,7 +52,6 @@ import java.util.Arrays;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
org.slf4j.Logger
;
...
...
@@ -176,33 +174,6 @@ public class Submitter {
// 加载第三方jar
loadDep
(
taskConfig
.
get
(
"type"
),
id
,
dinkyAddr
,
executorSetting
);
String
uuid
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
if
(
executorSetting
.
getConfig
()
.
containsKey
(
CheckpointingOptions
.
CHECKPOINTS_DIRECTORY
.
key
()))
{
executorSetting
.
getConfig
()
.
put
(
CheckpointingOptions
.
CHECKPOINTS_DIRECTORY
.
key
(),
executorSetting
.
getConfig
()
.
get
(
CheckpointingOptions
.
CHECKPOINTS_DIRECTORY
.
key
())
+
"/"
+
uuid
);
}
if
(
executorSetting
.
getConfig
()
.
containsKey
(
CheckpointingOptions
.
SAVEPOINT_DIRECTORY
.
key
()))
{
executorSetting
.
getConfig
()
.
put
(
CheckpointingOptions
.
SAVEPOINT_DIRECTORY
.
key
(),
executorSetting
.
getConfig
()
.
get
(
CheckpointingOptions
.
SAVEPOINT_DIRECTORY
.
key
())
+
"/"
+
uuid
);
}
logger
.
info
(
"作业配置如下: {}"
,
executorSetting
);
Executor
executor
=
Executor
.
buildAppStreamExecutor
(
executorSetting
);
List
<
StatementParam
>
ddl
=
new
ArrayList
<>();
...
...
dinky-common/src/main/java/org/dinky/config/Dialect.java
View file @
eb41090f
...
...
@@ -108,4 +108,15 @@ public enum Dialect {
return
false
;
}
}
public
static
boolean
isJarDialect
(
String
value
)
{
Dialect
dialect
=
Dialect
.
get
(
value
);
switch
(
dialect
)
{
case
FLINK_JAR:
case
KUBERNETES_APPLICATION:
return
true
;
default
:
return
false
;
}
}
}
dinky-common/src/main/java/org/dinky/data/constant/CommonConstant.java
View file @
eb41090f
...
...
@@ -28,4 +28,7 @@ public final class CommonConstant {
/** 实例健康 */
public
static
final
String
HEALTHY
=
"1"
;
public
static
final
String
DINKY_APP_MAIN_CLASS
=
"org.dinky.app.MainApp"
;
public
static
final
String
LineSep
=
System
.
getProperty
(
"line.separator"
);
}
dinky-common/src/main/java/org/dinky/utils/JSONUtil.java
View file @
eb41090f
...
...
@@ -30,8 +30,10 @@ import org.dinky.assertion.Asserts;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TimeZone
;
import
org.slf4j.Logger
;
...
...
@@ -50,6 +52,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import
com.fasterxml.jackson.databind.node.TextNode
;
import
com.fasterxml.jackson.databind.type.CollectionType
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
/**
* JSONUtil
*
...
...
@@ -200,4 +205,22 @@ public class JSONUtil {
}
}
}
public
static
JSONObject
merge
(
JSONObject
mergeTo
,
JSONObject
...
values
)
{
for
(
JSONObject
value
:
values
)
{
Set
<
String
>
allKeys
=
new
HashSet
<>();
allKeys
.
addAll
(
mergeTo
.
keySet
());
allKeys
.
addAll
(
value
.
keySet
());
for
(
String
key
:
allKeys
)
{
if
(
value
.
containsKey
(
key
))
{
if
(
value
.
get
(
key
)
instanceof
JSONObject
)
{
return
merge
((
JSONObject
)
mergeTo
.
get
(
key
),
(
JSONObject
)
value
.
get
(
key
));
}
else
if
(
value
.
get
(
key
)
instanceof
JSONArray
)
{
((
JSONArray
)
mergeTo
.
get
(
key
)).
addAll
(((
JSONArray
)
value
.
get
(
key
)));
}
}
}
}
return
mergeTo
;
}
}
dinky-core/src/main/java/org/dinky/job/JobConfig.java
View file @
eb41090f
...
...
@@ -25,12 +25,12 @@ import org.dinky.executor.ExecutorSetting;
import
org.dinky.gateway.config.GatewayConfig
;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.enums.SavePointStrategy
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.apache.flink.configuration.CoreOptions
;
import
org.apache.flink.configuration.RestOptions
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
lombok.Getter
;
...
...
@@ -233,7 +233,8 @@ public class JobConfig {
Integer
parallelism
,
Integer
savePointStrategyValue
,
String
savePointPath
,
Map
<
String
,
String
>
config
)
{
Map
<
String
,
String
>
config
,
boolean
isJarTask
)
{
this
.
type
=
type
;
this
.
step
=
step
;
this
.
useResult
=
useResult
;
...
...
@@ -252,6 +253,7 @@ public class JobConfig {
this
.
savePointStrategy
=
SavePointStrategy
.
get
(
savePointStrategyValue
);
this
.
savePointPath
=
savePointPath
;
this
.
config
=
config
;
this
.
isJarTask
=
isJarTask
;
}
public
ExecutorSetting
getExecutorSetting
()
{
...
...
@@ -266,29 +268,15 @@ public class JobConfig {
config
);
}
public
void
buildGatewayConfig
(
Map
<
String
,
Object
>
config
)
{
public
void
buildGatewayConfig
(
FlinkClusterConfig
config
)
{
gatewayConfig
=
GatewayConfig
.
build
(
config
);
if
(
config
.
containsKey
(
"flinkConfig"
)
&&
Asserts
.
isNotNullMap
((
Map
<
String
,
String
>)
config
.
get
(
"flinkConfig"
)))
{
gatewayConfig
.
getFlinkConfig
()
.
getConfiguration
()
.
put
(
CoreOptions
.
DEFAULT_PARALLELISM
.
key
(),
String
.
valueOf
(
parallelism
));
}
}
public
void
addGatewayConfig
(
List
<
Map
<
String
,
String
>>
configList
)
{
if
(
Asserts
.
isNull
(
gatewayConfig
))
{
gatewayConfig
=
new
GatewayConfig
();
}
for
(
Map
<
String
,
String
>
item
:
configList
)
{
if
(
Asserts
.
isNotNull
(
item
))
{
gatewayConfig
.
getFlinkConfig
()
.
getConfiguration
()
.
put
(
item
.
get
(
"key"
),
item
.
get
(
"value"
));
}
}
gatewayConfig
.
setTaskId
(
getTaskId
());
gatewayConfig
.
getFlinkConfig
().
setJobName
(
getJobName
());
gatewayConfig
.
getFlinkConfig
()
.
getConfiguration
()
.
put
(
CoreOptions
.
DEFAULT_PARALLELISM
.
key
(),
String
.
valueOf
(
parallelism
));
setUseRemote
(
false
);
}
public
void
addGatewayConfig
(
Map
<
String
,
Object
>
config
)
{
...
...
dinky-core/src/main/java/org/dinky/job/JobManager.java
View file @
eb41090f
...
...
@@ -128,14 +128,6 @@ public class JobManager {
public
JobManager
()
{}
public
void
setUseGateway
(
boolean
useGateway
)
{
this
.
useGateway
=
useGateway
;
}
public
boolean
isUseGateway
()
{
return
useGateway
;
}
public
void
setPlanMode
(
boolean
planMode
)
{
isPlanMode
=
planMode
;
}
...
...
@@ -179,7 +171,6 @@ public class JobManager {
}
public
static
JobManager
build
(
JobConfig
config
)
{
initGatewayConfig
(
config
);
JobManager
manager
=
new
JobManager
(
config
);
manager
.
init
();
return
manager
;
...
...
@@ -193,24 +184,6 @@ public class JobManager {
return
manager
;
}
private
static
void
initGatewayConfig
(
JobConfig
config
)
{
if
(
useGateway
(
config
.
getType
()))
{
Asserts
.
checkNull
(
config
.
getGatewayConfig
(),
"GatewayConfig 不能为空"
);
config
.
getGatewayConfig
().
setType
(
GatewayType
.
get
(
config
.
getType
()));
config
.
getGatewayConfig
().
setTaskId
(
config
.
getTaskId
());
config
.
getGatewayConfig
().
getFlinkConfig
().
setJobName
(
config
.
getJobName
());
config
.
getGatewayConfig
().
getFlinkConfig
().
setSavePoint
(
config
.
getSavePointPath
());
config
.
setUseRemote
(
false
);
}
}
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_OPERATOR
.
equalsValue
(
type
));
}
private
Executor
createExecutor
()
{
initEnvironmentSetting
();
if
(!
runMode
.
equals
(
GatewayType
.
LOCAL
)
&&
!
useGateway
&&
config
.
isUseRemote
())
{
...
...
@@ -246,7 +219,7 @@ public class JobManager {
public
boolean
init
()
{
if
(!
isPlanMode
)
{
runMode
=
GatewayType
.
get
(
config
.
getType
());
useGateway
=
useGateway
(
config
.
getType
());
useGateway
=
GatewayType
.
isDeployCluster
(
config
.
getType
());
handler
=
JobHandler
.
build
();
}
useStatementSet
=
config
.
isUseStatementSet
();
...
...
dinky-gateway/src/main/java/org/dinky/gateway/AbstractGateway.java
View file @
eb41090f
...
...
@@ -62,7 +62,7 @@ public abstract class AbstractGateway implements Gateway {
protected
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AbstractGateway
.
class
);
protected
GatewayConfig
config
;
protected
Configuration
configuration
;
protected
Configuration
configuration
=
new
Configuration
()
;
public
AbstractGateway
()
{}
...
...
dinky-gateway/src/main/java/org/dinky/gateway/config/AppConfig.java
View file @
eb41090f
...
...
@@ -19,40 +19,19 @@
package
org
.
dinky
.
gateway
.
config
;
import
org.dinky.
assertion.Asserts
;
import
org.dinky.
data.constant.CommonConstant
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.With
;
import
lombok.Data
;
/**
* AppConfig
*
* @since 2021/11/3 21:55
*/
@Setter
@Getter
@With
@Data
public
class
AppConfig
{
private
String
userJarPath
;
private
String
[]
userJarParas
;
private
String
userJarMainAppClass
;
public
AppConfig
()
{}
public
AppConfig
(
String
userJarPath
,
String
[]
userJarParas
,
String
userJarMainAppClass
)
{
this
.
userJarPath
=
userJarPath
;
this
.
userJarParas
=
userJarParas
;
this
.
userJarMainAppClass
=
userJarMainAppClass
;
}
public
static
AppConfig
build
(
String
userJarPath
,
String
userJarParasStr
,
String
userJarMainAppClass
)
{
if
(
Asserts
.
isNotNullString
(
userJarParasStr
))
{
return
new
AppConfig
(
userJarPath
,
userJarParasStr
.
split
(
" "
),
userJarMainAppClass
);
}
else
{
return
new
AppConfig
(
userJarPath
,
new
String
[]
{},
userJarMainAppClass
);
}
}
private
String
userJarMainAppClass
=
CommonConstant
.
DINKY_APP_MAIN_CLASS
;
}
dinky-gateway/src/main/java/org/dinky/gateway/config/FlinkConfig.java
View file @
eb41090f
...
...
@@ -23,7 +23,9 @@ import org.dinky.assertion.Asserts;
import
org.dinky.gateway.enums.ActionType
;
import
org.dinky.gateway.enums.SavePointType
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
...
...
@@ -45,11 +47,12 @@ public class FlinkConfig {
private
String
jobName
;
private
String
jobId
;
private
String
flinkVersion
;
private
ActionType
action
;
private
SavePointType
savePointType
;
private
String
savePoint
;
private
Map
<
String
,
String
>
configuration
=
new
HashMap
<>();
private
Map
<
String
,
String
>
FlinkKubetnetsConfig
=
new
HashMap
<>();
private
List
<
Map
<
String
,
String
>>
flinkConfigList
=
new
ArrayList
<>();
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
...
...
dinky-gateway/src/main/java/org/dinky/gateway/config/GatewayConfig.java
View file @
eb41090f
...
...
@@ -21,14 +21,12 @@ package org.dinky.gateway.config;
import
org.dinky.assertion.Asserts
;
import
org.dinky.gateway.enums.GatewayType
;
import
org.dinky.gateway.model.FlinkClusterConfig
;
import
org.apache.http.util.TextUtils
;
import
java.util.Arrays
;
import
java.util.Map
;
import
c
om.fasterxml.jackson.databind.ObjectMapper
;
import
c
n.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.lang.Assert
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -41,25 +39,13 @@ import lombok.Setter;
@Setter
public
class
GatewayConfig
{
public
static
final
String
FLINK_CONFIG_PATH
=
"flinkConfigPath"
;
public
static
final
String
FLINK_LIB_PATH
=
"flinkLibPath"
;
public
static
final
String
FLINK_VERSION
=
"flinkVersion"
;
public
static
final
String
HADOOP_CONFIG_PATH
=
"hadoopConfigPath"
;
public
static
final
String
USER_JAR_PATH
=
"userJarPath"
;
public
static
final
String
USER_JAR_MAIN_APP_CLASS
=
"userJarMainAppClass"
;
public
static
final
String
USER_JAR_PARAS
=
"userJarParas"
;
public
static
final
String
FLINK_CONFIG
=
"flinkConfig"
;
public
static
final
String
KUBERNETES_CONFIG
=
"kubernetesConfig"
;
public
static
final
String
TASK_CUSTOM_CONFIG
=
"taskCustomConfig"
;
private
Integer
taskId
;
private
String
[]
jarPaths
;
private
GatewayType
type
;
private
ClusterConfig
clusterConfig
;
private
FlinkConfig
flinkConfig
;
private
AppConfig
appConfig
;
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
private
K8sConfig
kubernetesConfig
;
public
GatewayConfig
()
{
clusterConfig
=
new
ClusterConfig
();
...
...
@@ -67,84 +53,20 @@ public class GatewayConfig {
appConfig
=
new
AppConfig
();
}
public
static
GatewayConfig
build
(
Map
<
String
,
Object
>
config
)
{
public
static
GatewayConfig
build
(
FlinkClusterConfig
config
)
{
Assert
.
notNull
(
config
);
GatewayConfig
gatewayConfig
=
new
GatewayConfig
();
gatewayConfig
.
setClusterConfig
(
getClusterConfig
(
config
));
gatewayConfig
.
setAppConfig
(
getAppConfig
(
config
));
gatewayConfig
.
setFlinkConfig
(
getFlinkConfig
(
config
));
if
(
config
.
containsKey
(
"taskId"
))
{
gatewayConfig
.
setTaskId
(
Integer
.
valueOf
(
config
.
get
(
"taskId"
).
toString
()));
}
return
gatewayConfig
;
}
private
static
FlinkConfig
getFlinkConfig
(
Map
<
String
,
Object
>
config
)
{
FlinkConfig
fc
=
new
FlinkConfig
();
if
(
config
.
containsKey
(
FLINK_CONFIG
)
&&
Asserts
.
isNotNullMap
((
Map
<
String
,
String
>)
config
.
get
(
FLINK_CONFIG
)))
{
fc
=
FlinkConfig
.
build
((
Map
<
String
,
String
>)
config
.
get
(
FLINK_CONFIG
));
}
final
Map
<
String
,
String
>
configuration
=
fc
.
getConfiguration
();
final
Map
<
String
,
String
>
k8sConfig
=
fc
.
getFlinkKubetnetsConfig
();
if
(
config
.
containsKey
(
KUBERNETES_CONFIG
))
{
Map
<
String
,
String
>
kubernetesConfig
=
(
Map
<
String
,
String
>)
config
.
get
(
KUBERNETES_CONFIG
);
k8sConfig
.
putAll
(
kubernetesConfig
);
}
if
(
config
.
containsKey
(
FLINK_VERSION
))
{
k8sConfig
.
put
(
FLINK_VERSION
,
String
.
valueOf
(
config
.
get
(
FLINK_VERSION
)));
}
// at present only k8s task have this
if
(
config
.
containsKey
(
TASK_CUSTOM_CONFIG
))
{
Map
<
String
,
Map
<
String
,
String
>>
taskCustomConfig
=
(
Map
<
String
,
Map
<
String
,
String
>>)
config
.
get
(
TASK_CUSTOM_CONFIG
);
if
(
taskCustomConfig
.
containsKey
(
KUBERNETES_CONFIG
))
{
k8sConfig
.
putAll
(
taskCustomConfig
.
get
(
KUBERNETES_CONFIG
));
}
if
(
taskCustomConfig
.
containsKey
(
FLINK_CONFIG
))
{
configuration
.
putAll
(
taskCustomConfig
.
get
(
FLINK_CONFIG
));
BeanUtil
.
copyProperties
(
config
,
gatewayConfig
);
for
(
Map
<
String
,
String
>
item
:
gatewayConfig
.
getFlinkConfig
().
getFlinkConfigList
())
{
if
(
Asserts
.
isNotNull
(
item
))
{
Assert
.
notNull
(
item
.
get
(
"name"
),
"Custer config has null item"
);
Assert
.
notNull
(
item
.
get
(
"value"
),
"Custer config has null item"
);
gatewayConfig
.
getFlinkConfig
()
.
getConfiguration
()
.
put
(
item
.
get
(
"name"
),
item
.
get
(
"value"
));
}
}
return
fc
;
}
private
static
AppConfig
getAppConfig
(
Map
<
String
,
Object
>
config
)
{
AppConfig
appConfig
=
new
AppConfig
();
if
(
config
.
containsKey
(
USER_JAR_PATH
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
USER_JAR_PATH
)))
{
appConfig
.
setUserJarPath
(
config
.
get
(
USER_JAR_PATH
).
toString
());
if
(
config
.
containsKey
(
USER_JAR_MAIN_APP_CLASS
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
USER_JAR_MAIN_APP_CLASS
)))
{
appConfig
.
setUserJarMainAppClass
(
config
.
get
(
USER_JAR_MAIN_APP_CLASS
).
toString
());
}
if
(
config
.
containsKey
(
USER_JAR_PARAS
)
&&
Asserts
.
isNotNullString
((
String
)
config
.
get
(
USER_JAR_PARAS
)))
{
// 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
(
USER_JAR_PARAS
).
toString
().
split
(
" "
);
appConfig
.
setUserJarParas
(
Arrays
.
stream
(
temp
)
.
filter
(
s
->
!
TextUtils
.
isEmpty
(
s
.
trim
()))
.
toArray
(
String
[]::
new
));
}
}
return
appConfig
;
}
private
static
ClusterConfig
getClusterConfig
(
Map
<
String
,
Object
>
config
)
{
if
(
config
.
containsKey
(
HADOOP_CONFIG_PATH
))
{
return
ClusterConfig
.
build
(
config
.
get
(
FLINK_CONFIG_PATH
).
toString
(),
config
.
get
(
FLINK_LIB_PATH
).
toString
(),
config
.
get
(
HADOOP_CONFIG_PATH
).
toString
());
}
else
{
return
ClusterConfig
.
build
(
String
.
valueOf
(
config
.
get
(
FLINK_CONFIG_PATH
)));
}
return
gatewayConfig
;
}
}
dinky-gateway/src/main/java/org/dinky/gateway/config/K8sConfig.java
0 → 100644
View file @
eb41090f
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org
.
dinky
.
gateway
.
config
;
import
java.util.HashMap
;
import
java.util.Map
;
import
lombok.Data
;
@Data
public
class
K8sConfig
{
private
Map
<
String
,
String
>
configuration
=
new
HashMap
<>();
private
Map
<
String
,
Object
>
dockerConfig
=
new
HashMap
<>();
private
String
podTemplate
;
private
String
jmPodTemplate
;
private
String
tmPodTemplate
;
}
dinky-gateway/src/main/java/org/dinky/gateway/enums/GatewayType.java
View file @
eb41090f
...
...
@@ -74,15 +74,7 @@ public enum GatewayType {
}
public
static
boolean
isDeployCluster
(
String
type
)
{
switch
(
get
(
type
))
{
case
YARN_APPLICATION:
case
YARN_PER_JOB:
case
KUBERNETES_APPLICATION:
case
KUBERNETES_APPLICATION_OPERATOR:
return
true
;
default
:
return
false
;
}
return
get
(
type
).
isDeployCluster
();
}
public
boolean
isDeployCluster
()
{
...
...
@@ -90,6 +82,7 @@ public enum GatewayType {
case
"ya"
:
case
"ypj"
:
case
"ka"
:
case
"kao"
:
return
true
;
default
:
return
false
;
...
...
dinky-gateway/src/main/java/org/dinky/gateway/kubernetes/KubernetesApplicationGateway.java
View file @
eb41090f
...
...
@@ -73,7 +73,7 @@ public class KubernetesApplicationGateway extends KubernetesGateway {
new
ApplicationConfiguration
(
userJarParas
,
appConfig
.
getUserJarMainAppClass
());
KubernetesResult
result
=
KubernetesResult
.
build
(
getType
());
;
try
(
KubernetesClusterDescriptor
kubernetesClusterDescriptor
=
new
KubernetesClusterDescriptor
(
configuration
,
client
))
{
ClusterClientProvider
<
String
>
clusterClientProvider
=
...
...
dinky-gateway/src/main/java/org/dinky/gateway/kubernetes/KubernetesGateway.java
View file @
eb41090f
...
...
@@ -23,10 +23,13 @@ import org.dinky.assertion.Asserts;
import
org.dinky.gateway.AbstractGateway
;
import
org.dinky.gateway.config.FlinkConfig
;
import
org.dinky.gateway.config.GatewayConfig
;
import
org.dinky.gateway.config.K8sConfig
;
import
org.dinky.gateway.exception.GatewayException
;
import
org.dinky.gateway.result.SavePointResult
;
import
org.dinky.gateway.result.TestResult
;
import
org.dinky.utils.TextUtil
;
import
org.apache.flink.configuration.ConfigOption
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.configuration.DeploymentOptions
;
import
org.apache.flink.configuration.DeploymentOptionsInternal
;
...
...
@@ -38,12 +41,13 @@ import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
import
org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory
;
import
org.apache.flink.runtime.jobgraph.SavepointConfigOptions
;
import
java.lang.reflect.Method
;
import
java.util.Collections
;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.util.ReflectUtil
;
/**
...
...
@@ -67,33 +71,45 @@ public abstract class KubernetesGateway extends AbstractGateway {
}
private
void
initConfig
()
{
configuration
=
GlobalConfiguration
.
loadConfiguration
(
config
.
getClusterConfig
().
getFlinkConfigPath
());
final
FlinkConfig
flinkConfig
=
config
.
getFlinkConfig
();
if
(
flinkConfig
.
getFlinkKubetnetsConfig
()
!=
null
)
{
flinkConfig
.
getConfiguration
().
putAll
(
flinkConfig
.
getFlinkKubetnetsConfig
());
}
if
(
Asserts
.
isNotNull
(
flinkConfig
.
getConfiguration
()))
{
addConfigParas
(
flinkConfig
.
getConfiguration
());
String
flinkConfigPath
=
config
.
getClusterConfig
().
getFlinkConfigPath
();
if
(!
TextUtil
.
isEmpty
(
flinkConfigPath
))
{
configuration
=
GlobalConfiguration
.
loadConfiguration
(
flinkConfigPath
);
}
FlinkConfig
flinkConfig
=
config
.
getFlinkConfig
();
flinkConfig
.
getConfiguration
().
putAll
(
config
.
getKubernetesConfig
().
getConfiguration
());
addConfigParas
(
flinkConfig
.
getConfiguration
());
configuration
.
set
(
DeploymentOptions
.
TARGET
,
getType
().
getLongValue
());
if
(
Asserts
.
isNotNullString
(
flinkConfig
.
getSavePoint
()))
{
configuration
.
setString
(
SavepointConfigOptions
.
SAVEPOINT_PATH
,
flinkConfig
.
getSavePoint
());
}
configuration
.
set
(
KubernetesConfigOptions
.
CLUSTER_ID
,
flinkConfig
.
getJobName
());
if
(
Asserts
.
isNotNullString
(
flinkConfig
.
getJobName
()))
{
configuration
.
set
(
KubernetesConfigOptions
.
CLUSTER_ID
,
flinkConfig
.
getJobName
());
}
K8sConfig
k8sConfig
=
config
.
getKubernetesConfig
();
preparPodTemplate
(
k8sConfig
.
getPodTemplate
(),
KubernetesConfigOptions
.
KUBERNETES_POD_TEMPLATE
);
preparPodTemplate
(
k8sConfig
.
getJmPodTemplate
(),
KubernetesConfigOptions
.
JOB_MANAGER_POD_TEMPLATE
);
preparPodTemplate
(
k8sConfig
.
getTmPodTemplate
(),
KubernetesConfigOptions
.
TASK_MANAGER_POD_TEMPLATE
);
if
(
getType
().
isApplicationMode
())
{
resetCheckpointInApplicationMode
();
}
}
public
void
preparPodTemplate
(
String
podTemplate
,
ConfigOption
<
String
>
option
)
{
if
(
TextUtil
.
isEmpty
(
podTemplate
))
{
return
;
}
String
filePath
=
String
.
format
(
"%s/tmp/Kubernets/%s.yaml"
,
System
.
getProperty
(
"user.dir"
),
config
.
getFlinkConfig
().
getJobName
());
if
(
FileUtil
.
exist
(
filePath
))
{
Assert
.
isTrue
(
FileUtil
.
del
(
filePath
));
}
FileUtil
.
writeUtf8String
(
podTemplate
,
filePath
);
configuration
.
set
(
option
,
filePath
);
}
private
void
initKubeClient
()
{
client
=
FlinkKubeClientFactory
.
getInstance
().
fromConfiguration
(
configuration
,
"client"
);
}
...
...
dinky-gateway/src/main/java/org/dinky/gateway/kubernetes/operator/KubernetsOperatorGateway.java
View file @
eb41090f
...
...
@@ -22,6 +22,8 @@ package org.dinky.gateway.kubernetes.operator;
import
org.dinky.assertion.Asserts
;
import
org.dinky.data.enums.JobStatus
;
import
org.dinky.gateway.AbstractGateway
;
import
org.dinky.gateway.config.FlinkConfig
;
import
org.dinky.gateway.config.K8sConfig
;
import
org.dinky.gateway.enums.UpgradeMode
;
import
org.dinky.gateway.kubernetes.operator.api.AbstractPodSpec
;
import
org.dinky.gateway.kubernetes.operator.api.AbstractPodSpec.Resource
;
...
...
@@ -32,6 +34,9 @@ import org.dinky.gateway.result.SavePointResult;
import
org.dinky.gateway.result.TestResult
;
import
org.dinky.process.context.ProcessContextHolder
;
import
org.dinky.process.model.ProcessEntity
;
import
org.dinky.utils.TextUtil
;
import
org.apache.flink.configuration.CoreOptions
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
...
...
@@ -53,8 +58,9 @@ import lombok.EqualsAndHashCode;
@Data
public
abstract
class
KubernetsOperatorGateway
extends
AbstractGateway
{
private
Map
<
String
,
String
>
submitConfiguration
;
private
Map
<
String
,
String
>
flinkConfig
;
private
Map
<
String
,
String
>
kubernetsConfiguration
;
private
K8sConfig
k8sConfig
;
private
FlinkConfig
flinkConfig
;
private
FlinkDeployment
flinkDeployment
=
new
FlinkDeployment
();
private
FlinkDeploymentSpec
flinkDeploymentSpec
=
new
FlinkDeploymentSpec
();
private
KubernetesClient
kubernetesClient
;
...
...
@@ -64,8 +70,9 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
@Override
protected
void
init
()
{
submitConfiguration
=
config
.
getFlinkConfig
().
getFlinkKubetnetsConfig
();
flinkConfig
=
config
.
getFlinkConfig
().
getConfiguration
();
kubernetsConfiguration
=
config
.
getKubernetesConfig
().
getConfiguration
();
flinkConfig
=
config
.
getFlinkConfig
();
k8sConfig
=
config
.
getKubernetesConfig
();
kubernetesClient
=
new
DefaultKubernetesClient
();
initBase
();
initMetadata
();
...
...
@@ -77,8 +84,8 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
@Override
public
TestResult
test
()
{
submitConfiguration
=
config
.
getFlinkConfig
().
getFlinkKubetnetsConfig
();
flinkConfig
=
config
.
getFlinkConfig
()
.
getConfiguration
()
;
kubernetsConfiguration
=
config
.
getKubernetesConfig
().
getConfiguration
();
flinkConfig
=
config
.
getFlinkConfig
();
config
.
getFlinkConfig
().
setJobName
(
"test"
);
kubernetesClient
=
new
DefaultKubernetesClient
();
initBase
();
...
...
@@ -92,7 +99,7 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
@Override
public
boolean
onJobFinishCallback
(
String
status
)
{
submitConfiguration
=
config
.
getFlinkConfig
().
getFlinkKubetnetsConfig
();
kubernetsConfiguration
=
config
.
getKubernetesConfig
().
getConfiguration
();
kubernetesClient
=
new
DefaultKubernetesClient
();
String
jobName
=
config
.
getFlinkConfig
().
getJobName
();
...
...
@@ -117,7 +124,8 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
String
jarMainClass
=
config
.
getAppConfig
().
getUserJarMainAppClass
();
String
userJarPath
=
config
.
getAppConfig
().
getUserJarPath
();
String
[]
userJarParas
=
config
.
getAppConfig
().
getUserJarParas
();
String
parallelism
=
flinkConfig
.
get
(
"parallelism.default"
);
String
parallelism
=
flinkConfig
.
getConfiguration
().
get
(
CoreOptions
.
DEFAULT_PARALLELISM
.
key
());
logger
.
info
(
"\nThe app config is : \njarMainClass:{}\n userJarPath:{}\n userJarParas:{}\n "
,
...
...
@@ -160,42 +168,40 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
Pod
defaultPod
;
AbstractPodSpec
jobManagerSpec
=
new
AbstractPodSpec
();
AbstractPodSpec
taskManagerSpec
=
new
AbstractPodSpec
();
String
jbcpu
=
submitConfiguration
.
getOrDefault
(
"kubernetes.jobmanager.cpu"
,
"1"
);
String
jbmem
=
flinkConfig
.
getOrDefault
(
"jobmanager.memory.process.size"
,
"1G"
);
String
jbcpu
=
kubernetsConfiguration
.
getOrDefault
(
"kubernetes.jobmanager.cpu"
,
"1"
);
String
jbmem
=
flinkConfig
.
getConfiguration
().
getOrDefault
(
"jobmanager.memory.process.size"
,
"1G"
);
logger
.
info
(
"jobmanager resource is : cpu-->{}, mem-->{}"
,
jbcpu
,
jbmem
);
process
.
info
(
String
.
format
(
"jobmanager resource is : cpu-->%s, mem-->%s"
,
jbcpu
,
jbmem
));
jobManagerSpec
.
setResource
(
new
Resource
(
Double
.
parseDouble
(
jbcpu
),
jbmem
));
String
tmcpu
=
submitConfiguration
.
getOrDefault
(
"kubernetes.taskmanager.cpu"
,
"1"
);
String
tmmem
=
flinkConfig
.
getOrDefault
(
"taskmanager.memory.process.size"
,
"1G"
);
String
tmcpu
=
kubernetsConfiguration
.
getOrDefault
(
"kubernetes.taskmanager.cpu"
,
"1"
);
String
tmmem
=
flinkConfig
.
getConfiguration
()
.
getOrDefault
(
"taskmanager.memory.process.size"
,
"1G"
);
logger
.
info
(
"taskmanager resource is : cpu-->{}, mem-->{}"
,
tmcpu
,
tmmem
);
process
.
info
(
String
.
format
(
"taskmanager resource is : cpu-->%s, mem-->%s"
,
tmcpu
,
tmmem
));
taskManagerSpec
.
setResource
(
new
Resource
(
Double
.
parseDouble
(
tmcpu
),
tmmem
));
if
(
submitConfiguration
.
containsKey
(
"kubernetes.pod-template"
))
{
if
(
!
TextUtil
.
isEmpty
(
k8sConfig
.
getPodTemplate
()
))
{
InputStream
inputStream
=
new
ByteArrayInputStream
(
submitConfiguration
.
get
(
"kubernetes.pod-template"
)
.
getBytes
(
StandardCharsets
.
UTF_8
));
k8sConfig
.
getPodTemplate
().
getBytes
(
StandardCharsets
.
UTF_8
));
defaultPod
=
kubernetesClient
.
pods
().
load
(
inputStream
).
get
();
flinkDeploymentSpec
.
setPodTemplate
(
defaultPod
);
}
if
(
submitConfiguration
.
containsKey
(
"kubernetes.pod-template.jobmanager"
))
{
if
(
!
TextUtil
.
isEmpty
(
k8sConfig
.
getJmPodTemplate
()
))
{
InputStream
inputStream
=
new
ByteArrayInputStream
(
submitConfiguration
.
get
(
"kubernetes.pod-template.jobmanager"
)
.
getBytes
(
StandardCharsets
.
UTF_8
));
k8sConfig
.
getJmPodTemplate
().
getBytes
(
StandardCharsets
.
UTF_8
));
Pod
pod
=
kubernetesClient
.
pods
().
load
(
inputStream
).
get
();
jobManagerSpec
.
setPodTemplate
(
pod
);
}
if
(
submitConfiguration
.
containsKey
(
"kubernetes.pod-template.taskmanager"
))
{
if
(
!
TextUtil
.
isEmpty
(
k8sConfig
.
getTmPodTemplate
()
))
{
InputStream
inputStream
=
new
ByteArrayInputStream
(
submitConfiguration
.
get
(
"kubernetes.pod-template.taskmanager"
)
.
getBytes
(
StandardCharsets
.
UTF_8
));
k8sConfig
.
getTmPodTemplate
().
getBytes
(
StandardCharsets
.
UTF_8
));
Pod
pod
=
kubernetesClient
.
pods
().
load
(
inputStream
).
get
();
taskManagerSpec
.
setPodTemplate
(
pod
);
}
...
...
@@ -204,9 +210,9 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
}
private
void
initSpec
()
{
String
flinkVersion
=
submitConfiguration
.
get
(
"flinkVersion"
);
String
image
=
submit
Configuration
.
get
(
"kubernetes.container.image"
);
String
serviceAccount
=
submit
Configuration
.
get
(
"kubernetes.service.account"
);
String
flinkVersion
=
flinkConfig
.
getFlinkVersion
(
);
String
image
=
kubernets
Configuration
.
get
(
"kubernetes.container.image"
);
String
serviceAccount
=
kubernets
Configuration
.
get
(
"kubernetes.service.account"
);
logger
.
info
(
"\nflinkVersion is : {} \n image is : {}"
,
flinkVersion
,
image
);
process
.
info
(
String
.
format
(
"\nflinkVersion is : %s \n image is : %s"
,
flinkVersion
,
image
));
...
...
@@ -220,7 +226,7 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
flinkDeploymentSpec
.
setImage
(
image
);
flinkDeploymentSpec
.
setFlinkConfiguration
(
flinkConfig
);
flinkDeploymentSpec
.
setFlinkConfiguration
(
flinkConfig
.
getConfiguration
()
);
flinkDeployment
.
setSpec
(
flinkDeploymentSpec
);
if
(
Asserts
.
isNotNull
(
serviceAccount
))
{
...
...
@@ -242,7 +248,7 @@ public abstract class KubernetsOperatorGateway extends AbstractGateway {
private
void
initMetadata
()
{
String
jobName
=
config
.
getFlinkConfig
().
getJobName
();
String
nameSpace
=
submit
Configuration
.
get
(
"kubernetes.namespace"
);
String
nameSpace
=
kubernets
Configuration
.
get
(
"kubernetes.namespace"
);
logger
.
info
(
"\njobName is :{} \n namespce is : {}"
,
jobName
,
nameSpace
);
process
.
info
(
String
.
format
(
"\njobName is :%s \n namespce is : %s"
,
jobName
,
nameSpace
));
...
...
dinky-
common/src/main/java/org/dinky/data/model/FlinkClusterConfiguration
.java
→
dinky-
gateway/src/main/java/org/dinky/gateway/model/FlinkClusterConfig
.java
View file @
eb41090f
...
...
@@ -17,9 +17,13 @@
*
*/
package
org
.
dinky
.
data
.
model
;
package
org
.
dinky
.
gateway
.
model
;
import
java.util.Map
;
import
org.dinky.gateway.config.AppConfig
;
import
org.dinky.gateway.config.ClusterConfig
;
import
org.dinky.gateway.config.FlinkConfig
;
import
org.dinky.gateway.config.K8sConfig
;
import
org.dinky.gateway.enums.GatewayType
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -27,21 +31,10 @@ import lombok.Setter;
/** @since */
@Getter
@Setter
public
class
FlinkClusterConfiguration
{
private
Type
type
;
private
String
hadoopConfigPath
;
private
String
flinkConfigPath
;
private
String
flinkLibPath
;
private
String
userJarPath
;
private
String
flinkVersion
;
Map
<
String
,
String
>
flinkConfig
;
Map
<
String
,
String
>
kubernetesConfig
;
public
enum
Type
{
//
Yarn
,
Kubernetes
,
KubernetesOperator
;
}
public
class
FlinkClusterConfig
{
private
GatewayType
type
;
private
ClusterConfig
clusterConfig
;
private
FlinkConfig
flinkConfig
;
private
AppConfig
appConfig
;
private
K8sConfig
kubernetesConfig
;
}
dinky-gateway/src/main/java/org/dinky/gateway/yarn/YarnGateway.java
View file @
eb41090f
...
...
@@ -37,7 +37,6 @@ import org.apache.flink.client.program.ClusterClient;
import
org.apache.flink.configuration.DeploymentOptions
;
import
org.apache.flink.configuration.GlobalConfiguration
;
import
org.apache.flink.configuration.SecurityOptions
;
import
org.apache.flink.runtime.jobgraph.SavepointConfigOptions
;
import
org.apache.flink.runtime.security.SecurityConfiguration
;
import
org.apache.flink.runtime.security.SecurityUtils
;
import
org.apache.flink.yarn.YarnClientYarnClusterInformationRetriever
;
...
...
@@ -99,10 +98,6 @@ public abstract class YarnGateway extends AbstractGateway {
}
configuration
.
set
(
DeploymentOptions
.
TARGET
,
getType
().
getLongValue
());
final
String
savePoint
=
flinkConfig
.
getSavePoint
();
if
(
Asserts
.
isNotNullString
(
savePoint
))
{
configuration
.
setString
(
SavepointConfigOptions
.
SAVEPOINT_PATH
,
savePoint
);
}
configuration
.
set
(
YarnConfigOptions
.
PROVIDED_LIB_DIRS
,
...
...
dinky-web/src/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/ApplicationConfig/index.tsx
View file @
eb41090f
...
...
@@ -28,7 +28,7 @@ const ApplicationConfig = () => {
<
ProFormGroup
labelLayout=
{
'inline'
}
>
<
ProFormText
width=
{
'xl'
}
name=
{
[
"configJson"
,
"userJarPath"
]
}
name=
{
[
"configJson"
,
'appConfig'
,
"userJarPath"
]
}
placeholder=
{
l
(
'rc.cc.sqlSubmitJarPathHelp'
)
}
label=
{
l
(
'rc.cc.sqlSubmitJarPath'
)
}
tooltip=
{
l
(
'rc.cc.sqlSubmitJarPathHelp'
)
}
...
...
dinky-web/src/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/FlinkK8s/index.tsx
View file @
eb41090f
...
...
@@ -48,13 +48,13 @@ const FlinkK8s = (props: { type: string, value: any }) => {
<
ProFormText
tooltip=
{
item
.
tooltip
}
key=
{
item
.
name
}
name=
{
[
'configJson'
,
'kubernetesConfig'
,
item
.
name
]
}
name=
{
[
'configJson'
,
'kubernetesConfig'
,
'configuration'
,
item
.
name
]
}
label=
{
item
.
label
}
width=
{
250
}
placeholder=
{
item
.
placeholder
}
/>
)
}
<
ProFormList
name=
{
[
'configJson'
,
'flinkConfigList'
]
}
name=
{
[
'configJson'
,
'flinkConfig'
,
'flinkConfigList'
]
}
copyIconProps=
{
false
}
deleteIconProps=
{
{
tooltipText
:
l
(
'rc.cc.deleteConfig'
),}
}
creatorButtonProps=
{
{
style
:
{
width
:
'32vw'
},
creatorButtonText
:
l
(
'rc.cc.addConfig'
),}
}
...
...
@@ -72,24 +72,24 @@ const FlinkK8s = (props: { type: string, value: any }) => {
key
:
"defaultPodTemplate"
,
label
:
<
TagAlignCenter
>
Default Pod Template
</
TagAlignCenter
>,
children
:
<
ProFormItem
key=
"dpe"
name=
{
[
'configJson'
,
'podTemplate'
]
}
>
<
CodeEdit
{
...
CodeEditProps
}
code=
{
value
.
configJson
.
podTemplate
}
/>
<
ProFormItem
key=
"dpe"
name=
{
[
'configJson'
,
'
kubernetesConfig'
,
'
podTemplate'
]
}
>
<
CodeEdit
{
...
CodeEditProps
}
code=
{
value
.
configJson
.
kubernetesConfig
.
podTemplate
}
/>
</
ProFormItem
>
},
{
key
:
"JMPodTemplate"
,
label
:
<
TagAlignCenter
>
JM Pod Template
</
TagAlignCenter
>,
children
:
<
ProFormItem
key=
"jmdpe"
name=
{
[
'configJson'
,
'
JMp
odTemplate'
]
}
>
<
CodeEdit
{
...
CodeEditProps
}
code=
{
value
.
configJson
.
JMp
odTemplate
}
/>
<
ProFormItem
key=
"jmdpe"
name=
{
[
'configJson'
,
'
kubernetesConfig'
,
'jmP
odTemplate'
]
}
>
<
CodeEdit
{
...
CodeEditProps
}
code=
{
value
.
configJson
.
kubernetesConfig
.
jmP
odTemplate
}
/>
</
ProFormItem
>
},
{
key
:
"TMPodTemplate"
,
label
:
<
TagAlignCenter
>
TM Pod Template
</
TagAlignCenter
>,
children
:
<
ProFormItem
key=
"tmdpe"
name=
{
[
'configJson'
,
'
TMp
odTemplate'
]
}
>
<
CodeEdit
{
...
CodeEditProps
}
code=
{
value
.
configJson
.
TMp
odTemplate
}
/>
<
ProFormItem
key=
"tmdpe"
name=
{
[
'configJson'
,
'
kubernetesConfig'
,
'tmP
odTemplate'
]
}
>
<
CodeEdit
{
...
CodeEditProps
}
code=
{
value
.
configJson
.
kubernetesConfig
.
tmP
odTemplate
}
/>
</
ProFormItem
>
},
];
...
...
@@ -101,7 +101,7 @@ const FlinkK8s = (props: { type: string, value: any }) => {
<
ProFormGroup
>
{
(
type
&&
type
===
ClusterType
.
KUBERNETES_NATIVE
)
&&
<
ProFormSelect
name=
{
[
'configJson'
,
'kubernetesConfig'
,
'kubernetes.rest-service.exposed.type'
]
}
name=
{
[
'configJson'
,
'kubernetesConfig'
,
'configuration'
,
'kubernetes.rest-service.exposed.type'
]
}
label=
{
l
(
'rc.cc.k8s.exposed'
)
}
tooltip=
{
l
(
'rc.cc.k8s.exposedHelp'
)
}
placeholder=
{
l
(
'rc.cc.k8s.exposedHelp'
)
}
...
...
@@ -110,7 +110,7 @@ const FlinkK8s = (props: { type: string, value: any }) => {
/>
}
{
(
type
&&
type
===
ClusterType
.
KUBERNETES_OPERATOR
)
&&
<
ProFormSelect
name=
{
[
'configJson'
,
'flinkVersion'
]
}
name=
{
[
'configJson'
,
'flinkConfig'
,
'flinkVersion'
]
}
label=
{
l
(
'rc.cc.k8sOp.version'
)
}
width=
{
250
}
placeholder=
{
l
(
'rc.cc.k8sOp.versionHelp'
)
}
...
...
dinky-web/src/pages/RegCenter/Cluster/Configuration/components/ConfigurationModal/ConfigurationForm/HighPriorityConfig/index.tsx
View file @
eb41090f
...
...
@@ -28,7 +28,7 @@ const HighPriorityConfig = () => {
const
renderHighPriorityConfig
=
()
=>
{
return
FLINK_CONFIG_LIST
.
map
(
item
=>
<>
<
ProFormText
name=
{
[
'configJson'
,
'flinkConfig'
,
item
.
name
]
}
name=
{
[
'configJson'
,
'flinkConfig'
,
'configuration'
,
item
.
name
]
}
label=
{
item
.
label
}
width=
{
400
}
placeholder=
{
item
.
placeholder
}
...
...
@@ -41,6 +41,11 @@ const HighPriorityConfig = () => {
<
Divider
>
{
l
(
'rc.cc.defineConfig'
)
}
</
Divider
>
<
ProFormGroup
direction=
{
'horizontal'
}
align=
{
'baseline'
}
>
{
renderHighPriorityConfig
()
}
<
ProFormText
name=
{
[
'configJson'
,
'clusterConfig'
,
'flinkConfigPath'
]
}
label=
{
"Flink Conf Yaml Path"
}
width=
{
400
}
/>
</
ProFormGroup
>
</>
}
...
...
dinky-web/src/pages/RegCenter/Cluster/constants.ts
View file @
eb41090f
...
...
@@ -19,11 +19,11 @@
export
const
enum
ClusterType
{
STANDALONE
=
'
S
tandalone'
,
YARN
=
'
Yar
n'
,
YARN_SESSION
=
'
Yarn S
ession'
,
KUBERNETES_SESSION
=
'
Kubernetes S
ession'
,
KUBERNETES_NATIVE
=
'
Kubernetes
'
,
KUBERNETES_OPERATOR
=
'
KubernetesO
perator'
,
STANDALONE
=
'
s
tandalone'
,
YARN
=
'
yarn-applicatio
n'
,
YARN_SESSION
=
'
yarn-s
ession'
,
KUBERNETES_SESSION
=
'
kubernetes-s
ession'
,
KUBERNETES_NATIVE
=
'
kubernetes-application
'
,
KUBERNETES_OPERATOR
=
'
kubernetes-application-o
perator'
,
};
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