Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
554429ea
提交
554429ea
authored
1月 16, 2016
作者:
xueli.xue
浏览文件
操作
浏览文件
下载
差异文件
重要版本升级:
1、新增“任务组”; 2、整合“远程调度”和“本地调度”;
上级
2bfd1cb7
ee501408
隐藏空白字符变更
内嵌
并排
正在显示
19 个修改的文件
包含
572 行增加
和
547 行删除
+572
-547
JobInfoController.java
...c/main/java/com/xxl/job/controller/JobInfoController.java
+113
-97
JobLogController.java
...rc/main/java/com/xxl/job/controller/JobLogController.java
+5
-3
XxlJobInfo.java
...dmin/src/main/java/com/xxl/job/core/model/XxlJobInfo.java
+20
-11
XxlJobLog.java
...admin/src/main/java/com/xxl/job/core/model/XxlJobLog.java
+10
-4
DynamicSchedulerUtil.java
...main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java
+76
-52
IXxlJobInfoDao.java
...b-admin/src/main/java/com/xxl/job/dao/IXxlJobInfoDao.java
+4
-5
XxlJobInfoDaoImpl.java
...src/main/java/com/xxl/job/dao/impl/XxlJobInfoDaoImpl.java
+16
-11
HttpJobBean.java
...in/src/main/java/com/xxl/job/service/job/HttpJobBean.java
+22
-22
XxlJobInfoMapper.xml
...in/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml
+58
-31
XxlJobLogMapper.xml
...min/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml
+5
-1
index.ftl
...-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl
+47
-67
index.ftl
...b-admin/src/main/webapp/WEB-INF/template/joblog/index.ftl
+2
-1
jobinfo.index.1.js
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js
+160
-105
joblog.index.1.js
xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js
+1
-0
XxlJobInfoTest.java
...in/src/test/java/com/xxl/job/dao/impl/XxlJobInfoTest.java
+4
-4
XxlJobLogTest.java
...min/src/test/java/com/xxl/job/dao/impl/XxlJobLogTest.java
+2
-2
DemoJobHandler.java
...main/java/com/xxl/job/service/handler/DemoJobHandler.java
+3
-4
HandlerRepository.java
...in/java/com/xxl/job/client/handler/HandlerRepository.java
+23
-124
IJobHandler.java
...src/main/java/com/xxl/job/client/handler/IJobHandler.java
+1
-3
没有找到文件。
xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java
浏览文件 @
554429ea
package
com
.
xxl
.
job
.
controller
;
package
com
.
xxl
.
job
.
controller
;
import
java.
io.UnsupportedEncodingException
;
import
java.
util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.quartz.CronExpression
;
import
org.quartz.CronExpression
;
...
@@ -28,6 +25,8 @@ import com.xxl.job.core.model.XxlJobInfo;
...
@@ -28,6 +25,8 @@ import com.xxl.job.core.model.XxlJobInfo;
import
com.xxl.job.core.util.DynamicSchedulerUtil
;
import
com.xxl.job.core.util.DynamicSchedulerUtil
;
import
com.xxl.job.dao.IXxlJobInfoDao
;
import
com.xxl.job.dao.IXxlJobInfoDao
;
import
com.xxl.job.service.job.HttpJobBean
;
import
com.xxl.job.service.job.HttpJobBean
;
import
com.xxl.job.service.job.LocalJobBean
;
import
com.xxl.job.service.job.LocalJobBeanB
;
/**
/**
* index controller
* index controller
...
@@ -40,9 +39,20 @@ public class JobInfoController {
...
@@ -40,9 +39,20 @@ public class JobInfoController {
@Resource
@Resource
private
IXxlJobInfoDao
xxlJobInfoDao
;
private
IXxlJobInfoDao
xxlJobInfoDao
;
// remote job bean
public
static
Class
<?
extends
Job
>
remoteJobBean
=
HttpJobBean
.
class
;
// loacal job bean
public
static
List
<
Class
<?
extends
Job
>>
localJobBeanList
=
new
ArrayList
<
Class
<?
extends
Job
>>();
static
{
localJobBeanList
.
add
(
LocalJobBean
.
class
);
localJobBeanList
.
add
(
LocalJobBeanB
.
class
);
}
@RequestMapping
@RequestMapping
public
String
index
(
Model
model
)
{
public
String
index
(
Model
model
)
{
model
.
addAttribute
(
"JobGroupList"
,
JobGroupEnum
.
values
());
model
.
addAttribute
(
"localJobBeanList"
,
localJobBeanList
);
// 本地任务-列表
model
.
addAttribute
(
"remoteJobBean"
,
remoteJobBean
);
// 远程任务-jobBean
model
.
addAttribute
(
"JobGroupList"
,
JobGroupEnum
.
values
());
// 任务组列表
return
"jobinfo/index"
;
return
"jobinfo/index"
;
}
}
...
@@ -50,11 +60,11 @@ public class JobInfoController {
...
@@ -50,11 +60,11 @@ public class JobInfoController {
@ResponseBody
@ResponseBody
public
Map
<
String
,
Object
>
pageList
(
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
int
start
,
public
Map
<
String
,
Object
>
pageList
(
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
int
start
,
@RequestParam
(
required
=
false
,
defaultValue
=
"10"
)
int
length
,
@RequestParam
(
required
=
false
,
defaultValue
=
"10"
)
int
length
,
String
jobName
,
String
filterTime
)
{
String
job
Group
,
String
job
Name
,
String
filterTime
)
{
// page list
// page list
List
<
XxlJobInfo
>
list
=
xxlJobInfoDao
.
pageList
(
start
,
length
,
job
Name
,
null
,
null
);
List
<
XxlJobInfo
>
list
=
xxlJobInfoDao
.
pageList
(
start
,
length
,
job
Group
,
jobName
);
int
list_count
=
xxlJobInfoDao
.
pageListCount
(
start
,
length
,
job
Name
,
null
,
null
);
int
list_count
=
xxlJobInfoDao
.
pageListCount
(
start
,
length
,
job
Group
,
jobName
);
// fill job info
// fill job info
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
...
@@ -71,72 +81,89 @@ public class JobInfoController {
...
@@ -71,72 +81,89 @@ public class JobInfoController {
return
maps
;
return
maps
;
}
}
@SuppressWarnings
(
"unchecked"
)
@RequestMapping
(
"/add"
)
@RequestMapping
(
"/add"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
add
(
HttpServletRequest
request
)
{
public
ReturnT
<
String
>
add
(
String
jobGroup
,
String
jobName
,
String
jobCron
,
String
jobDesc
,
String
jobClass
,
String
triggerKeyName
=
null
;
String
handler_params
,
String
handler_address
,
String
handler_name
,
String
cronExpression
=
null
;
String
author
,
String
alarm_email
,
int
alarm_threshold
)
{
Map
<
String
,
String
>
jobData
=
new
HashMap
<
String
,
String
>();
// valid
if
(
JobGroupEnum
.
match
(
jobGroup
)
==
null
)
{
return
new
ReturnT
<
String
>(
500
,
"请选择“任务组”"
);
}
if
(
StringUtils
.
isBlank
(
jobName
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务名”"
);
}
if
(!
CronExpression
.
isValidExpression
(
jobCron
))
{
return
new
ReturnT
<
String
>(
500
,
"“corn”不合法"
);
}
if
(
StringUtils
.
isBlank
(
jobDesc
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务描述”"
);
}
Class
<?
extends
Job
>
jobClass_
=
null
;
try
{
try
{
request
.
setCharacterEncoding
(
"utf-8"
);
Class
<?>
clazz
=
Class
.
forName
(
jobClass
);
}
catch
(
UnsupportedEncodingException
e1
)
{
if
(
clazz
!=
null
)
{
jobClass_
=
(
Class
<?
extends
Job
>)
clazz
;
}
}
catch
(
ClassNotFoundException
e1
)
{
e1
.
printStackTrace
();
e1
.
printStackTrace
();
}
}
@SuppressWarnings
(
"unchecked"
)
if
(
jobClass_
==
null
)
{
Set
<
Map
.
Entry
<
String
,
String
[]>>
paramSet
=
request
.
getParameterMap
().
entrySet
();
return
new
ReturnT
<
String
>(
500
,
"请选择“JobBean”"
);
for
(
Entry
<
String
,
String
[]>
param
:
paramSet
)
{
if
(
param
.
getKey
().
equals
(
"triggerKeyName"
))
{
triggerKeyName
=
param
.
getValue
()[
0
];
}
else
if
(
param
.
getKey
().
equals
(
"cronExpression"
))
{
cronExpression
=
param
.
getValue
()[
0
];
}
else
{
jobData
.
put
(
param
.
getKey
(),
(
String
)
(
param
.
getValue
().
length
>
0
?
param
.
getValue
()[
0
]:
param
.
getValue
()));
}
}
}
if
(
jobClass_
.
getClass
().
getName
().
equals
(
remoteJobBean
.
getName
()))
{
// triggerKeyName
if
(
StringUtils
.
isBlank
(
handler_address
))
{
if
(
StringUtils
.
isBlank
(
triggerKeyName
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“远程-机器地址”"
);
return
new
ReturnT
<
String
>(
500
,
"请输入“任务key”"
);
}
if
(
StringUtils
.
isBlank
(
handler_name
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“远程-执行器”"
);
}
}
}
if
(
StringUtils
.
isBlank
(
author
))
{
// cronExpression
return
new
ReturnT
<
String
>(
500
,
"请输入“负责人”"
);
if
(
StringUtils
.
isBlank
(
cronExpression
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务corn”"
);
}
}
if
(
!
CronExpression
.
isValidExpression
(
cronExpression
))
{
if
(
StringUtils
.
isBlank
(
alarm_email
))
{
return
new
ReturnT
<
String
>(
500
,
"
“任务corn”不合法
"
);
return
new
ReturnT
<
String
>(
500
,
"
请输入“报警邮件”
"
);
}
}
// jobData
try
{
if
(
jobData
.
get
(
HandlerRepository
.
job_desc
)==
null
||
jobData
.
get
(
HandlerRepository
.
job_desc
).
toString
().
trim
().
length
()==
0
)
{
if
(
DynamicSchedulerUtil
.
checkExists
(
jobName
,
jobGroup
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务描述”"
);
return
new
ReturnT
<
String
>(
500
,
"此任务已存在,请更换任务组或任务名"
);
}
}
if
(
jobData
.
get
(
HandlerRepository
.
job_url
)==
null
||
jobData
.
get
(
HandlerRepository
.
job_url
).
toString
().
trim
().
length
()==
0
)
{
}
catch
(
SchedulerException
e1
)
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务URL”"
);
e1
.
printStackTrace
();
}
return
new
ReturnT
<
String
>(
500
,
"此任务已存在,请更换任务组或任务名"
);
if
(
jobData
.
get
(
HandlerRepository
.
handleName
)==
null
||
jobData
.
get
(
HandlerRepository
.
handleName
).
toString
().
trim
().
length
()==
0
)
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务handler”"
);
}
}
// jobClass
HashMap
<
String
,
String
>
jobDataMap
=
new
HashMap
<
String
,
String
>();
Class
<?
extends
Job
>
jobClass
=
HttpJobBean
.
class
;
jobDataMap
.
put
(
HandlerRepository
.
HANDLER_PARAMS
,
handler_params
);
jobDataMap
.
put
(
HandlerRepository
.
HANDLER_ADDRESS
,
handler_address
);
jobDataMap
.
put
(
HandlerRepository
.
HANDLER_NAME
,
handler_name
);
// Backup to the database
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setJobGroup
(
jobGroup
);
jobInfo
.
setJobName
(
jobName
);
jobInfo
.
setJobCron
(
jobCron
);
jobInfo
.
setJobDesc
(
jobDesc
);
jobInfo
.
setJobClass
(
jobClass
);
jobInfo
.
setJobData
(
JacksonUtil
.
writeValueAsString
(
jobDataMap
));
jobInfo
.
setAuthor
(
author
);
jobInfo
.
setAlarmEmail
(
alarm_email
);
jobInfo
.
setAlarmThreshold
(
alarm_threshold
);
xxlJobInfoDao
.
save
(
jobInfo
);
try
{
try
{
// add job 2 quartz
// add job 2 quartz
boolean
result
=
DynamicSchedulerUtil
.
addJob
(
triggerKeyName
,
cronExpression
,
jobClass
,
null
);
boolean
result
=
DynamicSchedulerUtil
.
addJob
(
jobInfo
);
if
(!
result
)
{
if
(
result
)
{
return
new
ReturnT
<
String
>(
500
,
"任务ID重复,请更换确认"
);
return
ReturnT
.
SUCCESS
;
}
else
{
xxlJobInfoDao
.
delete
(
jobGroup
,
jobName
);
return
new
ReturnT
<
String
>(
500
,
"新增任务失败"
);
}
}
// Backup to the database
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setJobName
(
triggerKeyName
);
jobInfo
.
setJobCron
(
cronExpression
);
jobInfo
.
setJobClass
(
jobClass
.
getName
());
jobInfo
.
setJobData
(
JacksonUtil
.
writeValueAsString
(
jobData
));
xxlJobInfoDao
.
save
(
jobInfo
);
return
ReturnT
.
SUCCESS
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -145,27 +172,30 @@ public class JobInfoController {
...
@@ -145,27 +172,30 @@ public class JobInfoController {
@RequestMapping
(
"/reschedule"
)
@RequestMapping
(
"/reschedule"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
reschedule
(
String
triggerKeyName
,
String
cronExpression
)
{
public
ReturnT
<
String
>
reschedule
(
String
jobGroup
,
String
jobName
,
String
jobCron
,
String
jobDesc
,
String
jobClass
,
// triggerKeyName
String
handler_params
,
String
handler_address
,
String
handler_name
,
if
(
StringUtils
.
isBlank
(
triggerKeyName
))
{
String
author
,
String
alarm_email
,
int
alarm_threshold
)
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务key”"
);
// valid
if
(
JobGroupEnum
.
match
(
jobGroup
)
==
null
)
{
return
new
ReturnT
<
String
>(
500
,
"请选择“任务组”"
);
}
}
// cronExpression
if
(
StringUtils
.
isBlank
(
jobName
))
{
if
(
StringUtils
.
isBlank
(
cronExpression
))
{
return
new
ReturnT
<
String
>(
500
,
"请输入“任务名”"
);
return
new
ReturnT
<
String
>(
500
,
"请输入“任务corn”"
);
}
}
if
(!
CronExpression
.
isValidExpression
(
cronExpressi
on
))
{
if
(!
CronExpression
.
isValidExpression
(
jobCr
on
))
{
return
new
ReturnT
<
String
>(
500
,
"“
任务
corn”不合法"
);
return
new
ReturnT
<
String
>(
500
,
"“corn”不合法"
);
}
}
XxlJobInfo
jobInfo
=
xxlJobInfoDao
.
load
(
jobGroup
,
jobName
);
jobInfo
.
setJobCron
(
jobCron
);
try
{
try
{
DynamicSchedulerUtil
.
rescheduleJob
(
triggerKeyName
,
cronExpression
);
// fresh quartz
DynamicSchedulerUtil
.
rescheduleJob
(
jobInfo
);
// update
// fresh db
XxlJobInfo
jobInfo
=
xxlJobInfoDao
.
load
(
triggerKeyName
);
xxlJobInfoDao
.
update
(
jobInfo
);
if
(
jobInfo
!=
null
)
{
jobInfo
.
setJobCron
(
cronExpression
);
xxlJobInfoDao
.
update
(
jobInfo
);
}
return
ReturnT
.
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -175,13 +205,11 @@ public class JobInfoController {
...
@@ -175,13 +205,11 @@ public class JobInfoController {
@RequestMapping
(
"/remove"
)
@RequestMapping
(
"/remove"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
remove
(
String
triggerKey
Name
)
{
public
ReturnT
<
String
>
remove
(
String
jobGroup
,
String
job
Name
)
{
try
{
try
{
if
(
triggerKeyName
!=
null
)
{
DynamicSchedulerUtil
.
removeJob
(
jobName
,
jobGroup
);
DynamicSchedulerUtil
.
removeJob
(
triggerKeyName
);
xxlJobInfoDao
.
delete
(
jobGroup
,
jobName
);
xxlJobInfoDao
.
delete
(
triggerKeyName
);
return
ReturnT
.
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -190,15 +218,9 @@ public class JobInfoController {
...
@@ -190,15 +218,9 @@ public class JobInfoController {
@RequestMapping
(
"/pause"
)
@RequestMapping
(
"/pause"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
pause
(
String
triggerKey
Name
)
{
public
ReturnT
<
String
>
pause
(
String
jobGroup
,
String
job
Name
)
{
try
{
try
{
DynamicSchedulerUtil
.
pauseJob
(
triggerKeyName
);
DynamicSchedulerUtil
.
pauseJob
(
jobName
,
jobGroup
);
// jobStatus do not store
// update
XxlJobInfo
jobInfo
=
xxlJobInfoDao
.
load
(
triggerKeyName
);
if
(
jobInfo
!=
null
)
{
jobInfo
.
setJobStatus
(
"PAUSED"
);
xxlJobInfoDao
.
update
(
jobInfo
);
}
return
ReturnT
.
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -208,15 +230,9 @@ public class JobInfoController {
...
@@ -208,15 +230,9 @@ public class JobInfoController {
@RequestMapping
(
"/resume"
)
@RequestMapping
(
"/resume"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
resume
(
String
triggerKey
Name
)
{
public
ReturnT
<
String
>
resume
(
String
jobGroup
,
String
job
Name
)
{
try
{
try
{
DynamicSchedulerUtil
.
resumeJob
(
triggerKeyName
);
DynamicSchedulerUtil
.
resumeJob
(
jobName
,
jobGroup
);
// update
XxlJobInfo
jobInfo
=
xxlJobInfoDao
.
load
(
triggerKeyName
);
if
(
jobInfo
!=
null
)
{
jobInfo
.
setJobStatus
(
"NORMAL"
);
xxlJobInfoDao
.
update
(
jobInfo
);
}
return
ReturnT
.
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -226,9 +242,9 @@ public class JobInfoController {
...
@@ -226,9 +242,9 @@ public class JobInfoController {
@RequestMapping
(
"/trigger"
)
@RequestMapping
(
"/trigger"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
triggerJob
(
String
triggerKey
Name
)
{
public
ReturnT
<
String
>
triggerJob
(
String
jobGroup
,
String
job
Name
)
{
try
{
try
{
DynamicSchedulerUtil
.
triggerJob
(
triggerKeyName
);
DynamicSchedulerUtil
.
triggerJob
(
jobName
,
jobGroup
);
return
ReturnT
.
SUCCESS
;
return
ReturnT
.
SUCCESS
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
xxl-job-admin/src/main/java/com/xxl/job/controller/JobLogController.java
浏览文件 @
554429ea
...
@@ -33,7 +33,9 @@ public class JobLogController {
...
@@ -33,7 +33,9 @@ public class JobLogController {
public
IXxlJobLogDao
xxlJobLogDao
;
public
IXxlJobLogDao
xxlJobLogDao
;
@RequestMapping
@RequestMapping
public
String
index
(
Model
model
)
{
public
String
index
(
Model
model
,
String
jobGroup
,
String
jobName
)
{
model
.
addAttribute
(
"jobGroup"
,
jobGroup
);
model
.
addAttribute
(
"jobName"
,
jobName
);
model
.
addAttribute
(
"JobGroupList"
,
JobGroupEnum
.
values
());
model
.
addAttribute
(
"JobGroupList"
,
JobGroupEnum
.
values
());
return
"joblog/index"
;
return
"joblog/index"
;
}
}
...
@@ -71,8 +73,8 @@ public class JobLogController {
...
@@ -71,8 +73,8 @@ public class JobLogController {
@RequestMapping
(
"/save"
)
@RequestMapping
(
"/save"
)
@ResponseBody
@ResponseBody
public
ReturnT
<
String
>
triggerLog
(
int
trigger
LogI
d
,
String
status
,
String
msg
)
{
public
ReturnT
<
String
>
triggerLog
(
int
trigger
_log_i
d
,
String
status
,
String
msg
)
{
XxlJobLog
log
=
xxlJobLogDao
.
load
(
trigger
LogI
d
);
XxlJobLog
log
=
xxlJobLogDao
.
load
(
trigger
_log_i
d
);
if
(
log
!=
null
)
{
if
(
log
!=
null
)
{
log
.
setHandleTime
(
new
Date
());
log
.
setHandleTime
(
new
Date
());
log
.
setHandleStatus
(
status
);
log
.
setHandleStatus
(
status
);
...
...
xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobInfo.java
浏览文件 @
554429ea
...
@@ -10,21 +10,22 @@ public class XxlJobInfo {
...
@@ -10,21 +10,22 @@ public class XxlJobInfo {
private
int
id
;
private
int
id
;
private
String
jobGroup
;
// base on quartz 任务组
private
String
jobGroup
;
// 任务组
private
String
jobName
;
// base on quartz 任务名
private
String
jobName
;
// 任务名
private
String
jobCron
;
// base on quartz 任务执行CRON表达式
private
String
jobCron
;
// 任务执行CRON表达式 【base on quartz】
private
String
jobClass
;
// base on quartz 任务执行JobBean
private
String
jobDesc
;
private
String
jobData
;
// base on db, Map-JSON-String 任务执行数据
private
String
jobClass
;
// 任务执行JobBean 【base on quartz】
private
String
jobData
;
// 任务执行数据 Map-JSON-String
private
Date
addTime
;
private
Date
addTime
;
private
Date
updateTime
;
private
Date
updateTime
;
private
String
author
;
//
作者
private
String
author
;
//
负责人
private
String
alarmEmail
;
// 报警邮件
private
String
alarmEmail
;
// 报警邮件
private
int
alarmThreshold
;
// 报警阀值
private
int
alarmThreshold
;
// 报警阀值
// copy from quartz
// copy from quartz
private
String
jobStatus
;
// 任务状态
private
String
jobStatus
;
// 任务状态
【base on quartz】
public
int
getId
()
{
public
int
getId
()
{
return
id
;
return
id
;
...
@@ -58,6 +59,14 @@ public class XxlJobInfo {
...
@@ -58,6 +59,14 @@ public class XxlJobInfo {
this
.
jobCron
=
jobCron
;
this
.
jobCron
=
jobCron
;
}
}
public
String
getJobDesc
()
{
return
jobDesc
;
}
public
void
setJobDesc
(
String
jobDesc
)
{
this
.
jobDesc
=
jobDesc
;
}
public
String
getJobClass
()
{
public
String
getJobClass
()
{
return
jobClass
;
return
jobClass
;
}
}
...
@@ -125,9 +134,9 @@ public class XxlJobInfo {
...
@@ -125,9 +134,9 @@ public class XxlJobInfo {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"XxlJobInfo [id="
+
id
+
", jobGroup="
+
jobGroup
+
", jobName="
+
jobName
+
", jobCron="
+
jobCron
return
"XxlJobInfo [id="
+
id
+
", jobGroup="
+
jobGroup
+
", jobName="
+
jobName
+
", jobCron="
+
jobCron
+
", job
Class="
+
jobClass
+
", jobData="
+
jobData
+
", addTime="
+
addTime
+
", updateTime="
+
", job
Desc="
+
jobDesc
+
", jobClass="
+
jobClass
+
", jobData="
+
jobData
+
", addTime="
+
addTime
+
updateTime
+
", author="
+
author
+
", alarmEmail="
+
alarmEmail
+
", alarmThreshold="
+
", updateTime="
+
updateTime
+
", author="
+
author
+
", alarmEmail="
+
alarmEmail
+
alarmThreshold
+
", jobStatus="
+
jobStatus
+
"]"
;
+
", alarmThreshold="
+
alarmThreshold
+
", jobStatus="
+
jobStatus
+
"]"
;
}
}
}
}
xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLog.java
浏览文件 @
554429ea
...
@@ -14,6 +14,7 @@ public class XxlJobLog {
...
@@ -14,6 +14,7 @@ public class XxlJobLog {
private
String
jobGroup
;
private
String
jobGroup
;
private
String
jobName
;
private
String
jobName
;
private
String
jobCron
;
private
String
jobCron
;
private
String
jobDesc
;
private
String
jobClass
;
private
String
jobClass
;
private
String
jobData
;
private
String
jobData
;
...
@@ -26,7 +27,6 @@ public class XxlJobLog {
...
@@ -26,7 +27,6 @@ public class XxlJobLog {
private
Date
handleTime
;
private
Date
handleTime
;
private
String
handleStatus
;
private
String
handleStatus
;
private
String
handleMsg
;
private
String
handleMsg
;
public
int
getId
()
{
public
int
getId
()
{
return
id
;
return
id
;
}
}
...
@@ -51,6 +51,12 @@ public class XxlJobLog {
...
@@ -51,6 +51,12 @@ public class XxlJobLog {
public
void
setJobCron
(
String
jobCron
)
{
public
void
setJobCron
(
String
jobCron
)
{
this
.
jobCron
=
jobCron
;
this
.
jobCron
=
jobCron
;
}
}
public
String
getJobDesc
()
{
return
jobDesc
;
}
public
void
setJobDesc
(
String
jobDesc
)
{
this
.
jobDesc
=
jobDesc
;
}
public
String
getJobClass
()
{
public
String
getJobClass
()
{
return
jobClass
;
return
jobClass
;
}
}
...
@@ -103,9 +109,9 @@ public class XxlJobLog {
...
@@ -103,9 +109,9 @@ public class XxlJobLog {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"XxlJobLog [id="
+
id
+
", jobGroup="
+
jobGroup
+
", jobName="
+
jobName
+
", jobCron="
+
jobCron
return
"XxlJobLog [id="
+
id
+
", jobGroup="
+
jobGroup
+
", jobName="
+
jobName
+
", jobCron="
+
jobCron
+
", job
Class="
+
jobClass
+
", jobData="
+
jobData
+
", triggerTime="
+
triggerTime
+
", job
Desc="
+
jobDesc
+
", jobClass="
+
jobClass
+
", jobData="
+
jobData
+
", triggerTime="
+
", triggerStatus="
+
triggerStatus
+
", triggerMsg="
+
triggerMsg
+
", handleTime="
+
handleTime
+
triggerTime
+
", triggerStatus="
+
triggerStatus
+
", triggerMsg="
+
triggerMsg
+
", handleTime="
+
", handleStatus="
+
handleStatus
+
", handleMsg="
+
handleMsg
+
"]"
;
+
handleTime
+
", handleStatus="
+
handleStatus
+
", handleMsg="
+
handleMsg
+
"]"
;
}
}
}
}
xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java
浏览文件 @
554429ea
...
@@ -3,6 +3,7 @@ package com.xxl.job.core.util;
...
@@ -3,6 +3,7 @@ package com.xxl.job.core.util;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory;
...
@@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
com.xxl.job.client.util.JacksonUtil
;
import
com.xxl.job.core.model.XxlJobInfo
;
import
com.xxl.job.core.model.XxlJobInfo
;
import
com.xxl.job.dao.IXxlJobInfoDao
;
import
com.xxl.job.dao.IXxlJobInfoDao
;
import
com.xxl.job.dao.IXxlJobLogDao
;
import
com.xxl.job.dao.IXxlJobLogDao
;
...
@@ -124,29 +126,42 @@ public final class DynamicSchedulerUtil implements InitializingBean {
...
@@ -124,29 +126,42 @@ public final class DynamicSchedulerUtil implements InitializingBean {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
// check if exists
public
static
boolean
checkExists
(
String
jobName
,
String
jobGroup
)
throws
SchedulerException
{
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
,
jobGroup
);
return
scheduler
.
checkExists
(
triggerKey
);
}
// addJob 新增
// addJob 新增
public
static
boolean
addJob
(
String
triggerKeyName
,
String
cronExpression
,
Class
<?
extends
Job
>
jobClass
,
Map
<
String
,
Object
>
jobData
)
throws
SchedulerException
{
@SuppressWarnings
(
"unchecked"
)
public
static
boolean
addJob
(
XxlJobInfo
jobInfo
)
throws
SchedulerException
{
// TriggerKey : name + group
// TriggerKey : name + group
String
group
=
Scheduler
.
DEFAULT_GROUP
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobInfo
.
getJobName
(),
jobInfo
.
getJobGroup
())
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
triggerKeyName
,
group
);
JobKey
jobKey
=
new
JobKey
(
jobInfo
.
getJobName
(),
jobInfo
.
getJobGroup
()
);
// TriggerKey valid if_exists
// TriggerKey valid if_exists
if
(
scheduler
.
checkExists
(
triggerKey
))
{
if
(
checkExists
(
jobInfo
.
getJobName
(),
jobInfo
.
getJobGroup
()))
{
Trigger
trigger
=
scheduler
.
getTrigger
(
triggerKey
);
logger
.
info
(
">>>>>>>>> addJob fail, job already exist, jobInfo:{}"
,
jobInfo
);
logger
.
info
(
">>>>>>>>> Already exist trigger ["
+
trigger
+
"] by key ["
+
triggerKey
+
"] in Scheduler"
);
return
false
;
return
false
;
}
}
// CronTrigger : TriggerKey + cronExpression // withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度
// CronTrigger : TriggerKey + cronExpression // withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度
CronScheduleBuilder
cronScheduleBuilder
=
CronScheduleBuilder
.
cronSchedule
(
cronExpression
).
withMisfireHandlingInstructionDoNothing
();
CronScheduleBuilder
cronScheduleBuilder
=
CronScheduleBuilder
.
cronSchedule
(
jobInfo
.
getJobCron
()
).
withMisfireHandlingInstructionDoNothing
();
CronTrigger
cronTrigger
=
TriggerBuilder
.
newTrigger
().
withIdentity
(
triggerKey
).
withSchedule
(
cronScheduleBuilder
).
build
();
CronTrigger
cronTrigger
=
TriggerBuilder
.
newTrigger
().
withIdentity
(
triggerKey
).
withSchedule
(
cronScheduleBuilder
).
build
();
// JobDetail : jobClass
// JobDetail : jobClass
JobDetail
jobDetail
=
JobBuilder
.
newJob
(
jobClass
).
withIdentity
(
triggerKeyName
,
group
).
build
();
Class
<?
extends
Job
>
jobClass_
=
null
;
if
(
jobData
!=
null
&&
jobData
.
size
()
>
0
)
{
try
{
jobClass_
=
(
Class
<?
extends
Job
>)
Class
.
forName
(
jobInfo
.
getJobClass
());
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
JobDetail
jobDetail
=
JobBuilder
.
newJob
(
jobClass_
).
withIdentity
(
jobKey
).
build
();
if
(
jobInfo
.
getJobData
()!=
null
)
{
JobDataMap
jobDataMap
=
jobDetail
.
getJobDataMap
();
JobDataMap
jobDataMap
=
jobDetail
.
getJobDataMap
();
jobDataMap
.
putAll
(
jobData
);
// JobExecutionContext context.getMergedJobDataMap().get("mailGuid");
jobDataMap
.
putAll
(
JacksonUtil
.
readValue
(
jobInfo
.
getJobData
(),
Map
.
class
)
);
// JobExecutionContext context.getMergedJobDataMap().get("mailGuid");
}
}
// schedule : jobDetail + cronTrigger
// schedule : jobDetail + cronTrigger
...
@@ -156,49 +171,60 @@ public final class DynamicSchedulerUtil implements InitializingBean {
...
@@ -156,49 +171,60 @@ public final class DynamicSchedulerUtil implements InitializingBean {
return
true
;
return
true
;
}
}
// reschedule 重置cron
// reschedule
public
static
boolean
rescheduleJob
(
String
triggerKeyName
,
String
cronExpression
)
throws
SchedulerException
{
@SuppressWarnings
(
"unchecked"
)
public
static
boolean
rescheduleJob
(
XxlJobInfo
jobInfo
)
throws
SchedulerException
{
// TriggerKey valid if_exists
if
(!
checkExists
(
jobInfo
.
getJobName
(),
jobInfo
.
getJobGroup
()))
{
logger
.
info
(
">>>>>>>>>>> rescheduleJob fail, job not exists, jobInfo:{}"
,
jobInfo
);
return
false
;
}
// TriggerKey : name + group
// TriggerKey : name + group
String
group
=
Scheduler
.
DEFAULT_GROUP
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobInfo
.
getJobName
(),
jobInfo
.
getJobGroup
())
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
triggerKeyName
,
group
);
JobKey
jobKey
=
new
JobKey
(
jobInfo
.
getJobName
(),
jobInfo
.
getJobGroup
()
);
boolean
result
=
false
;
// CronTrigger : TriggerKey + cronExpression
if
(
scheduler
.
checkExists
(
triggerKey
))
{
CronScheduleBuilder
cronScheduleBuilder
=
CronScheduleBuilder
.
cronSchedule
(
jobInfo
.
getJobCron
()).
withMisfireHandlingInstructionDoNothing
();
// CronTrigger : TriggerKey + cronExpression
CronTrigger
cronTrigger
=
TriggerBuilder
.
newTrigger
().
withIdentity
(
triggerKey
).
withSchedule
(
cronScheduleBuilder
).
build
();
CronScheduleBuilder
cronScheduleBuilder
=
CronScheduleBuilder
.
cronSchedule
(
cronExpression
).
withMisfireHandlingInstructionDoNothing
();
CronTrigger
cronTrigger
=
TriggerBuilder
.
newTrigger
().
withIdentity
(
triggerKey
).
withSchedule
(
cronScheduleBuilder
).
build
();
//scheduler.rescheduleJob(triggerKey, cronTrigger);
Date
date
=
scheduler
.
rescheduleJob
(
triggerKey
,
cronTrigger
);
// JobDetail-JobDataMap fresh
result
=
true
;
JobDetail
jobDetail
=
scheduler
.
getJobDetail
(
jobKey
);
logger
.
info
(
">>>>>>>>>>> resumeJob success, triggerKey:{}, cronExpression:{}, date:{}"
,
triggerKey
,
cronExpression
,
date
);
JobDataMap
jobDataMap
=
jobDetail
.
getJobDataMap
();
}
else
{
jobDataMap
.
clear
();
logger
.
info
(
">>>>>>>>>>> resumeJob fail, triggerKey:{}, cronExpression:{}"
,
triggerKey
,
cronExpression
);
jobDataMap
.
putAll
(
JacksonUtil
.
readValue
(
jobInfo
.
getJobData
(),
Map
.
class
));
}
return
result
;
// Trigger fresh
HashSet
<
Trigger
>
triggerSet
=
new
HashSet
<
Trigger
>();
triggerSet
.
add
(
cronTrigger
);
scheduler
.
scheduleJob
(
jobDetail
,
triggerSet
,
true
);
logger
.
info
(
">>>>>>>>>>> resumeJob success, jobInfo:{}"
,
jobInfo
);
return
true
;
}
}
// unscheduleJob
删除
// unscheduleJob
public
static
boolean
removeJob
(
String
triggerKeyName
)
throws
SchedulerException
{
public
static
boolean
removeJob
(
String
jobName
,
String
jobGroup
)
throws
SchedulerException
{
// TriggerKey : name + group
// TriggerKey : name + group
String
group
=
Scheduler
.
DEFAULT_GROUP
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
,
jobGroup
);
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
triggerKeyName
,
group
);
boolean
result
=
false
;
boolean
result
=
false
;
if
(
scheduler
.
checkExists
(
triggerKey
))
{
if
(
checkExists
(
jobName
,
jobGroup
))
{
result
=
scheduler
.
unscheduleJob
(
triggerKey
);
result
=
scheduler
.
unscheduleJob
(
triggerKey
);
logger
.
info
(
">>>>>>>>>>> removeJob, triggerKey:{}, result [{}]"
,
triggerKey
,
result
);
}
}
logger
.
info
(
">>>>>>>>>>> removeJob, triggerKey:{}, result [{}]"
,
triggerKey
,
result
);
return
true
;
return
result
;
}
}
// Pause
暂停
// Pause
public
static
boolean
pauseJob
(
String
triggerKeyName
)
throws
SchedulerException
{
public
static
boolean
pauseJob
(
String
jobName
,
String
jobGroup
)
throws
SchedulerException
{
// TriggerKey : name + group
// TriggerKey : name + group
String
group
=
Scheduler
.
DEFAULT_GROUP
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
,
jobGroup
);
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
triggerKeyName
,
group
);
boolean
result
=
false
;
boolean
result
=
false
;
if
(
scheduler
.
checkExists
(
triggerKey
))
{
if
(
checkExists
(
jobName
,
jobGroup
))
{
scheduler
.
pauseTrigger
(
triggerKey
);
scheduler
.
pauseTrigger
(
triggerKey
);
result
=
true
;
result
=
true
;
logger
.
info
(
">>>>>>>>>>> pauseJob success, triggerKey:{}"
,
triggerKey
);
logger
.
info
(
">>>>>>>>>>> pauseJob success, triggerKey:{}"
,
triggerKey
);
...
@@ -208,14 +234,13 @@ public final class DynamicSchedulerUtil implements InitializingBean {
...
@@ -208,14 +234,13 @@ public final class DynamicSchedulerUtil implements InitializingBean {
return
result
;
return
result
;
}
}
// resume 重启
// resume
public
static
boolean
resumeJob
(
String
triggerKeyName
)
throws
SchedulerException
{
public
static
boolean
resumeJob
(
String
jobName
,
String
jobGroup
)
throws
SchedulerException
{
// TriggerKey : name + group
// TriggerKey : name + group
String
group
=
Scheduler
.
DEFAULT_GROUP
;
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
,
jobGroup
);
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
triggerKeyName
,
group
);
boolean
result
=
false
;
boolean
result
=
false
;
if
(
scheduler
.
checkExists
(
triggerKey
))
{
if
(
checkExists
(
jobName
,
jobGroup
))
{
scheduler
.
resumeTrigger
(
triggerKey
);
scheduler
.
resumeTrigger
(
triggerKey
);
result
=
true
;
result
=
true
;
logger
.
info
(
">>>>>>>>>>> resumeJob success, triggerKey:{}"
,
triggerKey
);
logger
.
info
(
">>>>>>>>>>> resumeJob success, triggerKey:{}"
,
triggerKey
);
...
@@ -225,14 +250,13 @@ public final class DynamicSchedulerUtil implements InitializingBean {
...
@@ -225,14 +250,13 @@ public final class DynamicSchedulerUtil implements InitializingBean {
return
result
;
return
result
;
}
}
// run 执行一次
// run
public
static
boolean
triggerJob
(
String
triggerKeyName
)
throws
SchedulerException
{
public
static
boolean
triggerJob
(
String
jobName
,
String
jobGroup
)
throws
SchedulerException
{
// TriggerKey : name + group
// TriggerKey : name + group
String
group
=
Scheduler
.
DEFAULT_GROUP
;
JobKey
jobKey
=
new
JobKey
(
jobName
,
jobGroup
);
JobKey
jobKey
=
JobKey
.
jobKey
(
triggerKeyName
,
group
);
boolean
result
=
false
;
boolean
result
=
false
;
if
(
scheduler
.
checkExists
(
jobKey
))
{
if
(
checkExists
(
jobName
,
jobGroup
))
{
scheduler
.
triggerJob
(
jobKey
);
scheduler
.
triggerJob
(
jobKey
);
result
=
true
;
result
=
true
;
logger
.
info
(
">>>>>>>>>>> runJob success, jobKey:{}"
,
jobKey
);
logger
.
info
(
">>>>>>>>>>> runJob success, jobKey:{}"
,
jobKey
);
...
...
xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobInfoDao.java
浏览文件 @
554429ea
package
com
.
xxl
.
job
.
dao
;
package
com
.
xxl
.
job
.
dao
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
com.xxl.job.core.model.XxlJobInfo
;
import
com.xxl.job.core.model.XxlJobInfo
;
...
@@ -11,15 +10,15 @@ import com.xxl.job.core.model.XxlJobInfo;
...
@@ -11,15 +10,15 @@ import com.xxl.job.core.model.XxlJobInfo;
*/
*/
public
interface
IXxlJobInfoDao
{
public
interface
IXxlJobInfoDao
{
public
List
<
XxlJobInfo
>
pageList
(
int
offset
,
int
pagesize
,
String
job
Name
,
Date
addTimeStart
,
Date
addTimeEnd
);
public
List
<
XxlJobInfo
>
pageList
(
int
offset
,
int
pagesize
,
String
job
Group
,
String
jobName
);
public
int
pageListCount
(
int
offset
,
int
pagesize
,
String
job
Name
,
Date
addTimeStart
,
Date
addTimeEnd
);
public
int
pageListCount
(
int
offset
,
int
pagesize
,
String
job
Group
,
String
jobName
);
public
int
save
(
XxlJobInfo
info
);
public
int
save
(
XxlJobInfo
info
);
public
XxlJobInfo
load
(
String
jobName
);
public
XxlJobInfo
load
(
String
job
Group
,
String
job
Name
);
public
int
update
(
XxlJobInfo
item
);
public
int
update
(
XxlJobInfo
item
);
public
int
delete
(
String
jobName
);
public
int
delete
(
String
job
Group
,
String
job
Name
);
}
}
xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobInfoDaoImpl.java
浏览文件 @
554429ea
package
com
.
xxl
.
job
.
dao
.
impl
;
package
com
.
xxl
.
job
.
dao
.
impl
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -23,25 +22,23 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
...
@@ -23,25 +22,23 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
public
SqlSessionTemplate
sqlSessionTemplate
;
public
SqlSessionTemplate
sqlSessionTemplate
;
@Override
@Override
public
List
<
XxlJobInfo
>
pageList
(
int
offset
,
int
pagesize
,
String
job
Name
,
Date
addTimeStart
,
Date
addTimeEnd
)
{
public
List
<
XxlJobInfo
>
pageList
(
int
offset
,
int
pagesize
,
String
job
Group
,
String
jobName
)
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"offset"
,
offset
);
params
.
put
(
"offset"
,
offset
);
params
.
put
(
"pagesize"
,
pagesize
);
params
.
put
(
"pagesize"
,
pagesize
);
params
.
put
(
"jobGroup"
,
jobGroup
);
params
.
put
(
"jobName"
,
jobName
);
params
.
put
(
"jobName"
,
jobName
);
params
.
put
(
"addTimeStart"
,
addTimeStart
);
params
.
put
(
"addTimeEnd"
,
addTimeEnd
);
return
sqlSessionTemplate
.
selectList
(
"XxlJobInfoMapper.pageList"
,
params
);
return
sqlSessionTemplate
.
selectList
(
"XxlJobInfoMapper.pageList"
,
params
);
}
}
@Override
@Override
public
int
pageListCount
(
int
offset
,
int
pagesize
,
String
job
Name
,
Date
addTimeStart
,
Date
addTimeEnd
)
{
public
int
pageListCount
(
int
offset
,
int
pagesize
,
String
job
Group
,
String
jobName
)
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"offset"
,
offset
);
params
.
put
(
"offset"
,
offset
);
params
.
put
(
"pagesize"
,
pagesize
);
params
.
put
(
"pagesize"
,
pagesize
);
params
.
put
(
"jobGroup"
,
jobGroup
);
params
.
put
(
"jobName"
,
jobName
);
params
.
put
(
"jobName"
,
jobName
);
params
.
put
(
"addTimeStart"
,
addTimeStart
);
params
.
put
(
"addTimeEnd"
,
addTimeEnd
);
return
sqlSessionTemplate
.
selectOne
(
"XxlJobInfoMapper.pageListCount"
,
params
);
return
sqlSessionTemplate
.
selectOne
(
"XxlJobInfoMapper.pageListCount"
,
params
);
}
}
...
@@ -52,8 +49,12 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
...
@@ -52,8 +49,12 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
}
}
@Override
@Override
public
XxlJobInfo
load
(
String
jobName
)
{
public
XxlJobInfo
load
(
String
jobGroup
,
String
jobName
)
{
return
sqlSessionTemplate
.
selectOne
(
"XxlJobInfoMapper.load"
,
jobName
);
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"jobGroup"
,
jobGroup
);
params
.
put
(
"jobName"
,
jobName
);
return
sqlSessionTemplate
.
selectOne
(
"XxlJobInfoMapper.load"
,
params
);
}
}
@Override
@Override
...
@@ -62,8 +63,12 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
...
@@ -62,8 +63,12 @@ public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
}
}
@Override
@Override
public
int
delete
(
String
jobName
)
{
public
int
delete
(
String
jobGroup
,
String
jobName
)
{
return
sqlSessionTemplate
.
update
(
"XxlJobInfoMapper.delete"
,
jobName
);
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"jobGroup"
,
jobGroup
);
params
.
put
(
"jobName"
,
jobName
);
return
sqlSessionTemplate
.
update
(
"XxlJobInfoMapper.delete"
,
params
);
}
}
}
}
xxl-job-admin/src/main/java/com/xxl/job/service/job/HttpJobBean.java
浏览文件 @
554429ea
...
@@ -5,9 +5,10 @@ import java.util.HashMap;
...
@@ -5,9 +5,10 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.Map
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.quartz.DisallowConcurrentExecution
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionException
;
import
org.quartz.JobExecutionException
;
import
org.quartz.
impl.triggers.CronTriggerImpl
;
import
org.quartz.
JobKey
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
...
@@ -22,44 +23,43 @@ import com.xxl.job.core.util.PropertiesUtil;
...
@@ -22,44 +23,43 @@ import com.xxl.job.core.util.PropertiesUtil;
/**
/**
* http job bean
* http job bean
* “@DisallowConcurrentExecution” diable concurrent, thread size can not be only one, better given more
* @author xuxueli 2015-12-17 18:20:34
* @author xuxueli 2015-12-17 18:20:34
*/
*/
@DisallowConcurrentExecution
public
class
HttpJobBean
extends
QuartzJobBean
{
public
class
HttpJobBean
extends
QuartzJobBean
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpJobBean
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpJobBean
.
class
);
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Override
@Override
protected
void
executeInternal
(
JobExecutionContext
context
)
protected
void
executeInternal
(
JobExecutionContext
context
)
throws
JobExecutionException
{
throws
JobExecutionException
{
String
triggerKey
=
context
.
getTrigger
().
getJobKey
().
getName
();
JobKey
jobKey
=
context
.
getTrigger
().
getJobKey
();
// jobDataMap 2 params
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
XxlJobInfo
jobInfo
=
DynamicSchedulerUtil
.
xxlJobInfoDao
.
load
(
triggerKey
);
if
(
jobInfo
!=
null
&&
jobInfo
.
getJobData
()!=
null
)
{
params
=
JacksonUtil
.
readValue
(
jobInfo
.
getJobData
(),
Map
.
class
);
}
// corn
String
cornExp
=
null
;
if
(
context
.
getTrigger
()
instanceof
CronTriggerImpl
)
{
CronTriggerImpl
trigger
=
(
CronTriggerImpl
)
context
.
getTrigger
();
cornExp
=
trigger
.
getCronExpression
();
}
XxlJobInfo
jobInfo
=
DynamicSchedulerUtil
.
xxlJobInfoDao
.
load
(
jobKey
.
getGroup
(),
jobKey
.
getName
());
HashMap
<
String
,
String
>
jobDataMap
=
(
HashMap
<
String
,
String
>)
JacksonUtil
.
readValueRefer
(
jobInfo
.
getJobData
(),
Map
.
class
);
// save log
// save log
XxlJobLog
jobLog
=
new
XxlJobLog
();
XxlJobLog
jobLog
=
new
XxlJobLog
();
jobLog
.
setJobName
(
triggerKey
);
jobLog
.
setJobGroup
(
jobInfo
.
getJobGroup
());
jobLog
.
setJobCron
(
cornExp
);
jobLog
.
setJobName
(
jobInfo
.
getJobName
());
jobLog
.
setJobCron
(
jobInfo
.
getJobCron
());
jobLog
.
setJobDesc
(
jobInfo
.
getJobDesc
());
jobLog
.
setJobClass
(
jobInfo
.
getJobClass
());
jobLog
.
setJobData
(
jobInfo
.
getJobData
());
jobLog
.
setJobClass
(
HttpJobBean
.
class
.
getName
());
jobLog
.
setJobClass
(
HttpJobBean
.
class
.
getName
());
jobLog
.
setJobData
(
jobInfo
.
getJobData
());
jobLog
.
setJobData
(
jobInfo
.
getJobData
());
DynamicSchedulerUtil
.
xxlJobLogDao
.
save
(
jobLog
);
DynamicSchedulerUtil
.
xxlJobLogDao
.
save
(
jobLog
);
logger
.
info
(
">>>>>>>>>>> xxl-job trigger start, jobLog:{}"
,
jobLog
);
logger
.
info
(
">>>>>>>>>>> xxl-job trigger start, jobLog:{}"
,
jobLog
);
// trigger request
// trigger request
params
.
put
(
HandlerRepository
.
triggerLogId
,
String
.
valueOf
(
jobLog
.
getId
()));
HashMap
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
HandlerRepository
.
triggerLogUrl
,
PropertiesUtil
.
getString
(
HandlerRepository
.
triggerLogUrl
));
params
.
put
(
HandlerRepository
.
TRIGGER_LOG_URL
,
PropertiesUtil
.
getString
(
HandlerRepository
.
TRIGGER_LOG_URL
));
String
[]
postResp
=
HttpUtil
.
post
(
params
.
get
(
HandlerRepository
.
job_url
),
params
);
params
.
put
(
HandlerRepository
.
TRIGGER_LOG_ID
,
String
.
valueOf
(
jobLog
.
getId
()));
params
.
put
(
HandlerRepository
.
HANDLER_NAME
,
jobDataMap
.
get
(
HandlerRepository
.
HANDLER_NAME
));
params
.
put
(
HandlerRepository
.
HANDLER_PARAMS
,
jobDataMap
.
get
(
HandlerRepository
.
HANDLER_PARAMS
));
String
[]
postResp
=
HttpUtil
.
post
(
jobDataMap
.
get
(
HandlerRepository
.
HANDLER_ADDRESS
),
params
);
logger
.
info
(
">>>>>>>>>>> xxl-job trigger http response, jobLog.id:{}, jobLog:{}"
,
jobLog
.
getId
(),
jobLog
);
logger
.
info
(
">>>>>>>>>>> xxl-job trigger http response, jobLog.id:{}, jobLog:{}"
,
jobLog
.
getId
(),
jobLog
);
// parse trigger response
// parse trigger response
...
...
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml
浏览文件 @
554429ea
...
@@ -6,37 +6,45 @@
...
@@ -6,37 +6,45 @@
<resultMap
id=
"XxlJobInfo"
type=
"com.xxl.job.core.model.XxlJobInfo"
>
<resultMap
id=
"XxlJobInfo"
type=
"com.xxl.job.core.model.XxlJobInfo"
>
<result
column=
"id"
property=
"id"
/>
<result
column=
"id"
property=
"id"
/>
<result
column=
"job_group"
property=
"jobGroup"
/>
<result
column=
"job_name"
property=
"jobName"
/>
<result
column=
"job_name"
property=
"jobName"
/>
<result
column=
"job_cron"
property=
"jobCron"
/>
<result
column=
"job_cron"
property=
"jobCron"
/>
<result
column=
"job_desc"
property=
"jobDesc"
/>
<result
column=
"job_class"
property=
"jobClass"
/>
<result
column=
"job_class"
property=
"jobClass"
/>
<result
column=
"job_data"
property=
"jobData"
/>
<result
column=
"job_data"
property=
"jobData"
/>
<result
column=
"add_time"
property=
"addTime"
/>
<result
column=
"add_time"
property=
"addTime"
/>
<result
column=
"update_time"
property=
"updateTime"
/>
<result
column=
"update_time"
property=
"updateTime"
/>
<result
column=
"author"
property=
"author"
/>
<result
column=
"alarm_email"
property=
"alarmEmail"
/>
<result
column=
"alarm_threshold"
property=
"alarmThreshold"
/>
</resultMap>
</resultMap>
<sql
id=
"Base_Column_List"
>
<sql
id=
"Base_Column_List"
>
t.id,
t.id,
t.job_group,
t.job_name,
t.job_name,
t.job_cron,
t.job_cron,
t.job_desc,
t.job_class,
t.job_class,
t.job_data,
t.job_data,
t.add_time,
t.add_time,
t.update_time
t.update_time,
t.author,
t.alarm_email,
t.alarm_threshold
</sql>
</sql>
<select
id=
"pageList"
parameterType=
"java.util.HashMap"
resultMap=
"XxlJobInfo"
>
<select
id=
"pageList"
parameterType=
"java.util.HashMap"
resultMap=
"XxlJobInfo"
>
SELECT
<include
refid=
"Base_Column_List"
/>
SELECT
<include
refid=
"Base_Column_List"
/>
FROM xxl_job_qrtz_trigger_info AS t
FROM xxl_job_qrtz_trigger_info AS t
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<if
test=
"jobName != null and jobName!=''"
>
<if
test=
"jobGroup != null and jobGroup != ''"
>
AND t.job_name = #{jobName}
AND t.job_group = #{jobGroup}
</if>
<if
test=
"addTimeStart != null"
>
AND t.add_time
<![CDATA[ > ]]>
#{addTimeStart}
</if>
</if>
<if
test=
"
addTimeEnd != null
"
>
<if
test=
"
jobName != null and jobName != ''
"
>
AND t.
add_time
<![CDATA[ < ]]>
#{addTimeEnd}
AND t.
job_name like CONCAT(CONCAT('%', #{jobName}), '%')
</if>
</if>
</trim>
</trim>
ORDER BY id DESC
ORDER BY id DESC
...
@@ -47,56 +55,74 @@
...
@@ -47,56 +55,74 @@
SELECT count(1)
SELECT count(1)
FROM xxl_job_qrtz_trigger_info AS t
FROM xxl_job_qrtz_trigger_info AS t
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<if
test=
"job
Name != null and jobName!=
''"
>
<if
test=
"job
Group != null and jobGroup !=
''"
>
AND t.job_
name = #{jobName
}
AND t.job_
group = #{jobGroup
}
</if>
</if>
<if
test=
"addTimeStart != null"
>
<if
test=
"jobName != null and jobName != ''"
>
AND t.add_time
<![CDATA[ > ]]>
#{addTimeStart}
AND t.job_name like CONCAT(CONCAT('%', #{jobName}), '%')
</if>
<if
test=
"addTimeEnd != null"
>
AND t.add_time
<![CDATA[ < ]]>
#{addTimeEnd}
</if>
</if>
</trim>
</trim>
</select>
</select>
<insert
id=
"save"
parameterType=
"com.xxl.job.core.model.XxlJobInfo"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
<insert
id=
"save"
parameterType=
"com.xxl.job.core.model.XxlJobInfo"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
INSERT INTO `xxl_job_qrtz_trigger_info` (
INSERT INTO `xxl_job_qrtz_trigger_info` (
`job_name`,
job_group,
`job_cron`,
job_name,
`job_class`,
job_cron,
`job_data`,
job_desc,
`add_time`,
job_class,
`update_time`
job_data,
add_time,
update_time,
author,
alarm_email,
alarm_threshold
) VALUES (
) VALUES (
#{jobGroup},
#{jobName},
#{jobName},
#{jobCron},
#{jobCron},
#{jobDesc},
#{jobClass},
#{jobClass},
#{jobData},
#{jobData},
NOW(),
NOW(),
NOW()
NOW(),
#{author},
#{alarmEmail},
#{alarmThreshold}
);
);
<selectKey
resultType=
"java.lang.Integer"
order=
"AFTER"
keyProperty=
"id"
>
<selectKey
resultType=
"java.lang.Integer"
order=
"AFTER"
keyProperty=
"id"
>
SELECT LAST_INSERT_ID()
SELECT LAST_INSERT_ID()
</selectKey>
</selectKey>
</insert>
</insert>
<select
id=
"load"
parameterType=
"java.
lang.String
"
resultMap=
"XxlJobInfo"
>
<select
id=
"load"
parameterType=
"java.
util.HashMap
"
resultMap=
"XxlJobInfo"
>
SELECT
<include
refid=
"Base_Column_List"
/>
SELECT
<include
refid=
"Base_Column_List"
/>
FROM xxl_job_qrtz_trigger_info AS t
FROM xxl_job_qrtz_trigger_info AS t
WHERE t.job_name = #{jobName}
WHERE t.job_group = #{jobGroup}
AND t.job_name = #{jobName}
</select>
</select>
<update
id=
"update"
>
<update
id=
"update"
parameterType=
"com.xxl.job.core.model.XxlJobInfo"
>
UPDATE `xxl_job_qrtz_trigger_info`
UPDATE `xxl_job_qrtz_trigger_info`
SET `job_cron`= #{jobCron},
SET
`job_data`= #{jobData},
job_cron = #{jobCron},
`update_time`= NOW()
job_desc = #{jobDesc},
WHERE `id`= #{id}
job_data = #{jobData},
update_time = NOW(),
author = #{author},
alarm_email = #{alarmEmail},
alarm_threshold = #{alarmThreshold}
WHERE job_group = #{jobGroup}
AND job_name = #{jobName}
</update>
</update>
<delete
id=
"delete"
parameterType=
"java.lang.String"
>
<delete
id=
"delete"
parameterType=
"java.lang.String"
>
delete from xxl_job_qrtz_trigger_info
DELETE
where job_name = #{jobName}
FROM
xxl_job_qrtz_trigger_info
WHERE
job_group = #{jobGroup}
AND job_name = #{jobName}
</delete>
</delete>
</mapper>
</mapper>
\ No newline at end of file
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml
浏览文件 @
554429ea
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
<result
column=
"job_group"
property=
"jobGroup"
/>
<result
column=
"job_group"
property=
"jobGroup"
/>
<result
column=
"job_name"
property=
"jobName"
/>
<result
column=
"job_name"
property=
"jobName"
/>
<result
column=
"job_cron"
property=
"jobCron"
/>
<result
column=
"job_cron"
property=
"jobCron"
/>
<result
column=
"job_desc"
property=
"jobDesc"
/>
<result
column=
"job_class"
property=
"jobClass"
/>
<result
column=
"job_class"
property=
"jobClass"
/>
<result
column=
"job_data"
property=
"jobData"
/>
<result
column=
"job_data"
property=
"jobData"
/>
...
@@ -26,8 +27,9 @@
...
@@ -26,8 +27,9 @@
t.job_group,
t.job_group,
t.job_name,
t.job_name,
t.job_cron,
t.job_cron,
t.job_desc,
t.job_class,
t.job_class,
t.job_d
ata
,
t.job_d
esc
,
t.trigger_time,
t.trigger_time,
t.trigger_status,
t.trigger_status,
t.trigger_msg,
t.trigger_msg,
...
@@ -94,12 +96,14 @@
...
@@ -94,12 +96,14 @@
`job_group`,
`job_group`,
`job_name`,
`job_name`,
`job_cron`,
`job_cron`,
`job_desc`,
`job_class`,
`job_class`,
`job_data`
`job_data`
) VALUES (
) VALUES (
#{jobGroup},
#{jobGroup},
#{jobName},
#{jobName},
#{jobCron},
#{jobCron},
#{jobDesc},
#{jobClass},
#{jobClass},
#{jobData}
#{jobData}
);
);
...
...
xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/index.ftl
浏览文件 @
554429ea
...
@@ -42,9 +42,7 @@
...
@@ -42,9 +42,7 @@
</div>
</div>
<div
class=
"col-xs-4"
>
<div
class=
"col-xs-4"
>
<div
class=
"input-group"
>
<div
class=
"input-group"
>
<span
class=
"input-group-addon"
>
<span
class=
"input-group-addon"
>
任务名
</span>
jobName
</span>
<input
type=
"text"
class=
"form-control"
id=
"jobName"
value=
"${jobName}"
autocomplete=
"on"
>
<input
type=
"text"
class=
"form-control"
id=
"jobName"
value=
"${jobName}"
autocomplete=
"on"
>
</div>
</div>
</div>
</div>
...
@@ -66,63 +64,23 @@
...
@@ -66,63 +64,23 @@
<table
id=
"job_list"
class=
"table table-bordered table-striped"
>
<table
id=
"job_list"
class=
"table table-bordered table-striped"
>
<thead>
<thead>
<tr>
<tr>
<th>
id
</th>
<th
name=
"id"
>
id
</th>
<th>
任务Key
</th>
<th
name=
"jobGroup"
>
任务组
</th>
<th>
任务Cron
</th>
<th
name=
"jobName"
>
任务名
</th>
<th>
任务Class
</th>
<th
name=
"jobCron"
>
Cron
</th>
<th>
状态Status
</th>
<th
name=
"jobDesc"
>
描述
</th>
<th>
参数
</th>
<th
name=
"jobClass"
>
JobBean
</th>
<th>
addTime
</th>
<th
name=
"jobData"
>
任务数据
</th>
<th>
updateTime
</th>
<th
name=
"addTime"
>
新增时间
</th>
<th
name=
"updateTime"
>
更新时间
</th>
<th
name=
"author"
>
负责人
</th>
<th
name=
"alarmEmail"
>
报警邮件
</th>
<th
name=
"alarmThreshold"
>
报警阀值
</th>
<th
name=
"jobStatus"
>
状态
</th>
<th>
操作
</th>
<th>
操作
</th>
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody></tbody>
<
#
--
<#
if
jobList
?
exists
&&
jobList
?
size
gt
0
>
<
#
list
jobList
as
item
>
<tr>
<td>
${item['TriggerKey'].name}
</td>
<td>
${item['Trigger'].cronExpression}
</td>
<td>
${item['JobDetail'].jobClass}
</td>
<td>
<
#
assign
jobDataMap =
item['JobDetail'].jobDataMap
/>
<
#
if
jobDataMap
?
exists
&&
jobDataMap
?
keys
?
size
gt
0
>
<
#
list
jobDataMap
?
keys
as
key
>
${key} = ${jobDataMap[key]}
<br>
</
#
list>
</
#
if>
</td>
<td
state=
"${item['TriggerState']}"
>
<
#
if
item
['
TriggerState
']
==
'
NORMAL
'
>
<button
class=
"btn btn-block btn-success"
type=
"button"
>
运行ing
</button>
<
#
elseif
item
['
TriggerState
']
==
'
PAUSED
'
>
<button
class=
"btn btn-block btn-warning"
type=
"button"
>
暂停ing
</button>
<
#
else
>
<button
class=
"btn btn-block"
type=
"button"
>
${item['TriggerState']}
</button>
</
#
if>
</td>
<td>
<p
name=
"${item['TriggerKey'].name}"
group=
"${item['TriggerKey'].group}"
cronExpression=
"${item['Trigger'].cronExpression}"
jobClassName=
"${item['JobDetail'].jobClass}"
jobDesc=
"${job_desc?if_exists}"
>
<
#
if
item
['
TriggerState
']
==
'
NORMAL
'
>
<button
class=
"btn btn-info btn-xs job_operate"
type=
"job_pause"
type=
"button"
>
暂停
</button>
<
#
elseif
item
['
TriggerState
']
==
'
PAUSED
'
>
<button
class=
"btn btn-info btn-xs job_operate"
type=
"job_resume"
type=
"button"
>
恢复
</button>
</
#
if>
<button
class=
"btn btn-info btn-xs job_operate"
type=
"job_trigger"
type=
"button"
>
执行一次
</button>
<button
class=
"btn btn-info btn-xs update"
type=
"button"
>
更新corn
</button>
<button
class=
"btn btn-danger btn-xs job_operate"
type=
"job_del"
type=
"button"
>
删除
</button>
<button
class=
"btn btn-warning btn-xs"
type=
"job_del"
type=
"button"
onclick=
"javascript:window.open('${request.contextPath}/joblog?jobName=${item['TriggerKey'].name}')"
>
查看日志
</button>
</p>
</td>
</tr>
</
#
list>
</
#
if>
-->
</tbody>
<tfoot></tfoot>
<tfoot></tfoot>
</table>
</table>
</div>
</div>
...
@@ -155,29 +113,51 @@
...
@@ -155,29 +113,51 @@
</select>
</select>
</div>
</div>
<label
for=
"firstname"
class=
"col-sm-2 control-label"
>
任务名
</label>
<label
for=
"firstname"
class=
"col-sm-2 control-label"
>
任务名
</label>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"
triggerKeyName"
placeholder=
"请输入任务Key
"
minlength=
"4"
maxlength=
"100"
></div>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"
jobName"
placeholder=
"请输入“任务名”
"
minlength=
"4"
maxlength=
"100"
></div>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"lastname"
class=
"col-sm-3 control-label"
>
任务Corn
</label>
<label
for=
"lastname"
class=
"col-sm-2 control-label"
>
Corn
</label>
<div
class=
"col-sm-9"
><input
type=
"text"
class=
"form-control"
name=
"cronExpression"
placeholder=
"请输入任务Corn"
maxlength=
"100"
></div>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"jobCron"
placeholder=
"请输入“Corn”"
maxlength=
"100"
></div>
<label
for=
"lastname"
class=
"col-sm-2 control-label"
>
描述
</label>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"jobDesc"
placeholder=
"请输入“描述”"
maxlength=
"200"
></div>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"lastname"
class=
"col-sm-3 control-label"
>
任务描述
</label>
<label
for=
"firstname"
class=
"col-sm-2 control-label"
>
JobBean
</label>
<div
class=
"col-sm-9"
><input
type=
"text"
class=
"form-control"
name=
"job_desc"
placeholder=
"请输入任务描述"
maxlength=
"200"
></div>
<div
class=
"col-sm-4"
>
<select
class=
"form-control"
name=
"jobClass"
>
<
#
if
remoteJobBean
?
exists
>
<option
value=
"${remoteJobBean.name}"
jobClassType=
"remote"
>
【远程任务】
</option>
</
#
if>
<
#
if
localJobBeanList
?
exists
&&
localJobBeanList
?
size
gt
0
>
<
#
list
localJobBeanList
as
localJobBean
>
<option
value=
"${localJobBean.name}"
jobClassType=
"local"
>
${localJobBean.name}
</option>
</
#
list>
</
#
if>
</select>
</div>
<label
for=
"firstname"
class=
"col-sm-2 control-label"
>
执行参数
</label>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"handler_params"
placeholder=
"请输入“执行参数”"
maxlength=
"100"
></div>
</div>
<div
class=
"form-group remote_panel"
>
<label
for=
"lastname"
class=
"col-sm-2 control-label"
>
远程-机器地址
</label>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"handler_address"
placeholder=
"请输入“远程-机器地址”"
maxlength=
"200"
></div>
<label
for=
"lastname"
class=
"col-sm-2 control-label"
>
远程-执行器
</label>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"handler_name"
placeholder=
"请输入“远程-执行器”"
maxlength=
"200"
></div>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"lastname"
class=
"col-sm-3 control-label"
>
任务URL
</label>
<label
for=
"lastname"
class=
"col-sm-2 control-label"
>
负责人
</label>
<div
class=
"col-sm-9"
><input
type=
"text"
class=
"form-control"
name=
"job_url"
placeholder=
"请输入任务URL"
maxlength=
"200"
></div>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"author"
placeholder=
"请输入“负责人”"
maxlength=
"200"
></div>
<label
for=
"lastname"
class=
"col-sm-2 control-label"
>
报警邮件
</label>
<div
class=
"col-sm-4"
><input
type=
"text"
class=
"form-control"
name=
"alarm_email"
placeholder=
"请输入“报警邮件”,多个邮件地址逗号分隔"
maxlength=
"200"
></div>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"lastname"
class=
"col-sm-
3 control-label"
>
任务handler
</label>
<label
for=
"lastname"
class=
"col-sm-
2 control-label"
>
报警阈值
</label>
<div
class=
"col-sm-
9"
><input
type=
"text"
class=
"form-control"
name=
"handleName"
placeholder=
"请输入任务handler
"
maxlength=
"200"
></div>
<div
class=
"col-sm-
4"
><input
type=
"text"
class=
"form-control"
name=
"alarm_threshold"
placeholder=
"请输入“报警阈值”
"
maxlength=
"200"
></div>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-3 col-sm-9"
>
<div
class=
"col-sm-offset-3 col-sm-9"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
保存
</button>
<button
type=
"submit"
class=
"btn btn-primary"
>
保存
</button>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
取消
</button>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
取消
</button>
<button
type=
"button"
class=
"btn btn-info pull-right addParam"
>
+ arg
</button>
</div>
</div>
</div>
</div>
</form>
</form>
...
...
xxl-job-admin/src/main/webapp/WEB-INF/template/joblog/index.ftl
浏览文件 @
554429ea
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<span
class=
"input-group-addon"
>
任务组
</span>
<span
class=
"input-group-addon"
>
任务组
</span>
<select
class=
"form-control"
id=
"jobGroup"
>
<select
class=
"form-control"
id=
"jobGroup"
>
<
#
list
JobGroupList
as
group
>
<
#
list
JobGroupList
as
group
>
<option
value=
"${group}"
<#
if
job
Info
?
exists
&&
group =
=
jobInfo
.
jobG
roup
>
selected
</
#
if>
>${group.desc}
</option>
<option
value=
"${group}"
<#
if
job
Group =
=
g
roup
>
selected
</
#
if>
>${group.desc}
</option>
</
#
list>
</
#
list>
</select>
</select>
</div>
</div>
...
@@ -74,6 +74,7 @@
...
@@ -74,6 +74,7 @@
<th
name=
"jobGroup"
>
任务组
</th>
<th
name=
"jobGroup"
>
任务组
</th>
<th
name=
"jobName"
>
任务名
</th>
<th
name=
"jobName"
>
任务名
</th>
<th
name=
"jobCron"
>
Cron
</th>
<th
name=
"jobCron"
>
Cron
</th>
<th
name=
"jobDesc"
>
描述
</th>
<th
name=
"jobClass"
>
JobBean
</th>
<th
name=
"jobClass"
>
JobBean
</th>
<th
name=
"jobData"
>
任务数据
</th>
<th
name=
"jobData"
>
任务数据
</th>
<th
name=
"triggerTime"
>
调度时间
</th>
<th
name=
"triggerTime"
>
调度时间
</th>
...
...
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js
浏览文件 @
554429ea
...
@@ -7,32 +7,68 @@ $(function() {
...
@@ -7,32 +7,68 @@ $(function() {
"ajax"
:
{
"ajax"
:
{
url
:
base_url
+
"/jobinfo/pageList"
,
url
:
base_url
+
"/jobinfo/pageList"
,
data
:
function
(
d
)
{
data
:
function
(
d
)
{
d
.
jobName
=
$
(
'#jobName'
).
val
()
d
.
jobGroup
=
$
(
'#jobGroup'
).
val
();
d
.
jobName
=
$
(
'#jobName'
).
val
();
}
}
},
},
"searching"
:
false
,
"ordering"
:
false
,
//"scrollX": true, // X轴滚动条,取消自适应
//"scrollX": true, // X轴滚动条,取消自适应
"columns"
:
[
"columns"
:
[
{
"data"
:
'id'
,
"bSortable"
:
false
,
"visible"
:
false
},
{
"data"
:
'id'
,
"bSortable"
:
false
,
"visible"
:
false
},
{
"data"
:
'jobName'
,
"bSortable"
:
false
},
{
{
"data"
:
'jobCron'
,
"bSortable"
:
false
,
"visible"
:
true
},
"data"
:
'jobGroup'
,
{
"data"
:
'jobClass'
,
"bSortable"
:
false
,
"visible"
:
false
},
"render"
:
function
(
data
,
type
,
row
)
{
{
"data"
:
'jobStatus'
,
"bSortable"
:
false
,
"visible"
:
true
},
var
groupMenu
=
$
(
"#jobGroup"
).
find
(
"option"
);
{
"data"
:
'jobData'
,
"bSortable"
:
false
,
"visible"
:
true
},
for
(
var
index
in
$
(
"#jobGroup"
).
find
(
"option"
))
{
if
(
$
(
groupMenu
[
index
]).
attr
(
'value'
)
==
data
)
{
return
$
(
groupMenu
[
index
]).
html
();
}
}
return
data
;
}
},
{
"data"
:
'jobName'
},
{
"data"
:
'jobCron'
,
"visible"
:
true
},
{
"data"
:
'jobDesc'
,
"visible"
:
false
},
{
"data"
:
'jobClass'
,
"visible"
:
true
},
{
"data"
:
'jobData'
,
"visible"
:
true
,
"render"
:
function
(
data
,
type
,
row
)
{
return
data
?
'<a class="logTips" href="javascript:;" >查看<span style="display:none;">'
+
data
+
'</span></a>'
:
"无"
;
}
},
{
{
"data"
:
'addTime'
,
"data"
:
'addTime'
,
"
bSortable"
:
false
,
"
visible"
:
false
,
"render"
:
function
(
data
,
type
,
row
)
{
"render"
:
function
(
data
,
type
,
row
)
{
return
data
?
moment
(
new
Date
(
data
)).
format
(
"YYYY-MM-DD HH:mm:ss"
):
""
;
return
data
?
moment
(
new
Date
(
data
)).
format
(
"YYYY-MM-DD HH:mm:ss"
):
""
;
}
}
},
},
{
{
"data"
:
'updateTime'
,
"data"
:
'updateTime'
,
"
bSortable"
:
false
,
"
visible"
:
false
,
"render"
:
function
(
data
,
type
,
row
)
{
"render"
:
function
(
data
,
type
,
row
)
{
return
data
?
moment
(
new
Date
(
data
)).
format
(
"YYYY-MM-DD HH:mm:ss"
):
""
;
return
data
?
moment
(
new
Date
(
data
)).
format
(
"YYYY-MM-DD HH:mm:ss"
):
""
;
}
}
},
},
{
"data"
:
'操作'
,
"bSortable"
:
false
,
{
"data"
:
'author'
,
"visible"
:
true
},
{
"data"
:
'alarmEmail'
,
"visible"
:
false
},
{
"data"
:
'alarmThreshold'
,
"visible"
:
false
},
{
"data"
:
'jobStatus'
,
"visible"
:
true
,
"render"
:
function
(
data
,
type
,
row
)
{
if
(
'NORMAL'
==
data
)
{
return
'<small class="label label-success" ><i class="fa fa-clock-o"></i>'
+
data
+
'</small>'
;
}
else
if
(
'PAUSED'
==
data
){
return
'<small class="label label-default"><i class="fa fa-clock-o"></i>'
+
data
+
'</small>'
;
}
return
data
;
}
},
{
"data"
:
'操作'
,
"render"
:
function
(
data
,
type
,
row
)
{
"render"
:
function
(
data
,
type
,
row
)
{
return
function
(){
return
function
(){
// status
// status
...
@@ -43,23 +79,31 @@ $(function() {
...
@@ -43,23 +79,31 @@ $(function() {
pause_resume
=
'<button class="btn btn-info btn-xs job_operate" type="job_resume" type="button">恢复</button> '
;
pause_resume
=
'<button class="btn btn-info btn-xs job_operate" type="job_resume" type="button">恢复</button> '
;
}
}
// log url
// log url
var
logUrl
=
base_url
+
'/joblog?jobName='
+
row
.
jobName
;
var
logUrl
=
base_url
+
'/joblog?job
Group='
+
row
.
jobGroup
+
'&job
Name='
+
row
.
jobName
;
// job data
// job data
var
jobDataMap
=
eval
(
'('
+
row
.
jobData
+
')'
);
var
jobDataMap
=
eval
(
'('
+
row
.
jobData
+
')'
);
var
html
=
'<p jobName="'
+
row
.
jobName
+
'" '
+
var
html
=
'<p id="'
+
row
.
id
+
'" '
+
' cronExpression="'
+
row
.
jobCron
+
'" '
+
' jobGroup="'
+
row
.
jobGroup
+
'" '
+
' job_desc="'
+
jobDataMap
.
job_desc
+
'" '
+
' jobName="'
+
row
.
jobName
+
'" '
+
' job_url="'
+
jobDataMap
.
job_url
+
'" '
+
' jobCron="'
+
row
.
jobCron
+
'" '
+
' handleName="'
+
jobDataMap
.
handleName
+
'" '
+
' jobDesc="'
+
row
.
jobDesc
+
'" '
+
' jobClass="'
+
row
.
jobClass
+
'" '
+
' jobData="'
+
row
.
jobData
+
'" '
+
' author="'
+
row
.
author
+
'" '
+
' alarmEmail="'
+
row
.
alarmEmail
+
'" '
+
' alarmThreshold="'
+
row
.
alarmThreshold
+
'" '
+
' handler_params="'
+
jobDataMap
.
handler_params
+
'" '
+
' handler_address="'
+
jobDataMap
.
handler_address
+
'" '
+
' handler_name="'
+
jobDataMap
.
handler_name
+
'" '
+
'>'
+
'>'
+
pause_resume
+
pause_resume
+
'<button class="btn btn-info btn-xs job_operate" type="job_trigger" type="button">执行</button> '
+
'<button class="btn btn-info btn-xs job_operate" type="job_trigger" type="button">执行</button> '
+
'<button class="btn btn-info btn-xs update" type="button">更新corn</button> '
+
'<button class="btn btn-warning btn-xs update" type="button">编辑</button><br> '
+
'<button class="btn btn-danger btn-xs job_operate" type="job_del" type="button">删除</button> '
+
'<button class="btn btn-warning btn-xs" type="job_del" type="button" '
+
'<button class="btn btn-warning btn-xs" type="job_del" type="button" '
+
'onclick="javascript:window.open(
\'
'
+
logUrl
+
'
\'
)" >查看日志</button>'
+
'onclick="javascript:window.open(
\'
'
+
logUrl
+
'
\'
)" >查看日志</button> '
+
'<button class="btn btn-danger btn-xs job_operate" type="job_del" type="button">删除</button> '
+
'</p>'
;
'</p>'
;
...
@@ -68,8 +112,6 @@ $(function() {
...
@@ -68,8 +112,6 @@ $(function() {
}
}
}
}
],
],
"searching"
:
false
,
"ordering"
:
true
,
"language"
:
{
"language"
:
{
"sProcessing"
:
"处理中..."
,
"sProcessing"
:
"处理中..."
,
"sLengthMenu"
:
"每页 _MENU_ 条记录"
,
"sLengthMenu"
:
"每页 _MENU_ 条记录"
,
...
@@ -96,6 +138,12 @@ $(function() {
...
@@ -96,6 +138,12 @@ $(function() {
}
}
});
});
// 日志弹框提示
$
(
'#job_list'
).
on
(
'click'
,
'.logTips'
,
function
(){
var
msg
=
$
(
this
).
find
(
'span'
).
html
();
ComAlertTec
.
show
(
msg
);
});
// 搜索按钮
// 搜索按钮
$
(
'#searchBtn'
).
on
(
'click'
,
function
(){
$
(
'#searchBtn'
).
on
(
'click'
,
function
(){
jobTable
.
fnDraw
();
jobTable
.
fnDraw
();
...
@@ -108,28 +156,30 @@ $(function() {
...
@@ -108,28 +156,30 @@ $(function() {
var
type
=
$
(
this
).
attr
(
"type"
);
var
type
=
$
(
this
).
attr
(
"type"
);
if
(
"job_pause"
==
type
)
{
if
(
"job_pause"
==
type
)
{
typeName
=
"暂停"
;
typeName
=
"暂停"
;
url
=
base_url
+
"/job/pause"
;
url
=
base_url
+
"/job
info
/pause"
;
}
else
if
(
"job_resume"
==
type
)
{
}
else
if
(
"job_resume"
==
type
)
{
typeName
=
"恢复"
;
typeName
=
"恢复"
;
url
=
base_url
+
"/job/resume"
;
url
=
base_url
+
"/job
info
/resume"
;
}
else
if
(
"job_del"
==
type
)
{
}
else
if
(
"job_del"
==
type
)
{
typeName
=
"删除"
;
typeName
=
"删除"
;
url
=
base_url
+
"/job/remove"
;
url
=
base_url
+
"/job
info
/remove"
;
}
else
if
(
"job_trigger"
==
type
)
{
}
else
if
(
"job_trigger"
==
type
)
{
typeName
=
"执行
一次
"
;
typeName
=
"执行"
;
url
=
base_url
+
"/job/trigger"
;
url
=
base_url
+
"/job
info
/trigger"
;
}
else
{
}
else
{
return
;
return
;
}
}
var
name
=
$
(
this
).
parent
(
'p'
).
attr
(
"jobName"
);
var
jobGroup
=
$
(
this
).
parent
(
'p'
).
attr
(
"jobGroup"
);
var
jobName
=
$
(
this
).
parent
(
'p'
).
attr
(
"jobName"
);
ComConfirm
.
show
(
"确认"
+
typeName
+
"?"
,
function
(){
ComConfirm
.
show
(
"确认"
+
typeName
+
"?"
,
function
(){
$
.
ajax
({
$
.
ajax
({
type
:
'POST'
,
type
:
'POST'
,
url
:
url
,
url
:
url
,
data
:
{
data
:
{
"triggerKeyName"
:
name
"jobGroup"
:
jobGroup
,
"jobName"
:
jobName
},
},
dataType
:
"json"
,
dataType
:
"json"
,
success
:
function
(
data
){
success
:
function
(
data
){
...
@@ -162,50 +212,74 @@ $(function() {
...
@@ -162,50 +212,74 @@ $(function() {
errorClass
:
'help-block'
,
errorClass
:
'help-block'
,
focusInvalid
:
true
,
focusInvalid
:
true
,
rules
:
{
rules
:
{
triggerKey
Name
:
{
job
Name
:
{
required
:
true
,
required
:
true
,
minlength
:
4
,
minlength
:
4
,
maxlength
:
100
,
maxlength
:
100
,
myValid01
:
true
myValid01
:
true
},
},
cronExpressi
on
:
{
jobCr
on
:
{
required
:
true
,
required
:
true
,
maxlength
:
100
maxlength
:
100
},
},
job
_d
esc
:
{
job
D
esc
:
{
required
:
true
,
required
:
true
,
maxlength
:
200
maxlength
:
200
},
},
job_url
:
{
handler_address
:
{
required
:
true
,
required
:
true
,
maxlength
:
200
maxlength
:
200
},
},
handle
N
ame
:
{
handle
r_n
ame
:
{
required
:
true
,
required
:
true
,
maxlength
:
200
maxlength
:
200
},
author
:
{
required
:
true
,
maxlength
:
200
},
alarm_email
:
{
required
:
true
,
maxlength
:
200
},
alarm_threshold
:
{
required
:
true
,
digits
:
true
}
}
},
},
messages
:
{
messages
:
{
triggerKey
Name
:
{
job
Name
:
{
required
:
"请输入“任务
Key”.
"
,
required
:
"请输入“任务
名”
"
,
minlength
:
"“任务
Key
”长度不应低于4位"
,
minlength
:
"“任务
名
”长度不应低于4位"
,
maxlength
:
"“任务
Key
”长度不应超过100位"
maxlength
:
"“任务
名
”长度不应超过100位"
},
},
cronExpressi
on
:
{
jobCr
on
:
{
required
:
"请输入“
任务
Corn”."
,
required
:
"请输入“Corn”."
,
maxlength
:
"“
任务
Corn”长度不应超过100位"
maxlength
:
"“Corn”长度不应超过100位"
},
},
job
_d
esc
:
{
job
D
esc
:
{
required
:
"请输入“任务描述”."
,
required
:
"请输入“任务描述”."
,
maxlength
:
"“任务描述”长度不应超过200位"
maxlength
:
"“任务描述”长度不应超过200位"
},
},
job_url
:
{
handler_address
:
{
required
:
"请输入“
任务URL
”."
,
required
:
"请输入“
远程-机器地址
”."
,
maxlength
:
"“
任务URL
”长度不应超过200位"
maxlength
:
"“
远程-机器地址
”长度不应超过200位"
},
},
handleName
:
{
handler_name
:
{
required
:
"请输入“任务handler”."
,
required
:
"请输入“远程-执行器”."
,
maxlength
:
"“任务handler”长度不应超过200位"
maxlength
:
"“远程-执行器”长度不应超过200位"
},
author
:
{
required
:
"请输入“负责人”."
,
maxlength
:
"“负责人”长度不应超过50位"
},
alarm_email
:
{
required
:
"请输入“报警邮件”."
,
maxlength
:
"“报警邮件”长度不应超过200位"
},
alarm_threshold
:
{
required
:
"请输入“报警阈值”."
,
digits
:
"阀值应该为整数."
}
}
},
},
highlight
:
function
(
element
)
{
highlight
:
function
(
element
)
{
...
@@ -219,52 +293,20 @@ $(function() {
...
@@ -219,52 +293,20 @@ $(function() {
element
.
parent
(
'div'
).
append
(
error
);
element
.
parent
(
'div'
).
append
(
error
);
},
},
submitHandler
:
function
(
form
)
{
submitHandler
:
function
(
form
)
{
$
.
post
(
base_url
+
"/jobinfo/add"
,
$
(
"#addModal .form"
).
serialize
(),
function
(
data
,
status
)
{
var
triggerKeyName
=
$
(
'#addModal input[name="triggerKeyName"]'
).
val
();
if
(
data
.
code
==
"200"
)
{
var
cronExpression
=
$
(
'#addModal input[name="cronExpression"]'
).
val
();
ComAlert
.
show
(
1
,
"新增调度任务成功"
,
function
(){
var
job_desc
=
$
(
'#addModal input[name="job_desc"]'
).
val
();
ComAlert
.
show
(
1
,
"新增任务成功"
);
var
job_url
=
$
(
'#addModal input[name="job_url"]'
).
val
();
jobTable
.
fnDraw
();
var
handleName
=
$
(
'#addModal input[name="handleName"]'
).
val
();
});
}
else
{
var
paramStr
=
'triggerKeyName='
+
triggerKeyName
+
if
(
data
.
msg
)
{
'&cronExpression='
+
cronExpression
+
ComAlert
.
show
(
2
,
data
.
msg
);
'&job_desc='
+
job_desc
+
}
else
{
'&job_url='
+
job_url
+
ComAlert
.
show
(
2
,
"新增失败"
);
'&handleName='
+
handleName
;
}
}
var
ifFin
=
true
;
});
$
(
'#addModal .newParam'
).
each
(
function
(){
ifFin
=
false
;
var
key
=
$
(
this
).
find
(
'input[name="key"]'
).
val
();
var
value
=
$
(
this
).
find
(
'input[name="value"]'
).
val
();
if
(
!
key
)
{
ComAlert
.
show
(
2
,
"新增参数key不可为空"
);
return
;
}
else
{
if
(
!
/^
[
a-zA-Z
][
a-zA-Z0-9_
]
*$/
.
test
(
key
)){
ComAlert
.
show
(
2
,
"新增参数key不合法, 只支持英文字母开头,只含有英文字母、数字和下划线"
);
return
;
}
}
paramStr
+=
"&"
+
key
+
"="
+
value
;
ifFin
=
true
;
});
if
(
ifFin
){
$
.
post
(
base_url
+
"/job/add"
,
paramStr
,
function
(
data
,
status
)
{
if
(
data
.
code
==
"200"
)
{
ComAlert
.
show
(
1
,
"新增调度任务成功"
,
function
(){
window
.
location
.
reload
();
});
}
else
{
if
(
data
.
msg
)
{
ComAlert
.
show
(
2
,
data
.
msg
);
}
else
{
ComAlert
.
show
(
2
,
"新增失败"
);
}
}
});
}
}
}
});
});
$
(
"#addModal"
).
on
(
'hide.bs.modal'
,
function
()
{
$
(
"#addModal"
).
on
(
'hide.bs.modal'
,
function
()
{
...
@@ -273,19 +315,16 @@ $(function() {
...
@@ -273,19 +315,16 @@ $(function() {
$
(
"#addModal .form .form-group"
).
removeClass
(
"has-error"
);
$
(
"#addModal .form .form-group"
).
removeClass
(
"has-error"
);
});
});
// 新增-添加参数
// 远程任务/本地任务,切换
$
(
"#addModal .addParam"
).
on
(
'click'
,
function
()
{
$
(
"#addModal select[name='jobClass']"
).
change
(
function
()
{
var
html
=
'<div class="form-group newParam">'
+
//console.log($(this).val());
'<label for="lastname" class="col-sm-2 control-label">参数 <button class="btn btn-danger btn-xs removeParam" type="button">移除</button></label>'
+
console
.
log
(
$
(
this
).
val
().
indexOf
(
'HttpJobBean'
)
);
'<div class="col-sm-4"><input type="text" class="form-control" name="key" placeholder="请输入参数key[将会强转为String]" maxlength="200" /></div>'
+
if
(
$
(
this
).
val
().
indexOf
(
'HttpJobBean'
)
>
-
1
){
'<div class="col-sm-6"><input type="text" class="form-control" name="value" placeholder="请输入参数value[将会强转为String]" maxlength="200" /></div>'
+
$
(
".remote_panel"
).
show
();
// remote
'</div>'
;
}
else
if
(
$
(
this
).
val
().
indexOf
(
'HttpJobBean'
)
==
-
1
){
$
(
this
).
parents
(
'.form-group'
).
parent
().
append
(
html
);
$
(
".remote_panel"
).
hide
();
// local
}
$
(
"#addModal .removeParam"
).
on
(
'click'
,
function
()
{
});
$
(
this
).
parents
(
'.form-group'
).
remove
();
});
});
// 更新
// 更新
$
(
"#job_list"
).
on
(
'click'
,
'.update'
,
function
()
{
$
(
"#job_list"
).
on
(
'click'
,
'.update'
,
function
()
{
...
@@ -376,4 +415,20 @@ $(function() {
...
@@ -376,4 +415,20 @@ $(function() {
$
(
"#updateModal .form"
)[
0
].
reset
()
$
(
"#updateModal .form"
)[
0
].
reset
()
});
});
/*
// 新增-添加参数
$("#addModal .addParam").on('click', function () {
var html = '<div class="form-group newParam">'+
'<label for="lastname" class="col-sm-2 control-label">参数 <button class="btn btn-danger btn-xs removeParam" type="button">移除</button></label>'+
'<div class="col-sm-4"><input type="text" class="form-control" name="key" placeholder="请输入参数key[将会强转为String]" maxlength="200" /></div>'+
'<div class="col-sm-6"><input type="text" class="form-control" name="value" placeholder="请输入参数value[将会强转为String]" maxlength="200" /></div>'+
'</div>';
$(this).parents('.form-group').parent().append(html);
$("#addModal .removeParam").on('click', function () {
$(this).parents('.form-group').remove();
});
});
*/
});
});
xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js
浏览文件 @
554429ea
...
@@ -33,6 +33,7 @@ $(function() {
...
@@ -33,6 +33,7 @@ $(function() {
},
},
{
"data"
:
'jobName'
},
{
"data"
:
'jobName'
},
{
"data"
:
'jobCron'
,
"visible"
:
false
},
{
"data"
:
'jobCron'
,
"visible"
:
false
},
{
"data"
:
'jobDesc'
,
"visible"
:
false
},
{
"data"
:
'jobClass'
,
"visible"
:
false
},
{
"data"
:
'jobClass'
,
"visible"
:
false
},
{
{
"data"
:
'jobData'
,
"data"
:
'jobData'
,
...
...
xxl-job-admin/src/test/java/com/xxl/job/dao/impl/XxlJobInfoTest.java
浏览文件 @
554429ea
...
@@ -21,8 +21,8 @@ public class XxlJobInfoTest {
...
@@ -21,8 +21,8 @@ public class XxlJobInfoTest {
@Test
@Test
public
void
pageList
(){
public
void
pageList
(){
List
<
XxlJobInfo
>
list
=
xxlJobInfoDao
.
pageList
(
0
,
20
,
null
,
null
,
null
);
List
<
XxlJobInfo
>
list
=
xxlJobInfoDao
.
pageList
(
0
,
20
,
null
,
null
);
int
list_count
=
xxlJobInfoDao
.
pageListCount
(
0
,
20
,
null
,
null
,
null
);
int
list_count
=
xxlJobInfoDao
.
pageListCount
(
0
,
20
,
null
,
null
);
System
.
out
.
println
(
list
);
System
.
out
.
println
(
list
);
System
.
out
.
println
(
list_count
);
System
.
out
.
println
(
list_count
);
...
@@ -39,13 +39,13 @@ public class XxlJobInfoTest {
...
@@ -39,13 +39,13 @@ public class XxlJobInfoTest {
System
.
out
.
println
(
count
);
System
.
out
.
println
(
count
);
System
.
out
.
println
(
info
.
getId
());
System
.
out
.
println
(
info
.
getId
());
XxlJobInfo
item
=
xxlJobInfoDao
.
load
(
"job_name"
);
XxlJobInfo
item
=
xxlJobInfoDao
.
load
(
null
,
"job_name"
);
System
.
out
.
println
(
item
);
System
.
out
.
println
(
item
);
}
}
@Test
@Test
public
void
update
(){
public
void
update
(){
XxlJobInfo
item
=
xxlJobInfoDao
.
load
(
"job_name"
);
XxlJobInfo
item
=
xxlJobInfoDao
.
load
(
null
,
"job_name"
);
item
.
setJobCron
(
"jobCron2"
);
item
.
setJobCron
(
"jobCron2"
);
item
.
setJobData
(
"jobData2"
);
item
.
setJobData
(
"jobData2"
);
...
...
xxl-job-admin/src/test/java/com/xxl/job/dao/impl/XxlJobLogTest.java
浏览文件 @
554429ea
...
@@ -57,8 +57,8 @@ public class XxlJobLogTest {
...
@@ -57,8 +57,8 @@ public class XxlJobLogTest {
@Test
@Test
public
void
pageList
(){
public
void
pageList
(){
List
<
XxlJobLog
>
list
=
xxlJobLogDao
.
pageList
(
0
,
20
,
null
,
null
,
null
);
List
<
XxlJobLog
>
list
=
xxlJobLogDao
.
pageList
(
0
,
20
,
null
,
null
,
null
,
null
);
int
list_count
=
xxlJobLogDao
.
pageListCount
(
0
,
20
,
null
,
null
,
null
);
int
list_count
=
xxlJobLogDao
.
pageListCount
(
0
,
20
,
null
,
null
,
null
,
null
);
System
.
out
.
println
(
list
);
System
.
out
.
println
(
list
);
System
.
out
.
println
(
list_count
);
System
.
out
.
println
(
list_count
);
...
...
xxl-job-client-demo/src/main/java/com/xxl/job/service/handler/DemoJobHandler.java
浏览文件 @
554429ea
package
com
.
xxl
.
job
.
service
.
handler
;
package
com
.
xxl
.
job
.
service
.
handler
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -20,12 +19,12 @@ public class DemoJobHandler extends IJobHandler {
...
@@ -20,12 +19,12 @@ public class DemoJobHandler extends IJobHandler {
private
static
transient
Logger
logger
=
LoggerFactory
.
getLogger
(
DemoJobHandler
.
class
);
private
static
transient
Logger
logger
=
LoggerFactory
.
getLogger
(
DemoJobHandler
.
class
);
public
DemoJobHandler
()
{
public
DemoJobHandler
()
{
HandlerRepository
.
regist
(
DemoJobHandler
.
class
.
getName
()
,
this
);
HandlerRepository
.
regist
(
"demoJobHandler"
,
this
);
}
}
@Override
@Override
public
JobHandleStatus
handle
(
Map
<
String
,
String
>
param
)
throws
Exception
{
public
JobHandleStatus
handle
(
String
...
params
)
throws
Exception
{
logger
.
info
(
" ... param
:{}"
,
param
);
logger
.
info
(
" ... param
s:"
+
params
);
TimeUnit
.
SECONDS
.
sleep
(
new
Random
().
nextInt
(
5
));
TimeUnit
.
SECONDS
.
sleep
(
new
Random
().
nextInt
(
5
));
return
JobHandleStatus
.
SUCCESS
;
return
JobHandleStatus
.
SUCCESS
;
}
}
...
...
xxl-job-client/src/main/java/com/xxl/job/client/handler/HandlerRepository.java
浏览文件 @
554429ea
package
com
.
xxl
.
job
.
client
.
handler
;
package
com
.
xxl
.
job
.
client
.
handler
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.TimeUnit
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.xxl.job.client.handler.IJobHandler.JobHandleStatus
;
import
com.xxl.job.client.util.HttpUtil
;
import
com.xxl.job.client.util.HttpUtil
;
import
com.xxl.job.client.util.JacksonUtil
;
import
com.xxl.job.client.util.JacksonUtil
;
/**
/**
* handler repository
* handler repository
* @author xuxueli 2015-12-19 19:28:44
* @author xuxueli 2015-12-19 19:28:44
...
@@ -23,142 +17,47 @@ import com.xxl.job.client.util.JacksonUtil;
...
@@ -23,142 +17,47 @@ import com.xxl.job.client.util.JacksonUtil;
public
class
HandlerRepository
{
public
class
HandlerRepository
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HandlerRepository
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HandlerRepository
.
class
);
public
static
final
String
job_desc
=
"job_desc"
;
public
static
final
String
HANDLER_ADDRESS
=
"handler_address"
;
public
static
final
String
job_url
=
"job_url"
;
public
static
final
String
HANDLER_NAME
=
"handler_name"
;
public
static
final
String
handleName
=
"handleName"
;
public
static
final
String
HANDLER_PARAMS
=
"handler_params"
;
public
static
final
String
triggerLogId
=
"triggerLogId"
;
public
static
final
String
triggerLogUrl
=
"triggerLogUrl"
;
public
static
final
String
TRIGGER_LOG_ID
=
"trigger_log_id"
;
public
static
final
String
TRIGGER_LOG_URL
=
"trigger_log_url"
;
// handler class map
private
static
ConcurrentHashMap
<
String
,
IJobHandler
>
handlerClassMap
=
new
ConcurrentHashMap
<
String
,
IJobHandler
>();
public
static
ConcurrentHashMap
<
String
,
HandlerThread
>
handlerTreadMap
=
new
ConcurrentHashMap
<
String
,
HandlerThread
>();
// handler thread map
private
static
ConcurrentHashMap
<
String
,
HandlerThread
>
handlerTreadMap
=
new
ConcurrentHashMap
<
String
,
HandlerThread
>();
// handler date queue map
private
static
ConcurrentHashMap
<
String
,
LinkedBlockingQueue
<
Map
<
String
,
String
>>>
handlerDataQueueMap
=
new
ConcurrentHashMap
<
String
,
LinkedBlockingQueue
<
Map
<
String
,
String
>>>();
// regist handler
// regist handler
public
static
void
regist
(
String
handleName
,
IJobHandler
handler
){
public
static
void
regist
(
String
handleName
,
IJobHandler
handler
){
handlerClassMap
.
put
(
handleName
,
handler
);
HandlerThread
handlerThread
=
new
HandlerThread
(
handler
);
LinkedBlockingQueue
<
Map
<
String
,
String
>>
handlerDateQueue
=
new
LinkedBlockingQueue
<
Map
<
String
,
String
>>();
handlerDataQueueMap
.
put
(
handleName
,
handlerDateQueue
);
HandlerThread
handlerThread
=
new
HandlerThread
(
handleName
);
handlerThread
.
start
();
handlerThread
.
start
();
handlerTreadMap
.
put
(
handleName
,
handlerThread
);
handlerTreadMap
.
put
(
handleName
,
handlerThread
);
// putIfAbsent
logger
.
info
(
">>>>>>>>>>> xxl-job regist handler success, handleName:{}, handler:{}, handlerDateQueue:{}, handlerThread:{}"
,
logger
.
info
(
">>>>>>>>>>> xxl-job regist handler success, handleName:{}, handler:{}"
,
new
Object
[]{
handleName
,
handler
});
new
Object
[]{
handleName
,
handler
,
handlerDateQueue
,
handlerThread
});
}
// create handler thread
static
class
HandlerThread
extends
Thread
{
private
String
_handleName
;
public
HandlerThread
(
String
_handleName
)
{
this
.
_handleName
=
_handleName
;
}
public
boolean
isValid
=
true
;
public
void
stopThread
(){
isValid
=
false
;
}
@Override
public
void
run
()
{
while
(
isValid
)
{
LinkedBlockingQueue
<
Map
<
String
,
String
>>
handlerDateQueue
=
handlerDataQueueMap
.
get
(
_handleName
);
Map
<
String
,
String
>
handlerData
=
handlerDateQueue
.
poll
();
if
(
handlerData
!=
null
)
{
// handle job
JobHandleStatus
_status
=
JobHandleStatus
.
FAIL
;
String
_msg
=
null
;
try
{
IJobHandler
handler
=
handlerClassMap
.
get
(
_handleName
);
_status
=
handler
.
handle
(
handlerData
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
_status
=
JobHandleStatus
.
FAIL
;
StringWriter
out
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
out
));
_msg
=
out
.
toString
();
}
// callback handler info
String
callback_response
[]
=
null
;
try
{
String
_triggerLogUrl
=
handlerData
.
get
(
HandlerRepository
.
triggerLogUrl
);
HashMap
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
HandlerRepository
.
triggerLogId
,
handlerData
.
get
(
HandlerRepository
.
triggerLogId
));
params
.
put
(
HttpUtil
.
status
,
_status
.
name
());
params
.
put
(
HttpUtil
.
msg
,
_msg
);
callback_response
=
HttpUtil
.
post
(
_triggerLogUrl
,
params
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
logger
.
info
(
"<<<<<<<<<<< xxl-job thread handle, handlerData:{}, callback_status:{}, callback_msg:{}, callback_response:{}, thread:{}"
,
new
Object
[]{
handlerData
,
_status
,
_msg
,
callback_response
,
this
});
}
else
{
try
{
TimeUnit
.
MILLISECONDS
.
sleep
(
200
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
}
// handler push to queue
// handler push to queue
public
static
String
pushHandleQueue
(
Map
<
String
,
String
>
_param
)
{
public
static
String
pushHandleQueue
(
Map
<
String
,
String
>
_param
)
{
logger
.
info
(
">>>>>>>>>>> xxl-job pushHandleQueue start, _param:{}"
,
new
Object
[]{
_param
});
// resu
o
lt
// result
String
_status
=
HttpUtil
.
FAIL
;
String
_status
=
HttpUtil
.
FAIL
;
String
_msg
=
""
;
String
_msg
=
""
;
// push data to queue
// push data to queue
String
_handleName
=
_param
.
get
(
HandlerRepository
.
handleName
);
HandlerThread
handlerThread
=
handlerTreadMap
.
get
(
_param
.
get
(
HandlerRepository
.
HANDLER_NAME
));
int
_triggerLogId
=
Integer
.
valueOf
(
_param
.
get
(
HandlerRepository
.
triggerLogId
));
// 次数应校验,停止队列功能为开发
if
(
handlerThread
!=
null
)
{
try
{
handlerThread
.
pushData
(
_param
);
if
(
_handleName
!=
null
&&
_handleName
.
trim
().
length
()>
0
)
{
_status
=
HttpUtil
.
SUCCESS
;
IJobHandler
handler
=
handlerClassMap
.
get
(
_handleName
);
}
else
{
if
(
handler
!=
null
)
{
_msg
=
"handler not found."
;
// push data to handler queue
LinkedBlockingQueue
<
Map
<
String
,
String
>>
handlerDateQueue
=
handlerDataQueueMap
.
get
(
_handleName
);
if
(
handlerDateQueue
==
null
)
{
handlerDateQueue
=
new
LinkedBlockingQueue
<
Map
<
String
,
String
>>();
handlerDataQueueMap
.
put
(
_handleName
,
handlerDateQueue
);
logger
.
info
(
">>>>>>>>>>> xxl-job handler lazy fresh handlerDateQueue, _handleName:{}, handler:{}, handlerDateQueue:{}"
,
new
Object
[]{
_handleName
,
handler
,
handlerDateQueue
});
}
// check handler thread
HandlerThread
handlerThreadOld
=
handlerTreadMap
.
get
(
_handleName
);
if
(!
handlerThreadOld
.
isAlive
())
{
handlerThreadOld
.
stopThread
();
HandlerThread
handlerThread
=
new
HandlerThread
(
_handleName
);
handlerThread
.
start
();
handlerTreadMap
.
put
(
_handleName
,
handlerThread
);
logger
.
info
(
">>>>>>>>>>> xxl-job handler lazy fresh thread, _handleName:{}, handler:{}, handlerThread:{}"
,
new
Object
[]{
_handleName
,
handler
,
handlerThread
});
}
// push to queue
handlerDateQueue
.
offer
(
_param
);
_status
=
HttpUtil
.
SUCCESS
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
StringWriter
out
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
out
));
_status
=
HttpUtil
.
FAIL
;
_msg
=
out
.
toString
();
}
}
logger
.
info
(
">>>>>>>>>>> xxl-job pushHandleQueue, _handleName:{}, _triggerLogId:{}, _param:{}, _status:{}, _msg:{}"
,
new
Object
[]{
_handleName
,
_triggerLogId
,
_param
,
_status
,
_msg
});
HashMap
<
String
,
String
>
triggerData
=
new
HashMap
<
String
,
String
>();
HashMap
<
String
,
String
>
triggerData
=
new
HashMap
<
String
,
String
>();
triggerData
.
put
(
HandlerRepository
.
TRIGGER_LOG_ID
,
_param
.
get
(
HandlerRepository
.
TRIGGER_LOG_ID
));
triggerData
.
put
(
HttpUtil
.
status
,
_status
);
triggerData
.
put
(
HttpUtil
.
status
,
_status
);
triggerData
.
put
(
HttpUtil
.
msg
,
_msg
);
triggerData
.
put
(
HttpUtil
.
msg
,
_msg
);
return
JacksonUtil
.
writeValueAsString
(
triggerData
);
/**
logger
.
info
(
">>>>>>>>>>> xxl-job pushHandleQueue end, triggerData:{}"
,
new
Object
[]{
triggerData
});
* trigger-log :
return
JacksonUtil
.
writeValueAsString
(
triggerData
);
* trigger side : store trigger-info >> trigger request >> update trigger-response-status
* job side : handler trigger >> update trigger-result
*/
}
}
}
}
xxl-job-client/src/main/java/com/xxl/job/client/handler/IJobHandler.java
浏览文件 @
554429ea
package
com
.
xxl
.
job
.
client
.
handler
;
package
com
.
xxl
.
job
.
client
.
handler
;
import
java.util.Map
;
/**
/**
* remote job handler
* remote job handler
* @author xuxueli 2015-12-19 19:06:38
* @author xuxueli 2015-12-19 19:06:38
...
@@ -15,7 +13,7 @@ public abstract class IJobHandler extends HandlerRepository{
...
@@ -15,7 +13,7 @@ public abstract class IJobHandler extends HandlerRepository{
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
abstract
JobHandleStatus
handle
(
Map
<
String
,
String
>
param
)
throws
Exception
;
public
abstract
JobHandleStatus
handle
(
String
...
params
)
throws
Exception
;
public
enum
JobHandleStatus
{
public
enum
JobHandleStatus
{
/**
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论