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
74f0e51a
Commit
74f0e51a
authored
Mar 25, 2020
by
guominglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改运行的key和报错问题
parent
5b9da215
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
35 deletions
+56
-35
pom.xml
byit-myth-admin/pom.xml
+0
-5
ApiNodeServiceImpl.java
...c/main/java/com/byit/service/impl/ApiNodeServiceImpl.java
+25
-6
pom.xml
byit-myth-core/myth-admin-core/pom.xml
+6
-0
RedisConfig.java
...h-admin-core/src/main/java/com/byit/conf/RedisConfig.java
+1
-1
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+9
-1
ScheduleThreadRunHelper.java
.../java/com/byit/thread/helper/ScheduleThreadRunHelper.java
+3
-10
MythJobProcess.java
...server/src/main/java/com/byit/process/MythJobProcess.java
+8
-8
LogGobbler.java
...cutor-server/src/main/java/com/byit/utils/LogGobbler.java
+4
-4
No files found.
byit-myth-admin/pom.xml
View file @
74f0e51a
...
@@ -53,11 +53,6 @@
...
@@ -53,11 +53,6 @@
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-redis
</artifactId>
<version>
1.3.2.RELEASE
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
byit-myth-admin/src/main/java/com/byit/service/impl/ApiNodeServiceImpl.java
View file @
74f0e51a
...
@@ -4,10 +4,17 @@ import com.alibaba.fastjson.JSON;
...
@@ -4,10 +4,17 @@ import com.alibaba.fastjson.JSON;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.dto.plugin.RunNode
;
import
com.byit.dto.plugin.RunNode
;
import
com.byit.enums.NodePropertyEnum
;
import
com.byit.enums.NodePropertyEnum
;
import
com.byit.job.WorkRoulette
;
import
com.byit.job.utils.PlaceholderUtils
;
import
com.byit.mapper.JobTaskRunLogMapper
;
import
com.byit.mapper.JobTaskScheduleMapper
;
import
com.byit.mapper.JobTaskScheduleMapper
;
import
com.byit.model.JobTaskRunLogWithBLOBs
;
import
com.byit.model.JobTaskSchedule
;
import
com.byit.model.JobTaskSchedule
;
import
com.byit.service.ApiNodeService
;
import
com.byit.service.ApiNodeService
;
import
com.byit.task.ScriptExecutorJobTask
;
import
com.byit.utils.ValidationUtil
;
import
com.byit.utils.ValidationUtil
;
import
io.netty.util.TimerTask
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -22,7 +29,7 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
...
@@ -22,7 +29,7 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
public
class
ApiNodeServiceImpl
implements
ApiNodeService
{
public
class
ApiNodeServiceImpl
implements
ApiNodeService
{
@Resource
@Resource
private
JobTask
ScheduleMapper
jobTaskSchedule
Mapper
;
private
JobTask
RunLogMapper
jobTaskRunLog
Mapper
;
@Resource
@Resource
private
StringRedisTemplate
stringRedisTemplate
;
private
StringRedisTemplate
stringRedisTemplate
;
...
@@ -39,8 +46,10 @@ public class ApiNodeServiceImpl implements ApiNodeService {
...
@@ -39,8 +46,10 @@ public class ApiNodeServiceImpl implements ApiNodeService {
ValidationUtil
.
dataNotBank
(
runNode
.
getRunCmd
(),
"运行命令不允许为空!"
);
ValidationUtil
.
dataNotBank
(
runNode
.
getRunCmd
(),
"运行命令不允许为空!"
);
ValidationUtil
.
dataNotBank
(
runNode
.
getJobType
(),
"节点类型不允许为空!"
);
ValidationUtil
.
dataNotBank
(
runNode
.
getJobType
(),
"节点类型不允许为空!"
);
JobTaskSchedule
schedule
=
new
JobTaskSchedule
();
Long
triggerTime
=
System
.
currentTimeMillis
();
JobTaskSchedule
schedule
=
new
JobTaskSchedule
();
schedule
.
setNodeId
(
Integer
.
valueOf
(
runNode
.
getNodeId
()));
schedule
.
setNodeId
(
Integer
.
valueOf
(
runNode
.
getNodeId
()));
schedule
.
setRunId
(
runId
);
schedule
.
setRunId
(
runId
);
schedule
.
setNodeName
(
runNode
.
getNodeName
());
schedule
.
setNodeName
(
runNode
.
getNodeName
());
...
@@ -50,13 +59,23 @@ public class ApiNodeServiceImpl implements ApiNodeService {
...
@@ -50,13 +59,23 @@ public class ApiNodeServiceImpl implements ApiNodeService {
schedule
.
setRunSource
(
runNode
.
getRunSource
());
schedule
.
setRunSource
(
runNode
.
getRunSource
());
schedule
.
setScriptUrls
(
runNode
.
getScriptUrl
());
schedule
.
setScriptUrls
(
runNode
.
getScriptUrl
());
schedule
.
setJobType
(
runNode
.
getJobType
());
schedule
.
setJobType
(
runNode
.
getJobType
());
schedule
.
setTriggerTime
(
System
.
currentTimeMillis
()
);
schedule
.
setTriggerTime
(
triggerTime
);
jobTaskScheduleMapper
.
saveJobTaskSchedule
(
schedule
);
schedule
.
setRunParam
(
PlaceholderUtils
.
formatParam
(
schedule
.
getRunParam
())
);
JobTaskRunLogWithBLOBs
jobTaskRunLog
=
new
JobTaskRunLogWithBLOBs
();
BeanUtils
.
copyProperties
(
schedule
,
jobTaskRunLog
);
jobTaskRunLogMapper
.
saveJobTaskRunLog
(
jobTaskRunLog
);
//获取日志id
Integer
logId
=
jobTaskRunLog
.
getLogId
();
TimerTask
timerTask
=
new
ScriptExecutorJobTask
(
schedule
);
WorkRoulette
.
addJob
(
timerTask
,
triggerTime
);
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
false
).
runLog
(
"等待服务器分配资源"
).
build
();
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
false
).
runLog
(
"等待服务器分配资源"
).
build
();
stringRedisTemplate
.
convertAndSend
(
runId
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
String
runKey
=
"REAL-EXEC-"
+
logId
;
stringRedisTemplate
.
convertAndSend
(
runKey
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
return
run
Id
;
return
run
Key
;
}
}
}
}
byit-myth-core/myth-admin-core/pom.xml
View file @
74f0e51a
...
@@ -70,6 +70,12 @@
...
@@ -70,6 +70,12 @@
<scope>
compile
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-redis
</artifactId>
<version>
1.3.2.RELEASE
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
byit-myth-
admin/src/main/java/com/byit/config
/RedisConfig.java
→
byit-myth-
core/myth-admin-core/src/main/java/com/byit/conf
/RedisConfig.java
View file @
74f0e51a
package
com
.
byit
.
conf
ig
;
package
com
.
byit
.
conf
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
74f0e51a
package
com
.
byit
.
task
;
package
com
.
byit
.
task
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.conf.MythJobAutoConfigure
;
import
com.byit.conf.MythJobAutoConfigure
;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.enums.EmailEnum
;
import
com.byit.enums.EmailEnum
;
import
com.byit.enums.NodePropertyEnum
;
import
com.byit.enums.NodePropertyEnum
;
import
com.byit.enums.NodeRunStatusPropertyEnum
;
import
com.byit.enums.NodeRunStatusPropertyEnum
;
...
@@ -19,9 +21,12 @@ import com.byit.util.SpringUtil;
...
@@ -19,9 +21,12 @@ import com.byit.util.SpringUtil;
import
io.netty.util.Timeout
;
import
io.netty.util.Timeout
;
import
io.netty.util.TimerTask
;
import
io.netty.util.TimerTask
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
java.util.Date
;
import
java.util.Date
;
import
static
com
.
alibaba
.
fastjson
.
serializer
.
SerializerFeature
.
WriteClassName
;
/**
/**
* @author huangfu
* @author huangfu
*/
*/
...
@@ -101,7 +106,10 @@ public class ScriptExecutorJobTask implements TimerTask {
...
@@ -101,7 +106,10 @@ public class ScriptExecutorJobTask implements TimerTask {
try
{
try
{
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
}
catch
(
RpcException
rpcException
){
}
catch
(
RpcException
rpcException
){
log
.
error
(
"------执行机异常{}-----"
,
rpcException
.
getMessage
());
StringRedisTemplate
stringRedisTemplate
=
(
StringRedisTemplate
)
SpringUtil
.
getBean
(
"stringRedisTemplate"
);
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
false
).
runLog
(
"执行资源异常"
+
rpcException
.
getMessage
()).
build
();
stringRedisTemplate
.
convertAndSend
(
"REAL-EXEC-"
+
mythJobTaskSchedule
.
getLogId
()
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
log
.
error
(
"------执行机异常{}-----"
,
rpcException
.
getMessage
());
dispatchResponseDto
.
setMsg
(
rpcException
.
getMessage
());
dispatchResponseDto
.
setMsg
(
rpcException
.
getMessage
());
dispatchResponseDto
.
setCode
(
JobResultEnum
.
DISPATCH_FAIL
.
getRes
());
dispatchResponseDto
.
setCode
(
JobResultEnum
.
DISPATCH_FAIL
.
getRes
());
}
}
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/helper/ScheduleThreadRunHelper.java
View file @
74f0e51a
...
@@ -14,6 +14,7 @@ import com.byit.thread.BaseThreadRunHelper;
...
@@ -14,6 +14,7 @@ import com.byit.thread.BaseThreadRunHelper;
import
com.byit.util.SpringUtil
;
import
com.byit.util.SpringUtil
;
import
io.netty.util.TimerTask
;
import
io.netty.util.TimerTask
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
@@ -95,16 +96,8 @@ public class ScheduleThreadRunHelper extends BaseThreadRunHelper {
...
@@ -95,16 +96,8 @@ public class ScheduleThreadRunHelper extends BaseThreadRunHelper {
private
Integer
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
){
private
Integer
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
){
JobTaskRunLogWithBLOBs
jobTaskRunLog
=
new
JobTaskRunLogWithBLOBs
();
JobTaskRunLogWithBLOBs
jobTaskRunLog
=
new
JobTaskRunLogWithBLOBs
();
BeanUtils
.
copyProperties
(
mythJobTaskSchedule
,
jobTaskRunLog
);
jobTaskRunLog
.
setRunId
(
mythJobTaskSchedule
.
getRunId
());
jobTaskRunLog
.
setLogId
(
null
);
jobTaskRunLog
.
setIsVirtual
(
mythJobTaskSchedule
.
getIsVirtual
());
jobTaskRunLog
.
setFlowId
(
mythJobTaskSchedule
.
getFlowId
());
jobTaskRunLog
.
setFlowName
(
mythJobTaskSchedule
.
getFlowName
());
jobTaskRunLog
.
setNodeId
(
mythJobTaskSchedule
.
getNodeId
());
jobTaskRunLog
.
setNodeName
(
mythJobTaskSchedule
.
getNodeName
());
jobTaskRunLog
.
setRunParams
(
mythJobTaskSchedule
.
getRunParam
());
jobTaskRunLog
.
setFailedRemainingCount
(
mythJobTaskSchedule
.
getFailedRetryCount
());
jobTaskRunLog
.
setJobType
(
mythJobTaskSchedule
.
getJobType
());
JobTaskRunLogServiceImpl
mythJobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
JobTaskRunLogServiceImpl
mythJobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
mythJobTaskRunLogService
.
saveJobTaskRunLog
(
jobTaskRunLog
);
mythJobTaskRunLogService
.
saveJobTaskRunLog
(
jobTaskRunLog
);
...
...
byit-myth-executor/myth-executor-server/src/main/java/com/byit/process/MythJobProcess.java
View file @
74f0e51a
...
@@ -53,15 +53,15 @@ public class MythJobProcess implements Callable<String>{
...
@@ -53,15 +53,15 @@ public class MythJobProcess implements Callable<String>{
private
String
effectiveUser
=
null
;
private
String
effectiveUser
=
null
;
//本次任务对应的日志id
//本次任务对应的日志id
private
Integer
logId
;
private
Integer
logId
;
//redis的发布key
private
String
runId
;
//执行状态,默认是失败
//执行状态,默认是失败
private
int
exitCode
=
1
;
private
int
exitCode
=
1
;
//redis模板
//redis模板
private
StringRedisTemplate
stringRedisTemplate
;
private
StringRedisTemplate
stringRedisTemplate
;
//redis的key
private
String
runKey
;
public
MythJobProcess
(
final
List
<
String
>
cmd
,
final
Map
<
String
,
String
>
env
,
public
MythJobProcess
(
final
List
<
String
>
cmd
,
final
Map
<
String
,
String
>
env
,
final
String
workingDir
,
final
Integer
logId
,
final
String
runId
,
final
String
RedisTemplate
stringRedisTemplate
)
{
final
String
workingDir
,
final
Integer
logId
,
final
StringRedisTemplate
stringRedisTemplate
)
{
this
.
cmd
=
cmd
;
this
.
cmd
=
cmd
;
this
.
env
=
env
;
this
.
env
=
env
;
this
.
workingDir
=
workingDir
;
this
.
workingDir
=
workingDir
;
...
@@ -69,14 +69,14 @@ public class MythJobProcess implements Callable<String>{
...
@@ -69,14 +69,14 @@ public class MythJobProcess implements Callable<String>{
this
.
startupLatch
=
new
CountDownLatch
(
1
);
this
.
startupLatch
=
new
CountDownLatch
(
1
);
this
.
completeLatch
=
new
CountDownLatch
(
1
);
this
.
completeLatch
=
new
CountDownLatch
(
1
);
this
.
logId
=
logId
;
this
.
logId
=
logId
;
this
.
runId
=
runId
;
this
.
stringRedisTemplate
=
stringRedisTemplate
;
this
.
stringRedisTemplate
=
stringRedisTemplate
;
this
.
runKey
=
"REAL-EXEC-"
+
logId
;
}
}
public
MythJobProcess
(
final
List
<
String
>
cmd
,
final
Map
<
String
,
String
>
env
,
public
MythJobProcess
(
final
List
<
String
>
cmd
,
final
Map
<
String
,
String
>
env
,
final
String
workingDir
,
final
String
executeAsUserBinary
,
final
String
workingDir
,
final
String
executeAsUserBinary
,
final
String
effectiveUser
,
Integer
logId
,
final
String
runId
,
final
StringRedisTemplate
stringRedisTemplate
)
{
final
String
effectiveUser
,
Integer
logId
,
final
String
runId
,
final
StringRedisTemplate
stringRedisTemplate
)
{
this
(
cmd
,
env
,
workingDir
,
logId
,
runId
,
stringRedisTemplate
);
this
(
cmd
,
env
,
workingDir
,
logId
,
stringRedisTemplate
);
this
.
isExecuteAsUser
=
true
;
this
.
isExecuteAsUser
=
true
;
this
.
executeAsUserBinary
=
executeAsUserBinary
;
this
.
executeAsUserBinary
=
executeAsUserBinary
;
this
.
effectiveUser
=
effectiveUser
;
this
.
effectiveUser
=
effectiveUser
;
...
@@ -121,8 +121,8 @@ public class MythJobProcess implements Callable<String>{
...
@@ -121,8 +121,8 @@ public class MythJobProcess implements Callable<String>{
log
.
info
(
"进程的id "
+
this
.
processId
);
log
.
info
(
"进程的id "
+
this
.
processId
);
}
}
outputGobbler
=
new
LogGobbler
(
new
InputStreamReader
(
this
.
process
.
getInputStream
(),
"utf-8"
),
Boolean
.
FALSE
,
30
,
run
Id
,
stringRedisTemplate
);
outputGobbler
=
new
LogGobbler
(
new
InputStreamReader
(
this
.
process
.
getInputStream
(),
"utf-8"
),
Boolean
.
FALSE
,
30
,
run
Key
,
stringRedisTemplate
);
errorGobbler
=
new
LogGobbler
(
new
InputStreamReader
(
this
.
process
.
getErrorStream
(),
"utf-8"
),
Boolean
.
TRUE
,
30
,
run
Id
,
stringRedisTemplate
);
errorGobbler
=
new
LogGobbler
(
new
InputStreamReader
(
this
.
process
.
getErrorStream
(),
"utf-8"
),
Boolean
.
TRUE
,
30
,
run
Key
,
stringRedisTemplate
);
//开始获取进程的运行日志
//开始获取进程的运行日志
outputGobbler
.
start
();
outputGobbler
.
start
();
errorGobbler
.
start
();
errorGobbler
.
start
();
...
@@ -154,7 +154,7 @@ public class MythJobProcess implements Callable<String>{
...
@@ -154,7 +154,7 @@ public class MythJobProcess implements Callable<String>{
this
.
process
.
destroy
();
this
.
process
.
destroy
();
}
}
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
exitCode
==
0
?
true
:
false
).
build
();
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
exitCode
==
0
?
true
:
false
).
build
();
stringRedisTemplate
.
convertAndSend
(
run
Id
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
stringRedisTemplate
.
convertAndSend
(
run
Key
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
return
outputGobbler
.
getRecentLog
()
+
"\n"
+
errorGobbler
.
getRecentLog
();
return
outputGobbler
.
getRecentLog
()
+
"\n"
+
errorGobbler
.
getRecentLog
();
}
}
}
}
...
...
byit-myth-executor/myth-executor-server/src/main/java/com/byit/utils/LogGobbler.java
View file @
74f0e51a
...
@@ -22,14 +22,14 @@ public class LogGobbler extends Thread {
...
@@ -22,14 +22,14 @@ public class LogGobbler extends Thread {
private
final
BufferedReader
inputReader
;
private
final
BufferedReader
inputReader
;
private
final
boolean
isError
;
private
final
boolean
isError
;
private
final
StringBuilder
buffer
;
private
final
StringBuilder
buffer
;
private
final
String
run
Id
;
private
final
String
run
Key
;
private
final
StringRedisTemplate
stringRedisTemplate
;
private
final
StringRedisTemplate
stringRedisTemplate
;
public
LogGobbler
(
final
Reader
inputReader
,
final
boolean
isError
,
final
int
bufferLines
,
final
String
run
Id
,
final
StringRedisTemplate
stringRedisTemplate
)
{
public
LogGobbler
(
final
Reader
inputReader
,
final
boolean
isError
,
final
int
bufferLines
,
final
String
run
Key
,
final
StringRedisTemplate
stringRedisTemplate
)
{
this
.
inputReader
=
new
BufferedReader
(
inputReader
);
this
.
inputReader
=
new
BufferedReader
(
inputReader
);
this
.
isError
=
isError
;
this
.
isError
=
isError
;
this
.
buffer
=
new
StringBuilder
(
bufferLines
);
this
.
buffer
=
new
StringBuilder
(
bufferLines
);
this
.
run
Id
=
runId
;
this
.
run
Key
=
runKey
;
this
.
stringRedisTemplate
=
stringRedisTemplate
;
this
.
stringRedisTemplate
=
stringRedisTemplate
;
}
}
...
@@ -44,7 +44,7 @@ public class LogGobbler extends Thread {
...
@@ -44,7 +44,7 @@ public class LogGobbler extends Thread {
}
}
this
.
buffer
.
append
(
line
+
"\n"
);
this
.
buffer
.
append
(
line
+
"\n"
);
runLog
.
setRunLog
(
line
);
runLog
.
setRunLog
(
line
);
stringRedisTemplate
.
convertAndSend
(
run
Id
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
stringRedisTemplate
.
convertAndSend
(
run
Key
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
printLog
(
line
);
printLog
(
line
);
}
}
}
catch
(
final
IOException
e
)
{
}
catch
(
final
IOException
e
)
{
...
...
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