Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QA
holmes
Commits
7c3c416c
Commit
7c3c416c
authored
Jan 04, 2022
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增启用/禁用监控接口,新增接口增加定时任务启动,删除去掉定时任务监控
parent
da19d313
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
SqlMonitorTaskController.java
...g/holmes/controller/monitor/SqlMonitorTaskController.java
+51
-1
QuartzUtils.java
src/main/java/cn/qg/holmes/utils/QuartzUtils.java
+2
-0
No files found.
src/main/java/cn/qg/holmes/controller/monitor/SqlMonitorTaskController.java
View file @
7c3c416c
...
@@ -7,11 +7,13 @@ import cn.qg.holmes.service.monitor.SqlMonitorDataSourceService;
...
@@ -7,11 +7,13 @@ import cn.qg.holmes.service.monitor.SqlMonitorDataSourceService;
import
cn.qg.holmes.service.monitor.SqlMonitorTaskService
;
import
cn.qg.holmes.service.monitor.SqlMonitorTaskService
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
cn.qg.holmes.utils.DingdingUtils
;
import
cn.qg.holmes.utils.JdbcUtils
;
import
cn.qg.holmes.utils.JdbcUtils
;
import
cn.qg.holmes.utils.QuartzUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.quartz.Scheduler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -38,6 +40,9 @@ public class SqlMonitorTaskController {
...
@@ -38,6 +40,9 @@ public class SqlMonitorTaskController {
@Autowired
@Autowired
JdbcTemplate
jdbcTemplate
;
JdbcTemplate
jdbcTemplate
;
@Autowired
private
Scheduler
scheduler
;
/**
/**
* 获取监控列表,带搜索和分页
* 获取监控列表,带搜索和分页
* @param pageNum 第几页
* @param pageNum 第几页
...
@@ -84,7 +89,12 @@ public class SqlMonitorTaskController {
...
@@ -84,7 +89,12 @@ public class SqlMonitorTaskController {
if
(
sqlMonitorTaskService
.
getOne
(
queryWrapper
)
!=
null
)
{
if
(
sqlMonitorTaskService
.
getOne
(
queryWrapper
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"监控名称重复"
,
false
);
return
JsonResult
.
buildErrorStateResult
(
"监控名称重复"
,
false
);
}
}
return
JsonResult
.
buildSuccessResult
(
sqlMonitorTaskService
.
save
(
sqlMonitorTask
));
boolean
result
=
sqlMonitorTaskService
.
save
(
sqlMonitorTask
);
if
(
result
)
{
QuartzUtils
.
createSqlScheduleJob
(
scheduler
,
sqlMonitorTask
);
return
JsonResult
.
buildSuccessResult
(
"监控创建成功!"
);
}
return
JsonResult
.
buildErrorStateResult
(
"监控创建失败!"
,
false
);
}
}
/**
/**
...
@@ -118,6 +128,7 @@ public class SqlMonitorTaskController {
...
@@ -118,6 +128,7 @@ public class SqlMonitorTaskController {
}
}
boolean
delResult
=
sqlMonitorTaskService
.
removeById
(
taskId
);
boolean
delResult
=
sqlMonitorTaskService
.
removeById
(
taskId
);
if
(
delResult
)
{
if
(
delResult
)
{
QuartzUtils
.
deleteScheduleJob
(
scheduler
,
sqlMonitorTask
.
getTaskName
());
return
JsonResult
.
buildSuccessResult
(
"删除成功!"
);
return
JsonResult
.
buildSuccessResult
(
"删除成功!"
);
}
else
{
}
else
{
return
JsonResult
.
buildErrorStateResult
(
"删除失败!"
,
false
);
return
JsonResult
.
buildErrorStateResult
(
"删除失败!"
,
false
);
...
@@ -164,6 +175,10 @@ public class SqlMonitorTaskController {
...
@@ -164,6 +175,10 @@ public class SqlMonitorTaskController {
}
}
}
}
/**
* 定时任务执行策略
* @return
*/
@GetMapping
(
"/strategy"
)
@GetMapping
(
"/strategy"
)
public
JsonResult
getSqlMonitorStrategy
()
{
public
JsonResult
getSqlMonitorStrategy
()
{
List
<
Map
<
String
,
String
>>
strategyList
=
new
ArrayList
<>();
List
<
Map
<
String
,
String
>>
strategyList
=
new
ArrayList
<>();
...
@@ -181,4 +196,39 @@ public class SqlMonitorTaskController {
...
@@ -181,4 +196,39 @@ public class SqlMonitorTaskController {
strategyList
.
add
(
weeklyMap
);
strategyList
.
add
(
weeklyMap
);
return
JsonResult
.
buildSuccessResult
(
strategyList
);
return
JsonResult
.
buildSuccessResult
(
strategyList
);
}
}
/**
* 启用/禁用定时任务
* @param taskId 定时任务id
* @param status 状态,0-禁用,1-启用
* @return
*/
@PostMapping
(
"/enable"
)
public
JsonResult
modifyTaskStatus
(
Integer
taskId
,
Integer
status
)
{
SqlMonitorTask
sqlMonitorTask
=
sqlMonitorTaskService
.
getById
(
taskId
);
if
(
sqlMonitorTask
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"监控不存在!"
,
false
);
}
if
(
status
==
1
)
{
if
(
sqlMonitorTask
.
getStatus
()
==
1
)
{
return
JsonResult
.
buildErrorStateResult
(
"监控已是启用状态"
,
false
);
}
else
{
sqlMonitorTask
.
setStatus
(
1
);
sqlMonitorTaskService
.
updateById
(
sqlMonitorTask
);
QuartzUtils
.
resumeScheduleJob
(
scheduler
,
sqlMonitorTask
.
getTaskName
());
return
JsonResult
.
buildSuccessResult
(
"启用成功!"
,
true
);
}
}
if
(
status
==
0
)
{
if
(
sqlMonitorTask
.
getStatus
()
==
0
)
{
return
JsonResult
.
buildErrorStateResult
(
"监控已是禁用状态"
,
false
);
}
else
{
sqlMonitorTask
.
setStatus
(
0
);
sqlMonitorTaskService
.
updateById
(
sqlMonitorTask
);
QuartzUtils
.
pauseScheduleJob
(
scheduler
,
sqlMonitorTask
.
getTaskName
());
return
JsonResult
.
buildSuccessResult
(
"禁用成功!"
,
true
);
}
}
return
JsonResult
.
buildErrorStateResult
(
"status只能传0或1"
,
false
);
}
}
}
src/main/java/cn/qg/holmes/utils/QuartzUtils.java
View file @
7c3c416c
...
@@ -38,6 +38,7 @@ public class QuartzUtils {
...
@@ -38,6 +38,7 @@ public class QuartzUtils {
public
static
void
pauseScheduleJob
(
Scheduler
scheduler
,
String
jobName
)
{
public
static
void
pauseScheduleJob
(
Scheduler
scheduler
,
String
jobName
)
{
JobKey
jobKey
=
JobKey
.
jobKey
(
jobName
);
JobKey
jobKey
=
JobKey
.
jobKey
(
jobName
);
try
{
try
{
log
.
info
(
"暂停定时任务:{}"
,
jobName
);
scheduler
.
pauseJob
(
jobKey
);
scheduler
.
pauseJob
(
jobKey
);
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
log
.
info
(
"暂停定时任务出错:"
+
e
.
getMessage
());
log
.
info
(
"暂停定时任务出错:"
+
e
.
getMessage
());
...
@@ -53,6 +54,7 @@ public class QuartzUtils {
...
@@ -53,6 +54,7 @@ public class QuartzUtils {
public
static
void
resumeScheduleJob
(
Scheduler
scheduler
,
String
jobName
)
{
public
static
void
resumeScheduleJob
(
Scheduler
scheduler
,
String
jobName
)
{
JobKey
jobKey
=
JobKey
.
jobKey
(
jobName
);
JobKey
jobKey
=
JobKey
.
jobKey
(
jobName
);
try
{
try
{
log
.
info
(
"启动定时任务:{}"
,
jobName
);
scheduler
.
resumeJob
(
jobKey
);
scheduler
.
resumeJob
(
jobKey
);
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
log
.
info
(
"启动定时任务出错:"
+
e
.
getMessage
());
log
.
info
(
"启动定时任务出错:"
+
e
.
getMessage
());
...
...
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