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
fa446771
Commit
fa446771
authored
Nov 05, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
错误日志上传
parent
d114f545
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
25 deletions
+84
-25
JavaNodeExecutorTask.java
...ore/src/main/java/com/byit/task/JavaNodeExecutorTask.java
+24
-6
JavaTaskJobTask.java
...min-core/src/main/java/com/byit/task/JavaTaskJobTask.java
+24
-6
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+30
-13
JobUtils.java
...xecutor-plugin/src/main/java/com/byit/utils/JobUtils.java
+6
-0
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/JavaNodeExecutorTask.java
View file @
fa446771
...
...
@@ -6,6 +6,8 @@ import com.byit.dto.executor.RunParamWrapped;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.enums.NodePropertyEnum
;
import
com.byit.enums.task.RunResultEnum
;
import
com.byit.filesystem.FastDfsFileSystem
;
import
com.byit.filesystem.FileSystem
;
import
com.byit.job.utils.MythLogUtils
;
import
com.byit.model.JobTaskRunLogWithBLOBs
;
import
com.byit.model.JobTaskSchedule
;
...
...
@@ -23,7 +25,9 @@ import io.netty.util.TimerTask;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.TreeSet
;
import
java.util.stream.Collectors
;
...
...
@@ -89,9 +93,9 @@ public class JavaNodeExecutorTask implements TimerTask {
GetRegConfig
getRegConfig
=
SpringUtil
.
getBean
(
GetRegConfig
.
class
);
TreeSet
<
String
>
gatewayConf
=
getRegConfig
.
getGatewayConf
();
List
<
String
>
callUrlList
=
gatewayConf
.
stream
().
map
(
callbackIp
->
{
if
(
"2"
.
equals
(
hasRelatedFlow
))
{
if
(
"2"
.
equals
(
hasRelatedFlow
))
{
return
String
.
format
(
"%s%s%s"
,
HTTP_PRE
,
callbackIp
,
HTTP_SUFFIX_FLOW
);
}
else
{
}
else
{
return
String
.
format
(
"%s%s%s"
,
HTTP_PRE
,
callbackIp
,
HTTP_SUFFIX
);
}
}).
collect
(
Collectors
.
toList
());
...
...
@@ -129,20 +133,34 @@ public class JavaNodeExecutorTask implements TimerTask {
jobTaskRunLogById
.
setAlertEnd
(
"1"
);
}
catch
(
Exception
e
)
{
String
runErrorMessage
=
MythLogUtils
.
getMessage
(
e
);
if
(
mythJobTaskSchedule
.
getScheduleType
()
==
4
)
{
StringRedisTemplate
stringRedisTemplate
=
(
StringRedisTemplate
)
SpringUtil
.
getBean
(
"stringRedisTemplate"
);
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
false
).
runLog
(
"执行资源异常"
+
MythLogUtils
.
getMessage
(
e
)
).
build
();
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
false
).
runLog
(
"执行资源异常"
+
runErrorMessage
).
build
();
//stringRedisTemplate.convertAndSend("REAL:EXEC:" + mythJobTaskSchedule.getLogId() , JSON.toJSONString(runLog, WriteClassName));
//使用redis 想队尾push一个值
stringRedisTemplate
.
opsForList
().
rightPush
(
"REAL:EXEC:"
+
mythJobTaskSchedule
.
getLogId
(),
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
}
log
.
error
(
"------执行机异常{}-----"
,
MythLogUtils
.
getMessage
(
e
)
);
log
.
error
(
"------执行机异常{}-----"
,
runErrorMessage
);
assert
jobTaskRunLogById
!=
null
;
jobTaskRunLogById
.
setTriggerCode
(
RunResultEnum
.
TRIGGER_ERROR
.
getCode
());
jobTaskRunLogById
.
setRunCode
(
RunResultEnum
.
RUN_ERROR
.
getCode
());
jobTaskRunLogById
.
setRunMsg
(
mythJobTaskSchedule
.
getNodeName
()
+
":"
+
MythLogUtils
.
getMessage
(
e
));
jobTaskRunLogById
.
setTriggerMsg
(
mythJobTaskSchedule
.
getNodeName
()
+
":"
+
MythLogUtils
.
getMessage
(
e
));
jobTaskRunLogById
.
setRunMsg
(
mythJobTaskSchedule
.
getNodeName
()
+
":"
+
runErrorMessage
);
jobTaskRunLogById
.
setTriggerMsg
(
mythJobTaskSchedule
.
getNodeName
()
+
":"
+
runErrorMessage
);
FileSystem
fileSystem
=
SpringUtil
.
getBean
(
FastDfsFileSystem
.
class
);
HashMap
<
String
,
String
>
fileNameMap
=
new
HashMap
<>(
1
);
fileNameMap
.
put
(
"filename"
,
String
.
format
(
"%s_error.log"
,
mythJobTaskSchedule
.
getNodeName
()));
String
uploadFilePath
;
try
{
uploadFilePath
=
fileSystem
.
uploadFile
(
runErrorMessage
.
getBytes
(
StandardCharsets
.
UTF_8
),
"log"
,
fileNameMap
);
jobTaskRunLogById
.
setLogRemotelyPath
(
uploadFilePath
);
}
catch
(
Exception
ex
)
{
String
logUploadErrorMessage
=
MythLogUtils
.
getMessage
(
ex
);
jobTaskRunLogById
.
setRunMsg
(
jobTaskRunLogById
.
getRunMsg
()
+
"\n 日志上传异常:"
+
logUploadErrorMessage
);
jobTaskRunLogById
.
setTriggerMsg
(
jobTaskRunLogById
.
getTriggerMsg
()
+
"\n 日志上传异常:"
+
logUploadErrorMessage
);
}
}
jobTaskRunLogService
.
updateJobTaskRunLogWithBLOBs
(
jobTaskRunLogById
);
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/JavaTaskJobTask.java
View file @
fa446771
...
...
@@ -2,11 +2,12 @@ package com.byit.task;
import
com.alibaba.fastjson.JSON
;
import
com.byit.conf.MythJobAutoConfigure
;
import
com.byit.dto.executor.RunParamWrapped
;
import
com.byit.dto.personalise.JavaJobConfDTO
;
import
com.byit.dto.plugin.JavaTask
;
import
com.byit.enums.ScheduleTypeEnum
;
import
com.byit.enums.task.RunResultEnum
;
import
com.byit.filesystem.FastDfsFileSystem
;
import
com.byit.filesystem.FileSystem
;
import
com.byit.job.utils.DateUtil
;
import
com.byit.job.utils.MythLogUtils
;
import
com.byit.model.JobTaskRunLogWithBLOBs
;
...
...
@@ -21,7 +22,9 @@ import io.netty.util.Timeout;
import
io.netty.util.TimerTask
;
import
org.apache.commons.lang3.StringUtils
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.TreeSet
;
import
java.util.stream.Collectors
;
...
...
@@ -55,7 +58,7 @@ public class JavaTaskJobTask implements TimerTask {
String
personalise
=
javaTask
.
getPersonalise
();
String
hasRelatedFlow
=
"1"
;
JavaJobConfDTO
javaJobConfDTO
=
JSON
.
parseObject
(
personalise
,
JavaJobConfDTO
.
class
);
if
(
javaJobConfDTO
!=
null
&&
StringUtils
.
isNoneBlank
(
javaJobConfDTO
.
getHasRelatedFlow
()))
{
if
(
javaJobConfDTO
!=
null
&&
StringUtils
.
isNoneBlank
(
javaJobConfDTO
.
getHasRelatedFlow
()))
{
hasRelatedFlow
=
javaJobConfDTO
.
getHasRelatedFlow
();
}
...
...
@@ -65,9 +68,9 @@ public class JavaTaskJobTask implements TimerTask {
TreeSet
<
String
>
gatewayConf
=
getRegConfig
.
getGatewayConf
();
String
finalHasRelatedFlow
=
hasRelatedFlow
;
List
<
String
>
callUrlList
=
gatewayConf
.
stream
().
map
(
callbackIp
->
{
if
(
"2"
.
equals
(
finalHasRelatedFlow
))
{
if
(
"2"
.
equals
(
finalHasRelatedFlow
))
{
return
String
.
format
(
"%s%s%s"
,
HTTP_PRE
,
callbackIp
,
HTTP_SUFFIX_FLOW
);
}
else
{
}
else
{
return
String
.
format
(
"%s%s%s"
,
HTTP_PRE
,
callbackIp
,
HTTP_SUFFIX
);
}
}).
collect
(
Collectors
.
toList
());
...
...
@@ -102,8 +105,23 @@ public class JavaTaskJobTask implements TimerTask {
log
.
setTriggerCode
(
RunResultEnum
.
TRIGGER_ERROR
.
getCode
());
log
.
setRunCode
(
RunResultEnum
.
RUN_ERROR
.
getCode
());
log
.
setRunMsg
(
javaTask
.
getTaskName
()
+
":"
+
MythLogUtils
.
getMessage
(
e
));
log
.
setTriggerMsg
(
javaTask
.
getTaskName
()
+
":"
+
MythLogUtils
.
getMessage
(
e
));
String
runErrorMsgger
=
MythLogUtils
.
getMessage
(
e
);
log
.
setRunMsg
(
javaTask
.
getTaskName
()
+
":"
+
runErrorMsgger
);
log
.
setTriggerMsg
(
javaTask
.
getTaskName
()
+
":"
+
runErrorMsgger
);
FileSystem
fileSystem
=
SpringUtil
.
getBean
(
FastDfsFileSystem
.
class
);
HashMap
<
String
,
String
>
fileNameMap
=
new
HashMap
<>(
1
);
fileNameMap
.
put
(
"filename"
,
String
.
format
(
"%s_error.log"
,
javaTask
.
getTaskName
()));
String
uploadFilePath
;
try
{
uploadFilePath
=
fileSystem
.
uploadFile
(
runErrorMsgger
.
getBytes
(
StandardCharsets
.
UTF_8
),
"log"
,
fileNameMap
);
log
.
setLogRemotelyPath
(
uploadFilePath
);
}
catch
(
Exception
ex
)
{
String
uploadLogErrorMessage
=
MythLogUtils
.
getMessage
(
ex
);
log
.
setRunMsg
(
log
.
getRunMsg
()
+
"\n 日志上传异常:"
+
uploadLogErrorMessage
);
log
.
setTriggerMsg
(
log
.
getTriggerMsg
()
+
"\n 日志上传异常:"
+
uploadLogErrorMessage
);
}
}
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
jobTaskRunLogService
.
updateJobTaskRunLogWithBLOBs
(
log
);
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
fa446771
...
...
@@ -11,6 +11,8 @@ import com.byit.dto.plugin.RunLog;
import
com.byit.enums.*
;
import
com.byit.enums.task.RunResultEnum
;
import
com.byit.enums.task.RunTypeEnum
;
import
com.byit.filesystem.FastDfsFileSystem
;
import
com.byit.filesystem.FileSystem
;
import
com.byit.job.utils.DateUtil
;
import
com.byit.job.utils.MythLogUtils
;
import
com.byit.job.utils.PlaceholderUtils
;
...
...
@@ -28,10 +30,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeSet
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
com
.
alibaba
.
fastjson
.
serializer
.
SerializerFeature
.
WriteClassName
;
...
...
@@ -137,11 +137,11 @@ public class ScriptExecutorJobTask implements TimerTask {
command
=
PlaceholderUtils
.
commandReplace
(
command
,
param
);
}
if
(
ScheduleTypeEnum
.
REPAIR
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
()))
{
if
(
command
.
startsWith
(
JAVA_TYPE
))
{
if
(
ScheduleTypeEnum
.
REPAIR
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
()))
{
if
(
command
.
startsWith
(
JAVA_TYPE
))
{
if
(
ScheduleTypeEnum
.
REPAIR
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
()))
{
command
=
PlaceholderUtils
.
commandDateReplace
(
param
,
command
,
param
.
get
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
()),
param
.
get
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
()));
}
else
{
}
else
{
command
=
PlaceholderUtils
.
commandDateReplace
(
param
,
command
);
}
}
...
...
@@ -163,6 +163,7 @@ public class ScriptExecutorJobTask implements TimerTask {
*/
private
void
runJob
(
JobTaskSchedule
mythJobTaskSchedule
)
{
DispatchResponseDto
dispatchResponseDto
=
new
DispatchResponseDto
();
String
uploadFilePath
=
null
;
try
{
paramBuild
(
mythJobTaskSchedule
);
mythJobTaskSchedule
.
setRunCommand
(
mythJobTaskSchedule
.
getRunCommand
());
...
...
@@ -179,7 +180,7 @@ public class ScriptExecutorJobTask implements TimerTask {
scriptDto
.
setRemotePath
(
mythJobTaskSchedule
.
getScriptUrls
());
GetRegConfig
getRegConfig
=
SpringUtil
.
getBean
(
GetRegConfig
.
class
);
TreeSet
<
String
>
gatewayConf
=
getRegConfig
.
getGatewayConf
();
if
(
CollectionUtil
.
isEmpty
(
gatewayConf
))
{
if
(
CollectionUtil
.
isEmpty
(
gatewayConf
))
{
throw
new
RuntimeException
(
"网关地址为空!"
);
}
List
<
String
>
callUrlList
=
gatewayConf
.
stream
().
map
(
callbackIp
->
String
.
format
(
"%s%s%s"
,
HTTP_PRE
,
callbackIp
,
HTTP_SUFFIX
)).
collect
(
Collectors
.
toList
());
...
...
@@ -188,18 +189,30 @@ public class ScriptExecutorJobTask implements TimerTask {
scriptDto
.
setLogRemotePath
(
jobTaskRunLogById
.
getLogRemotelyPath
());
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
}
catch
(
Exception
e
)
{
//错误信息
String
errorMessage
=
MythLogUtils
.
getMessage
(
e
);
if
(
mythJobTaskSchedule
.
getScheduleType
().
equals
(
4
))
{
StringRedisTemplate
stringRedisTemplate
=
(
StringRedisTemplate
)
SpringUtil
.
getBean
(
"stringRedisTemplate"
);
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
false
).
runLog
(
"执行资源异常"
+
MythLogUtils
.
getMessage
(
e
)
).
build
();
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
true
).
isSuccess
(
false
).
runLog
(
"执行资源异常"
+
errorMessage
).
build
();
stringRedisTemplate
.
opsForList
().
rightPush
(
"REAL:EXEC:"
+
mythJobTaskSchedule
.
getLogId
(),
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
}
log
.
error
(
"------执行机异常{}-----"
,
MythLogUtils
.
getMessage
(
e
)
);
dispatchResponseDto
.
setMsg
(
MythLogUtils
.
getMessage
(
e
)
);
log
.
error
(
"------执行机异常{}-----"
,
errorMessage
);
dispatchResponseDto
.
setMsg
(
errorMessage
);
dispatchResponseDto
.
setCode
(
JobResultEnum
.
DISPATCH_FAIL
.
getCode
());
FileSystem
fileSystem
=
SpringUtil
.
getBean
(
FastDfsFileSystem
.
class
);
HashMap
<
String
,
String
>
fileNameMap
=
new
HashMap
<>(
1
);
fileNameMap
.
put
(
"filename"
,
String
.
format
(
"%s_error.log"
,
mythJobTaskSchedule
.
getNodeName
()));
try
{
uploadFilePath
=
fileSystem
.
uploadFile
(
errorMessage
.
getBytes
(
StandardCharsets
.
UTF_8
),
"log"
,
fileNameMap
);
}
catch
(
Exception
ex
)
{
String
logUploadErrorMessage
=
MythLogUtils
.
getMessage
(
ex
);
dispatchResponseDto
.
setMsg
(
dispatchResponseDto
.
getMsg
()
+
"\n 日志上传异常:"
+
logUploadErrorMessage
);
}
}
saveLog
(
mythJobTaskSchedule
,
dispatchResponseDto
);
saveLog
(
mythJobTaskSchedule
,
dispatchResponseDto
,
uploadFilePath
);
}
...
...
@@ -231,12 +244,16 @@ public class ScriptExecutorJobTask implements TimerTask {
throw
new
RuntimeException
(
"服务器分配资源失败"
);
}
private
void
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
,
DispatchResponseDto
dispatchResponseDto
)
{
private
void
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
,
DispatchResponseDto
dispatchResponseDto
,
String
uploadFilePath
)
{
log
.
debug
(
"-----------saveLog--保存脚本调度日志开始------------"
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
JobTaskRunLogWithBLOBs
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
if
(
StringUtils
.
isNoneBlank
(
uploadFilePath
))
{
jobTaskRunLogById
.
setLogRemotelyPath
(
uploadFilePath
);
}
JobTaskRunLogWithBLOBs
jobTaskRunLog
=
new
JobTaskRunLogWithBLOBs
();
//放置调度记录
if
(
jobTaskRunLogById
.
getRunCount
()
>
1
)
{
...
...
byit-myth-executor/myth-executor-plugin/src/main/java/com/byit/utils/JobUtils.java
View file @
fa446771
...
...
@@ -435,6 +435,12 @@ public class JobUtils {
return
JSON
.
parseObject
(
response
,
ResponseResult
.
class
);
}
public
static
void
main
(
String
[]
args
)
{
JobUtils
.
setTOKEN
(
"huangfu"
);
JobUtils
.
setRequestUrl
(
"http://10.0.120.208:8998/myth-job-admin"
);
System
.
out
.
println
(
stopFlow
(
"皇甫"
,
"科星"
));
}
/**
* 删除工作流
*
...
...
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