Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
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
liyuan
byit-myth-job
Commits
8edbcee1
Commit
8edbcee1
authored
Jan 02, 2020
by
guominglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
插件端工作流保存进行环路校验
parent
7ff3247d
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
404 additions
and
205 deletions
+404
-205
ApiFlowController.java
...h-admin/src/main/java/com/byit/api/ApiFlowController.java
+3
-25
ApiFlowService.java
...-admin/src/main/java/com/byit/service/ApiFlowService.java
+10
-8
ApiFlowServiceImpl.java
...c/main/java/com/byit/service/impl/ApiFlowServiceImpl.java
+112
-11
DagCheckEnum.java
...admin-core/src/main/java/com/byit/enums/DagCheckEnum.java
+38
-0
FlowPropertyEnum.java
...n-core/src/main/java/com/byit/enums/FlowPropertyEnum.java
+2
-0
FlowMapper.java
...-admin-core/src/main/java/com/byit/mapper/FlowMapper.java
+9
-0
WorkspaceMapper.java
...n-core/src/main/java/com/byit/mapper/WorkspaceMapper.java
+7
-3
ApiFlowDagCheck.java
...min-core/src/main/java/com/byit/util/ApiFlowDagCheck.java
+153
-11
DagCheck.java
...myth-admin-core/src/main/java/com/byit/util/DagCheck.java
+1
-0
FlowMapper.xml
.../myth-admin-core/src/main/resources/mapper/FlowMapper.xml
+12
-45
WorkspaceMapper.xml
...-admin-core/src/main/resources/mapper/WorkspaceMapper.xml
+10
-17
PluginBaseNode.java
...src/main/java/com/byit/job/dto/plugin/PluginBaseNode.java
+9
-3
PluginFlow.java
...mon/src/main/java/com/byit/job/dto/plugin/PluginFlow.java
+2
-23
PluginInnerFlow.java
...rc/main/java/com/byit/job/dto/plugin/PluginInnerFlow.java
+0
-40
PluginNode.java
...mon/src/main/java/com/byit/job/dto/plugin/PluginNode.java
+0
-6
PluginPackage.java
.../src/main/java/com/byit/job/dto/plugin/PluginPackage.java
+6
-13
PluginNodeTypeEnum.java
...in/java/com/byit/job/enums/plugin/PluginNodeTypeEnum.java
+30
-0
No files found.
byit-myth-admin/src/main/java/com/byit/api/ApiFlowController.java
View file @
8edbcee1
package
com
.
byit
.
api
;
package
com
.
byit
.
api
;
import
com.byit.job.dto.plugin.PluginFlow
;
import
com.byit.job.dto.plugin.PluginPackage
;
import
com.byit.job.dto.plugin.PluginFlowDepend
;
import
com.byit.service.ApiFlowService
;
import
com.byit.service.ApiFlowService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -27,8 +26,8 @@ public class ApiFlowController {
...
@@ -27,8 +26,8 @@ public class ApiFlowController {
@PostMapping
(
"publish"
)
@PostMapping
(
"publish"
)
@ApiOperation
(
"发布工作流,并开始调度"
)
@ApiOperation
(
"发布工作流,并开始调度"
)
public
String
publishFlow
(
@RequestBody
Plugin
Flow
flow
){
public
String
publishFlow
(
@RequestBody
Plugin
Package
pluginPackage
){
apiFlowService
.
publishFlow
(
flow
);
apiFlowService
.
publishFlow
(
pluginPackage
);
return
"SUCCESS"
;
return
"SUCCESS"
;
}
}
...
@@ -39,27 +38,6 @@ public class ApiFlowController {
...
@@ -39,27 +38,6 @@ public class ApiFlowController {
return
"SUCCESS"
;
return
"SUCCESS"
;
}
}
@PostMapping
(
"addDepend"
)
@ApiOperation
(
"添加工作流依赖,只是添加一个依赖"
)
public
String
addDepend
(
String
flowName
,
String
dependFlowName
,
String
workspaceName
){
apiFlowService
.
addDepend
(
flowName
,
dependFlowName
,
workspaceName
);
return
"SUCCESS"
;
}
@PostMapping
(
"resetDepend"
)
@ApiOperation
(
"重置工作流依赖,将工作流的所有依赖重置为依赖工作流名称集合中的工作流"
)
public
String
resetDepend
(
@RequestBody
PluginFlowDepend
flowDepend
){
apiFlowService
.
resetDepend
(
flowDepend
);
return
"SUCCESS"
;
}
@PostMapping
(
"deleteDepend"
)
@ApiOperation
(
"删除工作流依赖,只是删除一个依赖关系"
)
public
String
deleteDepend
(
String
flowName
,
String
dependFlowName
,
String
workspaceName
){
apiFlowService
.
deleteDepend
(
flowName
,
dependFlowName
,
workspaceName
);
return
"SUCCESS"
;
}
@PostMapping
(
"start"
)
@PostMapping
(
"start"
)
@ApiOperation
(
"开始工作流的调度,将工作流启用调度"
)
@ApiOperation
(
"开始工作流的调度,将工作流启用调度"
)
public
String
start
(
String
flowName
,
String
workspaceName
){
public
String
start
(
String
flowName
,
String
workspaceName
){
...
...
byit-myth-admin/src/main/java/com/byit/service/ApiFlowService.java
View file @
8edbcee1
package
com
.
byit
.
service
;
package
com
.
byit
.
service
;
import
com.byit.job.dto.plugin.PluginFlow
;
import
com.byit.job.dto.plugin.PluginFlow
;
import
com.byit.job.dto.plugin.Plugin
FlowDepend
;
import
com.byit.job.dto.plugin.Plugin
Package
;
/**
/**
* @description: 工作流的api请求业务处理接口
* @description: 工作流的api请求业务处理接口
...
@@ -12,12 +12,6 @@ public interface ApiFlowService {
...
@@ -12,12 +12,6 @@ public interface ApiFlowService {
void
deleteFlow
(
String
flowName
);
void
deleteFlow
(
String
flowName
);
void
addDepend
(
String
flowName
,
String
dependFlowName
,
String
workspaceName
);
void
resetDepend
(
PluginFlowDepend
flowDepend
);
void
deleteDepend
(
String
flowName
,
String
dependFlowName
,
String
workspaceName
);
void
start
(
String
flowName
,
String
workspaceName
);
void
start
(
String
flowName
,
String
workspaceName
);
void
repealSchedule
(
String
flowName
,
String
workspaceName
);
void
repealSchedule
(
String
flowName
,
String
workspaceName
);
...
@@ -28,5 +22,13 @@ public interface ApiFlowService {
...
@@ -28,5 +22,13 @@ public interface ApiFlowService {
void
reStartSchedule
(
String
runId
);
void
reStartSchedule
(
String
runId
);
void
publishFlow
(
PluginFlow
flow
);
void
publishFlow
(
PluginPackage
pluginPackage
);
/**
* 判断工作流石佛存在
* @param workspaceId
* @param flow
* @return
*/
void
validateFlow
(
Integer
workspaceId
,
PluginFlow
flow
);
}
}
byit-myth-admin/src/main/java/com/byit/service/impl/ApiFlowServiceImpl.java
View file @
8edbcee1
package
com
.
byit
.
service
.
impl
;
package
com
.
byit
.
service
.
impl
;
import
com.byit.enums.DagCheckEnum
;
import
com.byit.enums.FlowPropertyEnum
;
import
com.byit.job.dto.plugin.PluginBaseNode
;
import
com.byit.job.dto.plugin.PluginFlow
;
import
com.byit.job.dto.plugin.PluginFlow
;
import
com.byit.job.dto.plugin.PluginFlowDepend
;
import
com.byit.job.dto.plugin.PluginPackage
;
import
com.byit.job.enums.plugin.PluginNodeTypeEnum
;
import
com.byit.job.utils.CronExpression
;
import
com.byit.mapper.FlowMapper
;
import
com.byit.mapper.FlowMapper
;
import
com.byit.mapper.WorkspaceMapper
;
import
com.byit.mapper.WorkspaceMapper
;
import
com.byit.model.Flow
;
import
com.byit.model.Workspace
;
import
com.byit.service.ApiFlowService
;
import
com.byit.service.ApiFlowService
;
import
com.byit.util.ApiFlowDagCheck
;
import
com.byit.utils.ValidationUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
/**
/**
* @description: 工作流的Api请求业务处理实现类
* @description: 工作流的Api请求业务处理实现类
* @author: gml
* @author: gml
* @create: 2019-12-30 14:37
* @create: 2019-12-30 14:37
*/
*/
@Slf4j
@Service
@Service
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
ApiFlowServiceImpl
implements
ApiFlowService
{
public
class
ApiFlowServiceImpl
implements
ApiFlowService
{
...
@@ -26,27 +40,114 @@ public class ApiFlowServiceImpl implements ApiFlowService {
...
@@ -26,27 +40,114 @@ public class ApiFlowServiceImpl implements ApiFlowService {
private
WorkspaceMapper
workspaceMapper
;
private
WorkspaceMapper
workspaceMapper
;
@Override
@Override
public
void
publishFlow
(
PluginFlow
flow
)
{
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
publishFlow
(
PluginPackage
pluginPackage
)
{
//校验参数
validate
(
pluginPackage
);
}
}
@Override
/**
public
void
deleteFlow
(
String
flowName
)
{
* 校验插件端请求参数是否合法
* @param pluginPackage
*/
private
void
validate
(
PluginPackage
pluginPackage
)
{
ValidationUtil
.
dataNotBank
(
pluginPackage
.
getWorkspaceName
(),
"工作空间名称不允许为空!"
);
ValidationUtil
.
dataNotNull
(
pluginPackage
.
getFlow
(),
"工作流信息不允许为空!"
);
Workspace
workspace
=
workspaceMapper
.
getByName
(
pluginPackage
.
getWorkspaceName
());
ValidationUtil
.
dataNotNull
(
workspace
,
"工作空间不存在,请先添加工作空间"
);
PluginFlow
flow
=
pluginPackage
.
getFlow
();
//校验工作流参数配置
validateFlow
(
workspace
.
getWorkspaceId
(),
flow
);
//校验工作流名称是否重复
HashSet
<
String
>
flowNameSet
=
new
HashSet
<>();
//用来工作流的内嵌关系
HashMap
<
String
,
Integer
>
lineMap
=
new
HashMap
<>();
//父工作流
HashSet
<
String
>
fromFlowSet
=
new
HashSet
<>();
//内嵌工作流
HashSet
<
String
>
toFlowSet
=
new
HashSet
<>();
checkFlow
(
workspace
,
flow
,
flowNameSet
,
fromFlowSet
,
toFlowSet
,
lineMap
);
//校验内嵌的工作流是否存在环路
ApiFlowDagCheck
flowDagCheck
=
new
ApiFlowDagCheck
();
flowDagCheck
.
initDag
(
flowNameSet
,
fromFlowSet
,
toFlowSet
,
lineMap
);
//校验是否存在环路
DagCheckEnum
loopCheck
=
flowDagCheck
.
checkDag
();
ValidationUtil
.
isTrueValidation
(
DagCheckEnum
.
PASS
.
getCode
().
equals
(
loopCheck
.
getCode
()),
loopCheck
.
getMsg
());
}
}
@Override
/**
public
void
addDepend
(
String
flowName
,
String
dependFlowName
,
String
workspaceName
)
{
* 校验工作流
* @param workspace
* @param flow
* @param flowNameSet
* @param fromFlowSet
* @param flowNameSet
* @param lineMap
*/
private
void
checkFlow
(
Workspace
workspace
,
PluginFlow
flow
,
HashSet
<
String
>
flowNameSet
,
HashSet
<
String
>
fromFlowSet
,
HashSet
<
String
>
toFlowSet
,
HashMap
<
String
,
Integer
>
lineMap
)
{
//校验是否存在重名工作流
ValidationUtil
.
isTrueValidation
(!
flowNameSet
.
add
(
flow
.
getName
()),
"同一个工作空间内工作流名称不允许重复!"
);
fromFlowSet
.
add
(
flow
.
getName
());
List
<
PluginBaseNode
>
nodeList
=
flow
.
getNodeList
();
//用来校验同一工作流下是否有重复的节点
HashSet
<
String
>
nodeSet
=
new
HashSet
<>();
nodeList
.
forEach
(
node
->
{
ValidationUtil
.
dataNotBank
(
node
.
getName
(),
"节点名称不允许为空!"
);
ValidationUtil
.
isTrueValidation
(!
nodeSet
.
add
(
node
.
getName
()),
"同一个工作流下任务节点不允许重复!"
);
//判断节点类型
if
(
PluginNodeTypeEnum
.
FLOW
.
getCode
().
equals
(
node
.
getType
())){
//校验node的类别
ValidationUtil
.
isTrueValidation
(!(
node
instanceof
PluginFlow
),
"工作流的type设置错误,只有当节点为内嵌工作流是type才允许设置为flow"
);
//校验父工作流和内嵌工作流的执行类型是否一致
ValidationUtil
.
isTrueValidation
(!(
flow
.
getConfig
().
getExecType
().
equals
(((
PluginFlow
)
node
).
getConfig
().
getExecType
())),
"内嵌工作流的调度配置必须和父工作流配置保持一致!"
);
validateFlow
(
workspace
.
getWorkspaceId
(),
(
PluginFlow
)
node
);
toFlowSet
.
add
(
node
.
getName
());
lineMap
.
put
(
flow
.
getName
()
+
"_"
+
node
.
getName
(),
1
);
checkFlow
(
workspace
,
(
PluginFlow
)
node
,
flowNameSet
,
fromFlowSet
,
toFlowSet
,
lineMap
);
}
});
//校验同一个工作流下的任务节点是否存在环路
ApiFlowDagCheck
nodeDagCheck
=
new
ApiFlowDagCheck
();
nodeDagCheck
.
initDag
(
nodeList
);
//校验开始节点名称
DagCheckEnum
checkStart
=
nodeDagCheck
.
checkStart
();
ValidationUtil
.
isTrueValidation
(
DagCheckEnum
.
PASS
.
getCode
().
equals
(
checkStart
.
getCode
()),
checkStart
.
getCode
()
==
0
?
checkStart
.
getMsg
()
:
checkStart
.
getMsg
()
+
"start"
);
//校验结束节点名称
DagCheckEnum
endCheck
=
nodeDagCheck
.
checkEnd
();
ValidationUtil
.
isTrueValidation
(
DagCheckEnum
.
PASS
.
getCode
().
equals
(
endCheck
.
getCode
()),
endCheck
.
getCode
()
==
0
?
endCheck
.
getMsg
()
:
endCheck
.
getMsg
()
+
"end"
);
//校验是否有游离节点
DagCheckEnum
freeCheck
=
nodeDagCheck
.
checkFreeNode
();
ValidationUtil
.
isTrueValidation
(
DagCheckEnum
.
PASS
.
getCode
().
equals
(
freeCheck
.
getCode
()),
freeCheck
.
getMsg
());
//校验是否存在环路
DagCheckEnum
loopCheck
=
nodeDagCheck
.
checkDag
();
ValidationUtil
.
isTrueValidation
(
DagCheckEnum
.
PASS
.
getCode
().
equals
(
loopCheck
.
getCode
()),
loopCheck
.
getMsg
());
}
}
@Override
@Override
public
void
resetDepend
(
PluginFlowDepend
flowDepend
)
{
public
void
validateFlow
(
Integer
workspaceId
,
PluginFlow
pluginFlow
)
{
ValidationUtil
.
dataNotBank
(
pluginFlow
.
getName
(),
"工作流名称不允许为空!"
);
ValidationUtil
.
dataNotNull
(
pluginFlow
.
getConfig
(),
"工作流配置不允许为空!"
);
ValidationUtil
.
dataNotBank
(
pluginFlow
.
getConfig
().
getExecType
(),
"工作流的调度类型不允许为空!"
);
if
(
FlowPropertyEnum
.
SCHEDULE_MODE
.
getCode
().
equals
(
pluginFlow
.
getConfig
().
getExecType
())){
ValidationUtil
.
dataNotBank
(
pluginFlow
.
getConfig
().
getFlowCron
(),
"工作流cron表达式不允许为空!"
);
ValidationUtil
.
isTrueValidation
(
CronExpression
.
isValidExpression
(
pluginFlow
.
getConfig
().
getFlowCron
()),
"工作流cron表达式不符合规范!"
);
}
Flow
flow
=
flowMapper
.
getByWorkSpaceAndName
(
workspaceId
,
pluginFlow
.
getName
());
//判断是否是重发
//是重发
if
(
pluginFlow
.
isRePublish
()){
ValidationUtil
.
dataNotNull
(
flow
,
"工作流【"
+
flow
.
getFlowName
()
+
"】不存在!"
);
}
else
{
//不是重发
ValidationUtil
.
isTrueValidation
(
null
!=
flow
,
"工作流【"
+
flow
.
getFlowName
()
+
"】已存在!"
);
}
}
}
@Override
@Override
public
void
delete
Depend
(
String
flowName
,
String
dependFlowName
,
String
workspace
Name
)
{
public
void
delete
Flow
(
String
flow
Name
)
{
}
}
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/enums/DagCheckEnum.java
0 → 100644
View file @
8edbcee1
package
com
.
byit
.
enums
;
import
lombok.Getter
;
@Getter
public
enum
DagCheckEnum
{
LOOP
(
0
,
"存在环路"
),
FREE
(
1
,
"存在游离节点"
),
PASS
(
2
,
"校验通过"
),
STARTNAME_WRONG
(
3
,
"开始节点必须是"
),
ENDNAME_WRONG
(
4
,
"结束节点必须是"
),
;
private
Integer
code
;
private
String
msg
;
private
DagCheckEnum
(
Integer
code
,
String
msg
){
this
.
code
=
code
;
this
.
msg
=
msg
;
}
public
Integer
getCode
(){
return
this
.
code
;
}
public
String
getMsg
(){
return
this
.
msg
;
}
public
static
String
getNameByCode
(
Integer
code
)
{
for
(
DagCheckEnum
type
:
DagCheckEnum
.
values
())
{
if
(
type
.
getCode
().
equals
(
code
))
{
return
type
.
getMsg
();
}
}
return
null
;
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/enums/FlowPropertyEnum.java
View file @
8edbcee1
...
@@ -11,6 +11,8 @@ public enum FlowPropertyEnum {
...
@@ -11,6 +11,8 @@ public enum FlowPropertyEnum {
ISNOT_INNER
(
"1"
,
"不是内嵌工作流"
),
ISNOT_INNER
(
"1"
,
"不是内嵌工作流"
),
IS_START
(
"0"
,
"启动"
),
IS_START
(
"0"
,
"启动"
),
NO_START
(
"1"
,
"未启动"
),
NO_START
(
"1"
,
"未启动"
),
MANUAL_MODE
(
"2"
,
"手动执行"
),
SCHEDULE_MODE
(
"1"
,
"周期执行"
)
;
;
private
String
code
;
private
String
code
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/mapper/FlowMapper.java
View file @
8edbcee1
package
com
.
byit
.
mapper
;
package
com
.
byit
.
mapper
;
import
com.byit.model.Flow
;
import
com.byit.model.Flow
;
import
org.apache.ibatis.annotations.Param
;
public
interface
FlowMapper
{
public
interface
FlowMapper
{
int
deleteById
(
Integer
flowId
);
int
deleteById
(
Integer
flowId
);
...
@@ -11,4 +12,11 @@ public interface FlowMapper {
...
@@ -11,4 +12,11 @@ public interface FlowMapper {
int
updateByIdSelective
(
Flow
record
);
int
updateByIdSelective
(
Flow
record
);
/**
* 根据工作空间和工作流名称查找是否存在工作流
* @param workspaceId
* @param flowName
* @return
*/
Flow
getByWorkSpaceAndName
(
@Param
(
"workspaceId"
)
Integer
workspaceId
,
@Param
(
"flowName"
)
String
flowName
);
}
}
\ No newline at end of file
byit-myth-core/myth-admin-core/src/main/java/com/byit/mapper/WorkspaceMapper.java
View file @
8edbcee1
...
@@ -5,13 +5,16 @@ import com.byit.model.Workspace;
...
@@ -5,13 +5,16 @@ import com.byit.model.Workspace;
public
interface
WorkspaceMapper
{
public
interface
WorkspaceMapper
{
int
deleteById
(
Integer
workspaceId
);
int
deleteById
(
Integer
workspaceId
);
int
insert
(
Workspace
record
);
int
insertSelective
(
Workspace
record
);
int
insertSelective
(
Workspace
record
);
Workspace
getById
(
Integer
workspaceId
);
Workspace
getById
(
Integer
workspaceId
);
int
updateByIdSelective
(
Workspace
record
);
int
updateByIdSelective
(
Workspace
record
);
int
updateById
(
Workspace
record
);
/**
* 根据名称查找工作空间
* @param workspaceName
* @return
*/
Workspace
getByName
(
String
workspaceName
);
}
}
\ No newline at end of file
byit-myth-core/myth-admin-core/src/main/java/com/byit/util/ApiFlowDagCheck.java
View file @
8edbcee1
package
com
.
byit
.
util
;
package
com
.
byit
.
util
;
import
com.byit.
job.dto.plugin.PluginFlow
;
import
com.byit.
enums.DagCheckEnum
;
import
com.byit.
utils.ValidationUtil
;
import
com.byit.
job.dto.plugin.PluginBaseNode
;
import
java.util.*
;
import
java.util.*
;
...
@@ -11,33 +11,175 @@ import java.util.*;
...
@@ -11,33 +11,175 @@ import java.util.*;
* @create: 2019-12-30 16:34
* @create: 2019-12-30 16:34
*/
*/
public
class
ApiFlowDagCheck
{
public
class
ApiFlowDagCheck
{
//节点个数
//节点个数
private
int
flow
Num
;
private
int
node
Num
;
//连线个数
//连线个数
private
int
lineNum
;
private
int
lineNum
;
//节点入度
//节点入度
private
Map
<
Integer
,
Integer
>
importNum
=
new
HashMap
<>();
private
Map
<
String
,
Integer
>
importNum
=
new
HashMap
<>();
//入口集合
//入口集合
private
Set
<
String
>
fromSet
=
new
HashSet
<>();
private
Set
<
String
>
fromSet
=
new
HashSet
<>();
//出口集合
//出口集合
private
Set
<
String
>
toSet
=
new
HashSet
<>();
private
Set
<
String
>
toSet
=
new
HashSet
<>();
//节点集合
//节点集合
private
Set
<
String
>
flow
Set
=
new
HashSet
<>();
private
Set
<
String
>
node
Set
=
new
HashSet
<>();
//用队列保存拓扑序列
//用队列保存拓扑序列
private
Queue
<
Integer
>
queue
=
new
LinkedList
<>();
private
Queue
<
String
>
queue
=
new
LinkedList
<>();
//存储连线信息
//存储连线信息
private
Map
<
String
,
Integer
>
graph
=
new
HashMap
<>();
private
Map
<
String
,
Integer
>
graph
=
new
HashMap
<>();
//依赖的节点
//依赖的节点
private
Set
<
String
>
dependSet
=
new
HashSet
<>();
private
Set
<
String
>
dependencySet
=
new
HashSet
<>();
public
void
initDag
(
List
<
PluginBaseNode
>
nodeList
){
//设置节点个数
this
.
nodeNum
=
nodeList
.
size
();
//初始化连线信息
nodeList
.
forEach
(
node
->
{
//判断节点是否有依赖
if
(
null
!=
node
.
getDependNodeNameList
()
&&
node
.
getDependNodeNameList
().
size
()
>
0
){
node
.
getDependNodeNameList
().
forEach
(
dependNodeName
->
{
fromSet
.
add
(
dependNodeName
);
dependencySet
.
add
(
dependNodeName
);
//插入一条连线信息
graph
.
put
(
dependNodeName
+
"_"
+
node
.
getName
(),
1
);
lineNum
+=
1
;
});
toSet
.
add
(
node
.
getName
());
}
else
{
queue
.
offer
(
node
.
getName
());
}
nodeSet
.
add
(
node
.
getName
());
});
//初始化入度
initImportNum
();
}
/**
* 初始化入度
*/
private
void
initImportNum
(){
//初始化入度
for
(
String
from
:
nodeSet
){
for
(
String
to
:
nodeSet
){
Integer
line
=
graph
.
get
(
from
+
"_"
+
to
);
if
(
line
!=
null
&&
line
==
1
){
Integer
count
=
importNum
.
get
(
to
)
==
null
?
1
:
importNum
.
get
(
to
)
+
1
;
importNum
.
put
(
to
,
count
);
}
}
}
}
public
void
init
(
List
<
PluginFlow
>
flowList
){
public
void
initDag
(
HashSet
<
String
>
flowNameSet
,
HashSet
<
String
>
fromFlowSet
,
HashSet
<
String
>
toFlowSet
,
HashMap
<
String
,
Integer
>
lineMap
)
{
for
(
PluginFlow
pluginFlow
:
flowList
){
nodeSet
.
addAll
(
flowNameSet
);
if
(!
flowSet
.
add
(
pluginFlow
.
getFlowName
())){
fromSet
.
addAll
(
fromFlowSet
);
ValidationUtil
.
dataNotNull
(
null
,
"工作流名称不允许重复!"
);
toSet
.
addAll
(
toFlowSet
);
//初始化连线信息
graph
=
lineMap
;
//初始化入度
initImportNum
();
}
}
/**
* 校验是否保存游离节点
* @return
*/
public
DagCheckEnum
checkFreeNode
(){
if
(
lineNum
<
nodeNum
-
1
){
return
DagCheckEnum
.
FREE
;
}
for
(
String
jobName
:
nodeSet
){
if
(
fromSet
.
contains
(
jobName
)){
continue
;
}
}
if
(
toSet
.
contains
(
jobName
)){
continue
;
}
return
DagCheckEnum
.
FREE
;
}
}
return
DagCheckEnum
.
PASS
;
}
/**
* 校验是否存在环路
* @return
*/
public
DagCheckEnum
checkDag
(){
//入度为0的结点的个数,也就是入队个数
int
number
=
0
;
//暂时存放拓扑序列
Queue
<
String
>
temp
=
new
LinkedList
<
String
>();
//删除这些被删除结点的出边(即对应结点入度减一)
while
(!
queue
.
isEmpty
()){
String
fromNode
=
queue
.
peek
();
temp
.
offer
(
queue
.
poll
());
number
++;
for
(
String
toNode
:
nodeSet
){
String
line
=
fromNode
+
"_"
+
toNode
;
if
(
graph
.
get
(
line
)
!=
null
&&
graph
.
get
(
line
)
==
1
){
Integer
num
=
importNum
.
get
(
toNode
)
-
1
;
importNum
.
put
(
toNode
,
num
);
//出现了新的入度为0的结点,删除
if
(
num
==
0
){
queue
.
offer
(
toNode
);
}
}
}
}
if
(
number
!=
nodeNum
){
System
.
out
.
println
(
"最后存在入度为1的结点,这个有向图是有回路的。"
);
return
DagCheckEnum
.
LOOP
;
}
else
{
System
.
out
.
println
(
"这个有向图不存在回路,拓扑序列为:"
+
temp
.
toString
());
return
DagCheckEnum
.
PASS
;
}
}
/**
* 校验是否单一起点
* @return
*/
public
DagCheckEnum
checkStart
(){
int
startNum
=
queue
.
size
();
if
(
startNum
==
0
){
return
DagCheckEnum
.
LOOP
;
}
else
if
(
startNum
==
1
){
if
(
"start"
.
equals
(
queue
.
element
())){
return
DagCheckEnum
.
PASS
;
}
else
{
return
DagCheckEnum
.
STARTNAME_WRONG
;
}
}
return
DagCheckEnum
.
STARTNAME_WRONG
;
}
/**
* 校验是否统一结尾
* @return
*/
public
DagCheckEnum
checkEnd
(){
List
<
String
>
tempList
=
new
ArrayList
<>();
for
(
String
nodeName
:
nodeSet
){
if
(
dependencySet
.
contains
(
String
.
valueOf
(
nodeName
))){
continue
;
}
tempList
.
add
(
nodeName
);
}
int
num
=
tempList
.
size
();
if
(
num
==
0
){
return
DagCheckEnum
.
LOOP
;
}
else
if
(
num
==
1
){
String
nodeName
=
tempList
.
get
(
0
);
if
(
"end"
.
equals
(
nodeName
)){
return
DagCheckEnum
.
PASS
;
}
else
{
return
DagCheckEnum
.
ENDNAME_WRONG
;
}
}
return
DagCheckEnum
.
ENDNAME_WRONG
;
}
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/util/DagCheck.java
View file @
8edbcee1
//package com.byit.util;
//package com.byit.util;
//
//
//import com.byit.enums.DagCheckEnum;
//import lombok.Data;
//import lombok.Data;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.commons.lang3.StringUtils;
//
//
...
...
byit-myth-core/myth-admin-core/src/main/resources/mapper/FlowMapper.xml
View file @
8edbcee1
...
@@ -40,30 +40,21 @@
...
@@ -40,30 +40,21 @@
from flow
from flow
where flow_id = #{flowId,jdbcType=INTEGER}
where flow_id = #{flowId,jdbcType=INTEGER}
</select>
</select>
<select
id=
"getByWorkSpaceAndName"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from flow
where workspace_id = #{workspaceId}
and flow_name = #{flowName}
</select>
<delete
id=
"deleteById"
parameterType=
"java.lang.Integer"
>
<delete
id=
"deleteById"
parameterType=
"java.lang.Integer"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
<!-- generated @mbg.generated date: 2019-12-31 -->
delete from flow
delete from flow
where flow_id = #{flowId,jdbcType=INTEGER}
where flow_id = #{flowId,jdbcType=INTEGER}
</delete>
</delete>
<insert
id=
"insert"
parameterType=
"com.byit.model.Flow"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into flow (flow_id, alarm_email, exec_type,
flow_cron, flow_desc, flow_name,
flow_node_count, flow_timeout, is_inner,
alarml_action, priority, trigger_next_time,
workspace_id, author, add_time,
start_up, principal, version_name,
repeat_count, remaining_count, schedule_follow,
is_update)
values (#{flowId,jdbcType=INTEGER}, #{alarmEmail,jdbcType=VARCHAR}, #{execType,jdbcType=CHAR},
#{flowCron,jdbcType=VARCHAR}, #{flowDesc,jdbcType=VARCHAR}, #{flowName,jdbcType=VARCHAR},
#{flowNodeCount,jdbcType=INTEGER}, #{flowTimeout,jdbcType=BIGINT}, #{isInner,jdbcType=CHAR},
#{alarmlAction,jdbcType=CHAR}, #{priority,jdbcType=CHAR}, #{triggerNextTime,jdbcType=BIGINT},
#{workspaceId,jdbcType=INTEGER}, #{author,jdbcType=VARCHAR}, #{addTime,jdbcType=TIMESTAMP},
#{startUp,jdbcType=CHAR}, #{principal,jdbcType=VARCHAR}, #{versionName,jdbcType=VARCHAR},
#{repeatCount,jdbcType=INTEGER}, #{remainingCount,jdbcType=INTEGER}, #{scheduleFollow,jdbcType=CHAR},
#{isUpdate,jdbcType=CHAR})
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.byit.model.Flow"
>
<insert
id=
"insertSelective"
parameterType=
"com.byit.model.Flow"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into flow
insert into flow
...
@@ -274,30 +265,5 @@
...
@@ -274,30 +265,5 @@
</set>
</set>
where flow_id = #{flowId,jdbcType=INTEGER}
where flow_id = #{flowId,jdbcType=INTEGER}
</update>
</update>
<update
id=
"updateById"
parameterType=
"com.byit.model.Flow"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
update flow
set alarm_email = #{alarmEmail,jdbcType=VARCHAR},
exec_type = #{execType,jdbcType=CHAR},
flow_cron = #{flowCron,jdbcType=VARCHAR},
flow_desc = #{flowDesc,jdbcType=VARCHAR},
flow_name = #{flowName,jdbcType=VARCHAR},
flow_node_count = #{flowNodeCount,jdbcType=INTEGER},
flow_timeout = #{flowTimeout,jdbcType=BIGINT},
is_inner = #{isInner,jdbcType=CHAR},
alarml_action = #{alarmlAction,jdbcType=CHAR},
priority = #{priority,jdbcType=CHAR},
trigger_next_time = #{triggerNextTime,jdbcType=BIGINT},
workspace_id = #{workspaceId,jdbcType=INTEGER},
author = #{author,jdbcType=VARCHAR},
add_time = #{addTime,jdbcType=TIMESTAMP},
start_up = #{startUp,jdbcType=CHAR},
principal = #{principal,jdbcType=VARCHAR},
version_name = #{versionName,jdbcType=VARCHAR},
repeat_count = #{repeatCount,jdbcType=INTEGER},
remaining_count = #{remainingCount,jdbcType=INTEGER},
schedule_follow = #{scheduleFollow,jdbcType=CHAR},
is_update = #{isUpdate,jdbcType=CHAR}
where flow_id = #{flowId,jdbcType=INTEGER}
</update>
</mapper>
</mapper>
\ No newline at end of file
byit-myth-core/myth-admin-core/src/main/resources/mapper/WorkspaceMapper.xml
View file @
8edbcee1
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
<!-- generated @mbg.generated date: 2019-12-31 -->
<!-- generated @mbg.generated date: 2019-12-31 -->
workspace_id, workspace_name, author, add_time, remove_mark
workspace_id, workspace_name, author, add_time, remove_mark
</sql>
</sql>
<select
id=
"getById"
parameterType=
"java.lang.Integer"
resultMap=
"BaseResultMap"
>
<select
id=
"getById"
parameterType=
"java.lang.Integer"
resultMap=
"BaseResultMap"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
<!-- generated @mbg.generated date: 2019-12-31 -->
select
select
...
@@ -20,18 +21,20 @@
...
@@ -20,18 +21,20 @@
from workspace
from workspace
where workspace_id = #{workspaceId,jdbcType=INTEGER}
where workspace_id = #{workspaceId,jdbcType=INTEGER}
</select>
</select>
<select
id=
"getByName"
parameterType=
"string"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from workspace
where workspace_name = #{workspaceName,jdbcType=STRING}
</select>
<delete
id=
"deleteById"
parameterType=
"java.lang.Integer"
>
<delete
id=
"deleteById"
parameterType=
"java.lang.Integer"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
<!-- generated @mbg.generated date: 2019-12-31 -->
delete from workspace
delete from workspace
where workspace_id = #{workspaceId,jdbcType=INTEGER}
where workspace_id = #{workspaceId,jdbcType=INTEGER}
</delete>
</delete>
<insert
id=
"insert"
parameterType=
"com.byit.model.Workspace"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into workspace (workspace_id, workspace_name, author,
add_time, remove_mark)
values (#{workspaceId,jdbcType=INTEGER}, #{workspaceName,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR},
#{addTime,jdbcType=TIMESTAMP}, #{removeMark,jdbcType=CHAR})
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.byit.model.Workspace"
>
<insert
id=
"insertSelective"
parameterType=
"com.byit.model.Workspace"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
<!-- generated @mbg.generated date: 2019-12-31 -->
insert into workspace
insert into workspace
...
@@ -89,13 +92,4 @@
...
@@ -89,13 +92,4 @@
</set>
</set>
where workspace_id = #{workspaceId,jdbcType=INTEGER}
where workspace_id = #{workspaceId,jdbcType=INTEGER}
</update>
</update>
<update
id=
"updateById"
parameterType=
"com.byit.model.Workspace"
>
<!-- generated @mbg.generated date: 2019-12-31 -->
update workspace
set workspace_name = #{workspaceName,jdbcType=VARCHAR},
author = #{author,jdbcType=VARCHAR},
add_time = #{addTime,jdbcType=TIMESTAMP},
remove_mark = #{removeMark,jdbcType=CHAR}
where workspace_id = #{workspaceId,jdbcType=INTEGER}
</update>
</mapper>
</mapper>
\ No newline at end of file
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/plugin/PluginBaseNode.java
View file @
8edbcee1
...
@@ -3,6 +3,7 @@ package com.byit.job.dto.plugin;
...
@@ -3,6 +3,7 @@ package com.byit.job.dto.plugin;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
/**
/**
* @description: 基础Node
* @description: 基础Node
...
@@ -15,12 +16,12 @@ public class PluginBaseNode implements Serializable {
...
@@ -15,12 +16,12 @@ public class PluginBaseNode implements Serializable {
/**
/**
* 名称
* 名称
*/
*/
private
String
n
odeN
ame
;
private
String
name
;
/**
/**
*
任务
描述
* 描述
*/
*/
private
String
nodeD
esc
;
private
String
d
esc
;
/**
/**
* 类型 节点:node, 内嵌工作流:innerFlow
* 类型 节点:node, 内嵌工作流:innerFlow
...
@@ -32,6 +33,11 @@ public class PluginBaseNode implements Serializable {
...
@@ -32,6 +33,11 @@ public class PluginBaseNode implements Serializable {
*/
*/
private
String
author
;
private
String
author
;
/**
* 依赖的任务节点名称集合,只能是节点的名称,如果不是内嵌工作流不允许设置依赖
*/
private
List
<
String
>
dependNodeNameList
;
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
}
}
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/plugin/PluginFlow.java
View file @
8edbcee1
...
@@ -2,7 +2,6 @@ package com.byit.job.dto.plugin;
...
@@ -2,7 +2,6 @@ package com.byit.job.dto.plugin;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -11,22 +10,7 @@ import java.util.List;
...
@@ -11,22 +10,7 @@ import java.util.List;
* @create: 2019-12-30 10:44
* @create: 2019-12-30 10:44
*/
*/
@Data
@Data
public
class
PluginFlow
implements
Serializable
{
public
class
PluginFlow
extends
PluginBaseNode
{
/**
* 当前工作流的介绍
*/
private
String
flowDesc
;
/**
* 当前版本工作流名字
*/
private
String
flowName
;
/**
* 创建人
*/
private
String
author
;
/**
/**
* 责任人
* 责任人
...
@@ -36,7 +20,7 @@ public class PluginFlow implements Serializable {
...
@@ -36,7 +20,7 @@ public class PluginFlow implements Serializable {
/**
/**
* 是否是重新发布 true 是,false 否
* 是否是重新发布 true 是,false 否
*/
*/
private
B
oolean
rePublish
;
private
b
oolean
rePublish
;
/**
/**
* 下属任务节点集合
* 下属任务节点集合
...
@@ -44,11 +28,6 @@ public class PluginFlow implements Serializable {
...
@@ -44,11 +28,6 @@ public class PluginFlow implements Serializable {
private
List
<
PluginBaseNode
>
nodeList
;
private
List
<
PluginBaseNode
>
nodeList
;
/**
/**
* 依赖的工作流名称集合
*/
private
List
<
String
>
dependFlowNameList
;
/**
* 工作流的配置项
* 工作流的配置项
*/
*/
private
PluginFlowConfig
config
;
private
PluginFlowConfig
config
;
...
...
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/plugin/PluginInnerFlow.java
deleted
100644 → 0
View file @
7ff3247d
package
com
.
byit
.
job
.
dto
.
plugin
;
import
lombok.Data
;
import
java.util.List
;
/**
* @description: 内嵌工作流
* @author: gml
* @create: 2019-12-30 10:46
*/
@Data
public
class
PluginInnerFlow
extends
PluginBaseNode
{
/**
* 责任人
*/
private
String
principal
;
/**
* 工作流的配置项
*/
private
PluginFlowConfig
config
;
/**
* 是否是重新发布 true 是,false 否
*/
private
Boolean
rePublish
;
/**
* 依赖的任务节点名称集合,只能是节点的名称
*/
private
List
<
String
>
dependNodeNameList
;
/**
* 下属任务节点集合
*/
private
List
<
PluginNode
>
nodeList
;
}
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/plugin/PluginNode.java
View file @
8edbcee1
...
@@ -2,8 +2,6 @@ package com.byit.job.dto.plugin;
...
@@ -2,8 +2,6 @@ package com.byit.job.dto.plugin;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.List
;
/**
/**
* @description: 插件端的任务节点
* @description: 插件端的任务节点
* @author: gml
* @author: gml
...
@@ -51,9 +49,5 @@ public class PluginNode extends PluginBaseNode {
...
@@ -51,9 +49,5 @@ public class PluginNode extends PluginBaseNode {
*/
*/
private
PluginNodeConfig
config
;
private
PluginNodeConfig
config
;
/**
* 依赖节点的名称集合
*/
private
List
<
String
>
dependNodeNameList
;
}
}
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/plugin/Plugin
FlowDepend
.java
→
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/plugin/Plugin
Package
.java
View file @
8edbcee1
...
@@ -2,29 +2,22 @@ package com.byit.job.dto.plugin;
...
@@ -2,29 +2,22 @@ package com.byit.job.dto.plugin;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.List
;
/**
/**
* @description:
工作流的依赖关系
* @description:
插件段的发布包
* @author: gml
* @author: gml
* @create: 20
19-12-31 11:04
* @create: 20
20-01-02 14:38
*/
*/
@Data
@Data
public
class
PluginFlowDepend
{
public
class
PluginPackage
{
/**
* 工作流名称
*/
private
String
flowName
;
/**
/**
* 工作空间
的
名称
* 工作空间名称
*/
*/
private
String
workspaceName
;
private
String
workspaceName
;
/**
/**
* 工作流
依赖的工作流名称
* 工作流
*/
*/
private
List
<
String
>
dependFlowNameList
;
private
PluginFlow
flow
;
}
}
byit-myth-core/myth-core-common/src/main/java/com/byit/job/enums/plugin/PluginNodeTypeEnum.java
0 → 100644
View file @
8edbcee1
package
com
.
byit
.
job
.
enums
.
plugin
;
/**
* @description: 节点的类型枚举
* @author: gml
* @create: 2020-01-02 14:12
*/
public
enum
PluginNodeTypeEnum
{
NODE
(
"node"
,
"节点"
),
FLOW
(
"flow"
,
"工作流"
)
;
private
String
code
;
private
String
msg
;
private
PluginNodeTypeEnum
(
String
code
,
String
msg
){
this
.
code
=
code
;
this
.
msg
=
msg
;
}
public
String
getCode
(){
return
this
.
code
;
}
public
String
getMsg
(){
return
this
.
msg
;
}
}
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