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
a7396bf6
Commit
a7396bf6
authored
Feb 17, 2020
by
guo_minglei@163.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
执行器添加上下文
parent
ef9aa1ad
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
3 deletions
+61
-3
MythJobProcess.java
...com/byit/executor/jobExecutor/process/MythJobProcess.java
+10
-3
JobContentUtil.java
.../src/main/java/com/byit/executor/util/JobContentUtil.java
+51
-0
No files found.
byit-myth-core/myth-executor-core/src/main/java/com/byit/executor/jobExecutor/process/MythJobProcess.java
View file @
a7396bf6
package
com
.
byit
.
executor
.
jobExecutor
.
process
;
package
com
.
byit
.
executor
.
jobExecutor
.
process
;
import
com.byit.executor.util.JobContentUtil
;
import
com.byit.executor.util.LogGobbler
;
import
com.byit.executor.util.LogGobbler
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -44,9 +45,11 @@ public class MythJobProcess {
...
@@ -44,9 +45,11 @@ public class MythJobProcess {
private
String
executeAsUserBinary
=
null
;
private
String
executeAsUserBinary
=
null
;
//有效用户
//有效用户
private
String
effectiveUser
=
null
;
private
String
effectiveUser
=
null
;
//本次任务对应的日志id
private
Integer
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
workingDir
,
final
Integer
logId
)
{
this
.
cmd
=
cmd
;
this
.
cmd
=
cmd
;
this
.
env
=
env
;
this
.
env
=
env
;
this
.
workingDir
=
workingDir
;
this
.
workingDir
=
workingDir
;
...
@@ -57,8 +60,8 @@ public class MythJobProcess {
...
@@ -57,8 +60,8 @@ public class MythJobProcess {
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
)
{
final
String
effectiveUser
,
Integer
logId
)
{
this
(
cmd
,
env
,
workingDir
);
this
(
cmd
,
env
,
workingDir
,
logId
);
this
.
isExecuteAsUser
=
true
;
this
.
isExecuteAsUser
=
true
;
this
.
executeAsUserBinary
=
executeAsUserBinary
;
this
.
executeAsUserBinary
=
executeAsUserBinary
;
this
.
effectiveUser
=
effectiveUser
;
this
.
effectiveUser
=
effectiveUser
;
...
@@ -75,6 +78,8 @@ public class MythJobProcess {
...
@@ -75,6 +78,8 @@ public class MythJobProcess {
//标记为开始运行
//标记为开始运行
this
.
startupLatch
.
countDown
();
this
.
startupLatch
.
countDown
();
//记录上下文内容
JobContentUtil
.
doPut
(
logId
,
this
);
final
ProcessBuilder
builder
=
new
ProcessBuilder
(
this
.
cmd
);
final
ProcessBuilder
builder
=
new
ProcessBuilder
(
this
.
cmd
);
if
(!
Objects
.
isNull
(
workingDir
)){
if
(!
Objects
.
isNull
(
workingDir
)){
...
@@ -126,6 +131,8 @@ public class MythJobProcess {
...
@@ -126,6 +131,8 @@ public class MythJobProcess {
this
.
process
.
getInputStream
().
close
();
this
.
process
.
getInputStream
().
close
();
this
.
process
.
getOutputStream
().
close
();
this
.
process
.
getOutputStream
().
close
();
this
.
process
.
getErrorStream
().
close
();
this
.
process
.
getErrorStream
().
close
();
//运行完毕将本任务移除上下文内容
JobContentUtil
.
remove
(
logId
);
if
(
this
.
process
.
isAlive
()){
if
(
this
.
process
.
isAlive
()){
this
.
process
.
destroy
();
this
.
process
.
destroy
();
}
}
...
...
byit-myth-core/myth-executor-core/src/main/java/com/byit/executor/util/JobContentUtil.java
0 → 100644
View file @
a7396bf6
package
com
.
byit
.
executor
.
util
;
import
com.byit.executor.jobExecutor.process.MythJobProcess
;
import
java.util.HashMap
;
/**
* 脚本运行的上下文内容存储
*/
public
class
JobContentUtil
{
//任务总数
private
static
Integer
jobNum
=
0
;
//正在运行的任务总数
private
static
Integer
runIngJob
=
0
;
//正在等待运行的任务总数
private
static
Integer
watingJob
=
0
;
//任务对应的日志id和对应的线程对象
private
static
HashMap
<
Integer
,
MythJobProcess
>
jobContent
=
new
HashMap
<>(
10
);
public
static
synchronized
void
doPut
(
Integer
logId
,
MythJobProcess
jobProcess
){
jobNum
++;
watingJob
++;
jobContent
.
put
(
logId
,
jobProcess
);
}
public
static
synchronized
void
remove
(
Integer
logId
){
jobNum
--;
runIngJob
--;
MythJobProcess
jobProcess
=
jobContent
.
get
(
logId
);
if
(
jobProcess
!=
null
){
jobContent
.
remove
(
logId
,
jobProcess
);
}
}
public
static
synchronized
MythJobProcess
getJobThread
(
Integer
logId
){
MythJobProcess
jobProcess
=
jobContent
.
get
(
logId
);
if
(
jobProcess
!=
null
){
return
jobProcess
;
}
return
null
;
}
public
static
synchronized
void
runJobThread
(
Integer
logId
){
MythJobProcess
jobProcess
=
jobContent
.
get
(
logId
);
if
(
jobProcess
!=
null
){
watingJob
--;
jobNum
++;
}
}
}
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