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
73cba8e2
Commit
73cba8e2
authored
Feb 21, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
执行机拉取远程脚本文件并执行
parent
384182fc
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
154 additions
and
54 deletions
+154
-54
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+1
-0
ScriptDto.java
...core-common/src/main/java/com/byit/job/dto/ScriptDto.java
+4
-0
pom.xml
byit-myth-core/myth-executor-core/pom.xml
+4
-0
Test.java
...h-executor-core/src/main/java/com/byit/executor/Test.java
+0
-47
pom.xml
byit-myth-executor/myth-executor-server/pom.xml
+12
-0
RunThreadPool.java
...tor-server/src/main/java/com/byit/pool/RunThreadPool.java
+19
-0
ScriptExecutorServiceImpl.java
...main/java/com/byit/service/ScriptExecutorServiceImpl.java
+111
-3
ScriptAddFlow.java
...demo-client/src/main/java/com/byit/job/ScriptAddFlow.java
+3
-4
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
73cba8e2
...
@@ -50,6 +50,7 @@ public class ScriptExecutorJobTask implements TimerTask {
...
@@ -50,6 +50,7 @@ public class ScriptExecutorJobTask implements TimerTask {
scriptDto
.
setParam
(
mythJobTaskSchedule
.
getRunParam
());
scriptDto
.
setParam
(
mythJobTaskSchedule
.
getRunParam
());
scriptDto
.
setRunId
(
mythJobTaskSchedule
.
getRunId
());
scriptDto
.
setRunId
(
mythJobTaskSchedule
.
getRunId
());
scriptDto
.
setRemotePath
(
mythJobTaskSchedule
.
getScriptUrls
());
scriptDto
.
setRemotePath
(
mythJobTaskSchedule
.
getScriptUrls
());
scriptDto
.
setCallbackUrl
(
"http://127.0.0.1:8998/job/callbackRes"
);
DispatchResponseDto
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
DispatchResponseDto
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
System
.
out
.
println
(
dispatchResponseDto
);
System
.
out
.
println
(
dispatchResponseDto
);
}
}
...
...
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/ScriptDto.java
View file @
73cba8e2
...
@@ -30,4 +30,8 @@ public class ScriptDto implements Serializable {
...
@@ -30,4 +30,8 @@ public class ScriptDto implements Serializable {
* 脚本路径
* 脚本路径
*/
*/
private
String
remotePath
;
private
String
remotePath
;
/**
* 回调URL
*/
private
String
callbackUrl
;
}
}
byit-myth-core/myth-executor-core/pom.xml
View file @
73cba8e2
...
@@ -57,6 +57,10 @@
...
@@ -57,6 +57,10 @@
<artifactId>
junit
</artifactId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
byit-myth-core/myth-executor-core/src/main/java/com/byit/executor/Test.java
deleted
100644 → 0
View file @
384182fc
package
com
.
byit
.
executor
;
import
com.byit.executor.jobExecutor.process.MythJobProcess
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.IOException
;
import
java.util.*
;
/**
* @description:
* @author: gml
* @create: 2020-01-15 11:10
*/
@Slf4j
public
class
Test
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
List
<
MythJobProcess
>
list
=
new
ArrayList
<>();
Thread
thread
=
new
Thread
(()
->
{
List
<
String
>
cmdList
=
new
ArrayList
<>();
cmdList
=
Arrays
.
asList
(
"python D:\\workspace\\pycharmWorkSpace\\test\\com.test\\Test.py"
.
split
(
" "
));
Map
<
String
,
String
>
env
=
new
HashMap
<>();
env
.
put
(
"python"
,
"C:\\Program Files\\Python38"
);
MythJobProcess
mythJobProcess
=
new
MythJobProcess
(
cmdList
,
env
,
"D:\\workspace\\pycharmWorkSpace\\test\\com.test"
);
list
.
add
(
mythJobProcess
);
try
{
String
log
=
mythJobProcess
.
run
();
System
.
out
.
println
(
"运行日志"
+
log
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
});
thread
.
start
();
Thread
.
sleep
(
30000
);
list
.
forEach
(
process
->
{
process
.
hardKill
();
});
}
}
byit-myth-executor/myth-executor-server/pom.xml
View file @
73cba8e2
...
@@ -28,6 +28,17 @@
...
@@ -28,6 +28,17 @@
<groupId>
myth-job
</groupId>
<groupId>
myth-job
</groupId>
<artifactId>
byit-myth-rpc
</artifactId>
<artifactId>
byit-myth-rpc
</artifactId>
</dependency>
</dependency>
<!-- <!– slf4j –>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>-->
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
byit-myth-executor/myth-executor-server/src/main/java/com/byit/pool/RunThreadPool.java
0 → 100644
View file @
73cba8e2
package
com
.
byit
.
pool
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
/**
* @author huangfu
*/
public
class
RunThreadPool
{
public
static
final
ThreadPoolExecutor
SCRIPT_RUN_THREAD_POOL
=
new
ThreadPoolExecutor
(
100
,
400
,
60L
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<
Runnable
>(
600
),
r
->
new
Thread
(
r
,
"Myth job script run thread-"
+
r
.
hashCode
()));
}
byit-myth-executor/myth-executor-server/src/main/java/com/byit/service/ScriptExecutorServiceImpl.java
View file @
73cba8e2
package
com
.
byit
.
service
;
package
com
.
byit
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.executor.api.ScriptExecutorService
;
import
com.byit.executor.api.ScriptExecutorService
;
import
com.byit.executor.filesystem.FileSystem
;
import
com.byit.job.dto.DispatchResponseDto
;
import
com.byit.job.dto.DispatchResponseDto
;
import
com.byit.job.dto.JobRunResultDto
;
import
com.byit.job.dto.ScriptDto
;
import
com.byit.job.dto.ScriptDto
;
import
com.byit.job.enums.JobResultEnum
;
import
com.byit.job.enums.JobResultEnum
;
import
com.byit.job.vo.ReturnResult
;
import
com.byit.pool.RunThreadPool
;
import
com.byit.rpc.remoting.provider.annotation.RpcService
;
import
com.byit.rpc.remoting.provider.annotation.RpcService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.csource.common.MyException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.UUID
;
/**
/**
* 脚本执行的实现
* 脚本执行的实现
* @author huangfu
* @author huangfu
*/
*/
@Service
@Service
@RpcService
@RpcService
@Slf4j
public
class
ScriptExecutorServiceImpl
implements
ScriptExecutorService
{
public
class
ScriptExecutorServiceImpl
implements
ScriptExecutorService
{
@Value
(
"${myth-job.log.root.path}"
)
private
String
rootLogPath
;
@Value
(
"${myth-job.script.root.path}"
)
private
String
rootScriptPath
;
private
final
FileSystem
fileSystem
;
public
ScriptExecutorServiceImpl
(
FileSystem
fileSystem
)
{
this
.
fileSystem
=
fileSystem
;
}
@Override
@Override
public
DispatchResponseDto
runPythonScript
(
ScriptDto
scriptDto
)
{
public
DispatchResponseDto
runPythonScript
(
ScriptDto
scriptDto
)
{
System
.
out
.
println
(
"--------------3脚本调用开始-----------"
);
DispatchResponseDto
dispatchResponseDto
;
try
{
RunThreadPool
.
SCRIPT_RUN_THREAD_POOL
.
execute
(()->{
log
.
debug
(
"--------------脚本调用开始-----------"
);
//创建回复对象
JobRunResultDto
jobRunResultDto
=
new
JobRunResultDto
();
jobRunResultDto
.
setStartTime
(
new
Date
());
//设定运行标识
jobRunResultDto
.
setJobRunId
(
scriptDto
.
getRunId
());
//获取回调通知URL
String
callbackUrl
=
scriptDto
.
getCallbackUrl
();
String
remotePath
=
scriptDto
.
getRemotePath
();
String
command
=
scriptDto
.
getCommand
();
String
scriptPath
=
byteArrayToFile
(
remotePath
);
command
=
command
+
" "
+
scriptPath
;
log
.
info
(
"-----------执行命令,{}-----------"
,
command
);
//设置结束时间
jobRunResultDto
.
setEndTime
(
new
Date
());
jobRunResultDto
.
setReturnResult
(
ReturnResult
.
SUCCESS
);
jobRunResultDto
.
setLogId
(
scriptDto
.
getLogId
());
cn
.
hutool
.
http
.
HttpUtil
.
post
(
callbackUrl
,
JSON
.
toJSONString
(
jobRunResultDto
));
log
.
debug
(
"--------------脚本调用结束-----------"
);
});
System
.
out
.
println
(
"--------------3脚本调用结束-----------"
);
dispatchResponseDto
=
DispatchResponseDto
.
builder
()
DispatchResponseDto
dispatchResponseDto
=
DispatchResponseDto
.
builder
()
.
code
(
JobResultEnum
.
DISPATCH_SUCCESS
.
getCode
())
.
code
(
JobResultEnum
.
DISPATCH_SUCCESS
.
getCode
())
.
msg
(
JobResultEnum
.
DISPATCH_SUCCESS
.
getMsg
())
.
msg
(
JobResultEnum
.
DISPATCH_SUCCESS
.
getMsg
())
.
build
();
.
build
();
}
catch
(
Exception
e
){
dispatchResponseDto
=
DispatchResponseDto
.
builder
()
.
code
(
JobResultEnum
.
DISPATCH_FAIL
.
getCode
())
.
msg
(
JobResultEnum
.
DISPATCH_FAIL
.
getMsg
())
.
build
();
}
return
dispatchResponseDto
;
return
dispatchResponseDto
;
}
}
/**
* 将脚本字节转换成文件
* @return 生成文件的本地路径
*/
private
String
byteArrayToFile
(
String
remotePath
){
File
rootPathMkdir
=
new
File
(
rootScriptPath
);
if
(!
rootPathMkdir
.
exists
()){
rootPathMkdir
.
mkdirs
();
}
OutputStream
out
=
null
;
File
file
=
null
;
try
{
byte
[]
scriptByteArray
=
fileSystem
.
downloaderFile
(
remotePath
);
Map
<
String
,
String
>
fileMate
=
fileSystem
.
getFileMate
(
remotePath
);
String
fileName
=
fileMate
.
get
(
"filename"
);
fileName
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)+
fileName
;
file
=
new
File
(
rootPathMkdir
,
fileName
);
if
(!
file
.
exists
()){
file
.
createNewFile
();
}
out
=
new
FileOutputStream
(
file
);
out
.
write
(
scriptByteArray
);
return
file
.
getPath
();
}
catch
(
IOException
|
MyException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
out
!=
null
){
try
{
out
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
null
;
}
/**
* 将字符串转换我数组
* @param logData
* @return
*/
private
byte
[]
stringToByteArray
(
String
logData
)
{
return
logData
.
getBytes
(
StandardCharsets
.
UTF_8
);
}
}
}
demo-client/byit-demo-client/src/main/java/com/byit/job/ScriptAddFlow.java
View file @
73cba8e2
...
@@ -70,15 +70,14 @@ public class ScriptAddFlow {
...
@@ -70,15 +70,14 @@ public class ScriptAddFlow {
pluginNode2
.
setType
(
"node"
);
pluginNode2
.
setType
(
"node"
);
pluginNode2
.
setAuthor
(
"皇甫"
);
pluginNode2
.
setAuthor
(
"皇甫"
);
pluginNode2
.
setJobType
(
"SCRIPT"
);
pluginNode2
.
setJobType
(
"SCRIPT"
);
pluginNode2
.
setHandlerName
(
"addJob"
);
pluginNode2
.
setScriptUrls
(
"ddmp/M00/00/00/CgB4Al5PswCAGEeiAAAHa95jlv4490.log"
);
pluginNode2
.
setRunParam
(
"add1"
);
pluginNode2
.
setRunCommand
(
"python"
);
pluginNode2
.
setRunParam
(
"test1"
);
pluginNodeConfig2
.
setFailedRetryCount
(
2
);
pluginNodeConfig2
.
setFailedRetryCount
(
2
);
pluginNodeConfig2
.
setFailedRetryInterval
(
TimeUnit
.
MINUTES
.
toSeconds
(
2
));
pluginNodeConfig2
.
setFailedRetryInterval
(
TimeUnit
.
MINUTES
.
toSeconds
(
2
));
pluginNodeConfig2
.
setNodeCron
(
"0 0/7 * * * ? *"
);
pluginNodeConfig2
.
setNodeCron
(
"0 0/7 * * * ? *"
);
pluginNodeConfig2
.
setNodeTimeout
(-
1L
);
pluginNodeConfig2
.
setNodeTimeout
(-
1L
);
pluginNodeConfig2
.
setPluginUrls
(
"http://127.0.0.1:8888"
);
pluginNodeConfig2
.
setPriority
(
"1"
);
pluginNodeConfig2
.
setPriority
(
"1"
);
pluginNodeConfig2
.
setRoutingStrategy
(
LoadBalance
.
ROUND
.
name
());
pluginNode2
.
setConfig
(
pluginNodeConfig2
);
pluginNode2
.
setConfig
(
pluginNodeConfig2
);
pluginNode2
.
setDependNodeNameList
(
Collections
.
singletonList
(
"start"
));
pluginNode2
.
setDependNodeNameList
(
Collections
.
singletonList
(
"start"
));
...
...
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