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
65ae6a22
Commit
65ae6a22
authored
Jun 15, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runId生成策略修改以及异常修改
parent
607b9f6c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
12 deletions
+60
-12
ApiFlowServiceImpl.java
...c/main/java/com/byit/service/impl/ApiFlowServiceImpl.java
+8
-3
RunNodeServiceImpl.java
...c/main/java/com/byit/service/impl/RunNodeServiceImpl.java
+5
-1
RunRecordingAndLogServiceImpl.java
...ervice/mapservice/impl/RunRecordingAndLogServiceImpl.java
+11
-6
JobTaskThreadRunHelper.java
...n/java/com/byit/thread/helper/JobTaskThreadRunHelper.java
+7
-2
IDGenerationStrategy.java
...ore/src/main/java/com/byit/util/IDGenerationStrategy.java
+29
-0
No files found.
byit-myth-admin/src/main/java/com/byit/service/impl/ApiFlowServiceImpl.java
View file @
65ae6a22
...
@@ -20,12 +20,14 @@ import com.byit.model.*;
...
@@ -20,12 +20,14 @@ import com.byit.model.*;
import
com.byit.model.vo.RunRecordingVo
;
import
com.byit.model.vo.RunRecordingVo
;
import
com.byit.service.ApiFlowService
;
import
com.byit.service.ApiFlowService
;
import
com.byit.util.ApiFlowDagCheck
;
import
com.byit.util.ApiFlowDagCheck
;
import
com.byit.util.IDGenerationStrategy
;
import
com.byit.util.lock.RedissLockUtil
;
import
com.byit.util.lock.RedissLockUtil
;
import
com.byit.utils.ValidationUtil
;
import
com.byit.utils.ValidationUtil
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -49,6 +51,9 @@ public class ApiFlowServiceImpl implements ApiFlowService {
...
@@ -49,6 +51,9 @@ public class ApiFlowServiceImpl implements ApiFlowService {
private
final
static
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
private
final
static
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
public
static
final
String
PRE
=
"${"
;
public
static
final
String
PRE
=
"${"
;
public
static
final
String
SUFFER
=
"}"
;
public
static
final
String
SUFFER
=
"}"
;
@Value
(
"${server.port}"
)
private
Integer
serverPort
;
@Resource
@Resource
private
FlowMapper
flowMapper
;
private
FlowMapper
flowMapper
;
...
@@ -492,7 +497,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
...
@@ -492,7 +497,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
}
}
//获取当前时间
//获取当前时间
String
reRunId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
reRunId
=
IDGenerationStrategy
.
runIdGenerationStrategy
(
serverPort
);
Long
triggerTime
=
System
.
currentTimeMillis
();
Long
triggerTime
=
System
.
currentTimeMillis
();
WaitingTask
waitingTask
=
new
WaitingTask
();
WaitingTask
waitingTask
=
new
WaitingTask
();
BeanUtils
.
copyProperties
(
jobTaskRunLog
,
waitingTask
);
BeanUtils
.
copyProperties
(
jobTaskRunLog
,
waitingTask
);
...
@@ -598,7 +603,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
...
@@ -598,7 +603,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
}
else
{
}
else
{
//不是内嵌工作流
//不是内嵌工作流
Long
triggerTime
=
System
.
currentTimeMillis
();
Long
triggerTime
=
System
.
currentTimeMillis
();
String
reRunId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
reRunId
=
IDGenerationStrategy
.
runIdGenerationStrategy
(
serverPort
);
List
<
JobTaskRunLogWithBLOBs
>
jobTaskRunLogList
=
jobTaskRunLogMapper
.
findJobTaskRunLogWithBLOBsByFlowIdAndRunId
(
flow
.
getFlowId
(),
runInfo
.
getRunId
());
List
<
JobTaskRunLogWithBLOBs
>
jobTaskRunLogList
=
jobTaskRunLogMapper
.
findJobTaskRunLogWithBLOBsByFlowIdAndRunId
(
flow
.
getFlowId
(),
runInfo
.
getRunId
());
ValidationUtil
.
dataNotNull
(
jobTaskRunLogList
,
"该工作流没有在调度上的任务"
);
ValidationUtil
.
dataNotNull
(
jobTaskRunLogList
,
"该工作流没有在调度上的任务"
);
...
@@ -1227,7 +1232,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
...
@@ -1227,7 +1232,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
for
(
String
repairTime
:
repairTimeList
){
for
(
String
repairTime
:
repairTimeList
){
WaitingRecord
waitingRecord
=
new
WaitingRecord
();
WaitingRecord
waitingRecord
=
new
WaitingRecord
();
RunRecording
runRecording
=
new
RunRecording
();
RunRecording
runRecording
=
new
RunRecording
();
String
runId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
runId
=
IDGenerationStrategy
.
runIdGenerationStrategy
(
serverPort
);
//设置排期
//设置排期
BeanUtils
.
copyProperties
(
flow
,
waitingRecord
);
BeanUtils
.
copyProperties
(
flow
,
waitingRecord
);
waitingRecord
.
setFlowVersionName
(
flow
.
getVersionName
());
waitingRecord
.
setFlowVersionName
(
flow
.
getVersionName
());
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/impl/RunNodeServiceImpl.java
View file @
65ae6a22
...
@@ -8,9 +8,11 @@ import com.byit.model.JobTask;
...
@@ -8,9 +8,11 @@ import com.byit.model.JobTask;
import
com.byit.model.Node
;
import
com.byit.model.Node
;
import
com.byit.model.RunRecording
;
import
com.byit.model.RunRecording
;
import
com.byit.service.*
;
import
com.byit.service.*
;
import
com.byit.util.IDGenerationStrategy
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisherAware
;
import
org.springframework.context.ApplicationEventPublisherAware
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -34,6 +36,8 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
...
@@ -34,6 +36,8 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
private
final
JobTaskService
jobTaskService
;
private
final
JobTaskService
jobTaskService
;
private
final
FlowService
flowService
;
private
final
FlowService
flowService
;
private
ApplicationEventPublisher
applicationEventPublisher
;
private
ApplicationEventPublisher
applicationEventPublisher
;
@Value
(
"${server.port}"
)
private
Integer
serverPort
;
/**
/**
* 节点依赖查询操作
* 节点依赖查询操作
*/
*/
...
@@ -55,7 +59,7 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
...
@@ -55,7 +59,7 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
@Override
@Override
public
void
saveRunRec
(
Flow
flow
,
List
<
Node
>
nodes
)
{
public
void
saveRunRec
(
Flow
flow
,
List
<
Node
>
nodes
)
{
log
.
info
(
"---------saveRunRecAndTask start------【保存工作流:{}和节点:{}】-----------------------"
,
flow
,
nodes
);
log
.
info
(
"---------saveRunRecAndTask start------【保存工作流:{}和节点:{}】-----------------------"
,
flow
,
nodes
);
String
runId
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
runId
=
IDGenerationStrategy
.
runIdGenerationStrategy
(
serverPort
);
log
.
info
(
"-------------【开始保存运行记录runId为:{}】------------------"
,
runId
);
log
.
info
(
"-------------【开始保存运行记录runId为:{}】------------------"
,
runId
);
RunRecording
build
=
new
RunRecording
();
RunRecording
build
=
new
RunRecording
();
BeanUtils
.
copyProperties
(
flow
,
build
);
BeanUtils
.
copyProperties
(
flow
,
build
);
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/mapservice/impl/RunRecordingAndLogServiceImpl.java
View file @
65ae6a22
package
com
.
byit
.
service
.
mapservice
.
impl
;
package
com
.
byit
.
service
.
mapservice
.
impl
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.byit.enums.EmailEnum
;
import
com.byit.enums.EmailEnum
;
import
com.byit.enums.FlowPropertyEnum
;
import
com.byit.enums.FlowPropertyEnum
;
import
com.byit.enums.RunRecordingEnum
;
import
com.byit.enums.RunRecordingEnum
;
...
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
...
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -56,8 +58,9 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
...
@@ -56,8 +58,9 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
//List<NodeVersion> notLogNode = allByFlowId.stream().filter(nodeVersion -> !(logNodeId.contains(nodeVersion.getNodeId()))).collect(Collectors.toList());
//List<NodeVersion> notLogNode = allByFlowId.stream().filter(nodeVersion -> !(logNodeId.contains(nodeVersion.getNodeId()))).collect(Collectors.toList());
//将这些节点置为失败并将实例也置为失败
//将这些节点置为失败并将实例也置为失败
//保存错误日志节点
//保存错误日志节点
//第一将非虚节点的节点保存进日志,同时保存虚节点,同时筛选出end节点 不作处理,让他自己执行队形的end节点(为了执行结束事件)
//查询task所有的对应节点
List
<
JobTask
>
virtualTasks
=
new
ArrayList
<>();
//查询task所有的对应节点 这里需要判断不是虚节点 在进行日志插入之后需要将对应的节点删除
List
<
JobTask
>
byRunId
=
jobTaskService
.
findByRunId
(
runId
);
List
<
JobTask
>
byRunId
=
jobTaskService
.
findByRunId
(
runId
);
byRunId
.
forEach
(
task
->{
byRunId
.
forEach
(
task
->{
JobTaskRunLogWithBLOBs
log
=
new
JobTaskRunLogWithBLOBs
();
JobTaskRunLogWithBLOBs
log
=
new
JobTaskRunLogWithBLOBs
();
...
@@ -73,6 +76,11 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
...
@@ -73,6 +76,11 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
log
.
setFlowName
(
runRecording
.
getFlowName
());
log
.
setFlowName
(
runRecording
.
getFlowName
());
log
.
setTriggerTime
(
thisTime
);
log
.
setTriggerTime
(
thisTime
);
jobTaskRunLogService
.
saveJobTaskRunLog
(
log
);
jobTaskRunLogService
.
saveJobTaskRunLog
(
log
);
if
(
"0"
.
equals
(
task
.
getIsVirtual
()))
{
virtualTasks
.
add
(
task
);
}
jobTaskService
.
removeMythJobTaskById
(
task
.
getId
());
});
});
//执行实例的快速失败
//执行实例的快速失败
if
(
runRecording
.
getStartTime
()
==
null
)
{
if
(
runRecording
.
getStartTime
()
==
null
)
{
...
@@ -85,8 +93,6 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
...
@@ -85,8 +93,6 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
runRecordingService
.
updateRunRecordingById
(
runRecording
);
runRecordingService
.
updateRunRecordingById
(
runRecording
);
applicationEventPublisher
.
publishEvent
(
new
EndFlowEvent
(
this
,
runRecording
.
getFlowId
()));
applicationEventPublisher
.
publishEvent
(
new
EndFlowEvent
(
this
,
runRecording
.
getFlowId
()));
//筛选虚节点
List
<
JobTask
>
virtualTasks
=
byRunId
.
stream
().
filter
(
task
->
"0"
.
equals
(
task
.
getIsVirtual
())).
collect
(
Collectors
.
toList
());
virtualTasks
.
forEach
(
virtualTask
->
{
virtualTasks
.
forEach
(
virtualTask
->
{
Integer
mapFlowId
=
virtualTask
.
getMapFlowId
();
Integer
mapFlowId
=
virtualTask
.
getMapFlowId
();
List
<
NodeVersion
>
allByFlowId
=
nodeVersionService
.
findAllByFlowId
(
mapFlowId
);
List
<
NodeVersion
>
allByFlowId
=
nodeVersionService
.
findAllByFlowId
(
mapFlowId
);
...
@@ -144,8 +150,7 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
...
@@ -144,8 +150,7 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
});
});
//删除task里面的数据
//删除task里面的数据
jobTaskService
.
removeByRunId
(
runId
);
//jobTaskService.removeByRunId(runId);
}
}
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/helper/JobTaskThreadRunHelper.java
View file @
65ae6a22
...
@@ -113,7 +113,12 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper {
...
@@ -113,7 +113,12 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"-----------------节点执行时出现异常,{}----------"
,
e
.
getMessage
());
try
{
taskAndLogServer
.
addRunLogAndRemoveTask
(
jobTask
,
true
,
true
);
}
catch
(
UnknownHostException
unknownHostException
)
{
log
.
error
(
"-----------------节点执行时出现异常,{}----------"
,
unknownHostException
.
getMessage
());
}
}
}
}
else
{
}
else
{
//先处理开始节点
//先处理开始节点
...
@@ -138,7 +143,7 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper {
...
@@ -138,7 +143,7 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper {
}
catch
(
UnknownHostException
e
)
{
}
catch
(
UnknownHostException
e
)
{
log
.
error
(
"-----------------节点执行时出现异常,{}----------"
,
e
.
getMessage
());
log
.
error
(
"-----------------节点执行时出现异常,{}----------"
,
e
.
getMessage
());
}
}
}
catch
(
Business
Exception
businessException
)
{
}
catch
(
Exception
businessException
)
{
try
{
try
{
taskAndLogServer
.
addRunLogAndRemoveTask
(
jobTask
,
false
,
true
);
taskAndLogServer
.
addRunLogAndRemoveTask
(
jobTask
,
false
,
true
);
}
catch
(
UnknownHostException
e
)
{
}
catch
(
UnknownHostException
e
)
{
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/util/IDGenerationStrategy.java
0 → 100644
View file @
65ae6a22
package
com
.
byit
.
util
;
import
com.byit.utils.IpUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.UUID
;
/**
*
* @author huangfu
*/
public
class
IDGenerationStrategy
{
public
static
String
runIdGenerationStrategy
(
int
port
){
String
runIdPre
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
String
ipPort
=
IpUtil
.
getIpPort
(
port
);
if
(
StringUtils
.
isNoneBlank
(
ipPort
)){
String
replace
=
ipPort
.
replace
(
"."
,
""
).
replace
(
":"
,
""
);
runIdPre
=
runIdPre
+
replace
;
}
return
runIdPre
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
runIdGenerationStrategy
(
88
));
}
}
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