🔨 定时执行配置.
This commit is contained in:
@@ -92,7 +92,7 @@ public class ExecJobController {
|
||||
|
||||
@OperatorLog(ExecJobOperatorType.TRIGGER)
|
||||
@PostMapping("/trigger")
|
||||
@Operation(summary = "手动触发计划任务")
|
||||
@Operation(summary = "手动触发计划执行任务")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job:trigger')")
|
||||
public HttpWrapper<?> triggerExecJob(@Validated @RequestBody ExecJobTriggerRequest request) {
|
||||
execJobService.manualTriggerExecJob(request.getId());
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
### 查询计划任务日志
|
||||
### 查询计划执行任务日志
|
||||
GET {{baseUrl}}/asset/exec-job-log/get?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 分页查询计划任务日志
|
||||
### 分页查询计划执行任务日志
|
||||
POST {{baseUrl}}/asset/exec-job-log/query
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
@@ -20,12 +20,12 @@ Authorization: {{token}}
|
||||
}
|
||||
|
||||
|
||||
### 删除计划任务日志
|
||||
### 删除计划执行任务日志
|
||||
DELETE {{baseUrl}}/asset/exec-job-log/delete?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 批量删除计划任务日志
|
||||
### 批量删除计划执行任务日志
|
||||
DELETE {{baseUrl}}/asset/exec-job-log/batch-delete?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计划任务日志 api
|
||||
* 计划执行任务日志 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-11 11:31
|
||||
*/
|
||||
@Tag(name = "asset - 计划任务日志服务")
|
||||
@Tag(name = "asset - 计划执行任务日志服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@@ -53,7 +53,7 @@ public class ExecJobLogController {
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询计划任务日志")
|
||||
@Operation(summary = "分页查询计划执行任务日志")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:query')")
|
||||
public DataGrid<ExecLogVO> getExecJobLogPage(@Validated(Page.class) @RequestBody ExecLogQueryRequest request) {
|
||||
request.setSource(SOURCE);
|
||||
@@ -62,7 +62,7 @@ public class ExecJobLogController {
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "查询计划任务日志")
|
||||
@Operation(summary = "查询计划执行任务日志")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:query')")
|
||||
public ExecLogVO getExecJobLog(@RequestParam("id") Long id) {
|
||||
return execLogService.getExecLog(id, SOURCE);
|
||||
@@ -87,7 +87,7 @@ public class ExecJobLogController {
|
||||
|
||||
@OperatorLog(ExecJobLogOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除计划任务日志")
|
||||
@Operation(summary = "删除计划执行任务日志")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:delete')")
|
||||
public Integer deleteExecJobLog(@RequestParam("id") Long id) {
|
||||
@@ -96,7 +96,7 @@ public class ExecJobLogController {
|
||||
|
||||
@OperatorLog(ExecJobLogOperatorType.DELETE)
|
||||
@DeleteMapping("/batch-delete")
|
||||
@Operation(summary = "删除计划任务日志")
|
||||
@Operation(summary = "删除计划执行任务日志")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:delete')")
|
||||
public Integer batchDeleteExecJobLog(@RequestParam("idList") List<Long> idList) {
|
||||
@@ -113,7 +113,7 @@ public class ExecJobLogController {
|
||||
}
|
||||
|
||||
@PostMapping("/query-count")
|
||||
@Operation(summary = "查询计划任务日志数量")
|
||||
@Operation(summary = "查询计划执行任务日志数量")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:management:clear')")
|
||||
public Long getExecJobLogCount(@RequestBody ExecLogQueryRequest request) {
|
||||
request.setSource(SOURCE);
|
||||
@@ -122,7 +122,7 @@ public class ExecJobLogController {
|
||||
|
||||
@OperatorLog(ExecJobLogOperatorType.CLEAR)
|
||||
@PostMapping("/clear")
|
||||
@Operation(summary = "清空计划任务日志")
|
||||
@Operation(summary = "清空计划执行任务日志")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:management:clear')")
|
||||
public Integer clearExecJobLog(@RequestBody ExecLogQueryRequest request) {
|
||||
request.setSource(SOURCE);
|
||||
@@ -130,7 +130,7 @@ public class ExecJobLogController {
|
||||
}
|
||||
|
||||
@PostMapping("/tail")
|
||||
@Operation(summary = "查看计划任务日志")
|
||||
@Operation(summary = "查看计划执行任务日志")
|
||||
@PreAuthorize("@ss.hasAnyPermission('asset:exec-job-log:query', 'asset:exec-job:exec')")
|
||||
public String getExecJobLogTailToken(@Validated @RequestBody ExecLogTailRequest request) {
|
||||
request.setSource(SOURCE);
|
||||
@@ -139,7 +139,7 @@ public class ExecJobLogController {
|
||||
|
||||
@OperatorLog(ExecJobLogOperatorType.DOWNLOAD)
|
||||
@GetMapping("/download")
|
||||
@Operation(summary = "下载计划任务日志")
|
||||
@Operation(summary = "下载计划执行任务日志")
|
||||
@PreAuthorize("@ss.hasAnyPermission('asset:exec-job-log:query', 'asset:exec-job:exec')")
|
||||
public void downloadExecJobLogFile(@RequestParam("id") Long id, HttpServletResponse response) {
|
||||
execLogService.downloadLogFile(id, SOURCE, response);
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.orion.ops.module.asset.entity.vo.HostVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机 内部对象转换器
|
||||
*
|
||||
@@ -33,4 +35,6 @@ public interface HostConvert {
|
||||
|
||||
HostCacheDTO toCache(HostDO domain);
|
||||
|
||||
List<HostVO> toList(List<HostDO> domain);
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ExecCommandLogOperatorType extends InitializingOperatorTypes {
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(H, DELETE, "删除批量执行日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE_HOST, "删除批量主机执行日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
new OperatorType(H, DELETE_HOST, "删除批量执行主机日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
new OperatorType(H, CLEAR, "清理批量执行日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(L, DOWNLOAD, "下载主机执行日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLe
|
||||
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.L;
|
||||
|
||||
/**
|
||||
* 计划任务日志 操作记录类型
|
||||
* 计划执行日志 操作记录类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
@@ -28,9 +28,9 @@ public class ExecJobLogOperatorType extends InitializingOperatorTypes {
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(H, DELETE, "删除计划任务日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE_HOST, "删除批量主机执行日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
new OperatorType(H, CLEAR, "清理计划任务日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE, "删除计划执行日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(H, DELETE_HOST, "删除计划执行主机日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
new OperatorType(H, CLEAR, "清理计划执行日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(L, DOWNLOAD, "下载主机执行日志 <sb>${logId}</sb> <sb>${hostName}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ public class ExecJobOperatorType extends InitializingOperatorTypes {
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, CREATE, "创建计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE, "更新计划任务 <sb>${before}</sb>"),
|
||||
new OperatorType(M, UPDATE_STATUS, "<sb>${statusName}</sb>计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, TRIGGER, "手动触发计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(H, DELETE, "删除计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(L, CREATE, "创建计划执行任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE, "更新计划执行任务 <sb>${before}</sb>"),
|
||||
new OperatorType(M, UPDATE_STATUS, "<sb>${statusName}</sb>计划执行任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, TRIGGER, "手动触发计划执行任务 <sb>${name}</sb>"),
|
||||
new OperatorType(H, DELETE, "删除计划执行任务 <sb>${name}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ExecJobDO extends BaseDO {
|
||||
@TableField("parameter_schema")
|
||||
private String parameterSchema;
|
||||
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
@Schema(description = "任务状态")
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ExecJobQueryRequest extends PageRequest {
|
||||
@Schema(description = "执行命令")
|
||||
private String command;
|
||||
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
@Schema(description = "任务状态")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "是否查询最近执行任务")
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ExecJobUpdateStatusRequest implements Serializable {
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
@Schema(description = "任务状态")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -44,17 +44,17 @@ public class ExecJobVO implements Serializable {
|
||||
@Schema(description = "命令参数")
|
||||
private String parameterSchema;
|
||||
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
@Schema(description = "任务状态")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "最近执行id")
|
||||
private Long recentLogId;
|
||||
|
||||
@Schema(description = "最近执行状态")
|
||||
private String recentExecStatus;
|
||||
private String recentLogStatus;
|
||||
|
||||
@Schema(description = "最近执行时间")
|
||||
private Date recentExecTime;
|
||||
private Date recentLogTime;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
@@ -65,4 +65,7 @@ public class ExecJobVO implements Serializable {
|
||||
@Schema(description = "执行主机")
|
||||
private List<Long> hostIdList;
|
||||
|
||||
@Schema(description = "执行主机")
|
||||
private List<HostVO> hostList;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public enum ExecSourceEnum {
|
||||
BATCH,
|
||||
|
||||
/**
|
||||
* 计划任务
|
||||
* 计划执行
|
||||
*/
|
||||
JOB,
|
||||
|
||||
|
||||
@@ -221,7 +221,6 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
||||
// 添加内置参数
|
||||
params.put("userId", request.getUserId());
|
||||
params.put("username", request.getUsername());
|
||||
params.put("source", request.getSource());
|
||||
params.put("sourceId", request.getSourceId());
|
||||
params.put("seq", request.getExecSeq());
|
||||
params.put("execId", execId);
|
||||
|
||||
@@ -12,10 +12,13 @@ import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.job.core.utils.QuartzUtils;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.convert.ExecJobConvert;
|
||||
import com.orion.ops.module.asset.convert.HostConvert;
|
||||
import com.orion.ops.module.asset.dao.ExecJobDAO;
|
||||
import com.orion.ops.module.asset.dao.ExecLogDAO;
|
||||
import com.orion.ops.module.asset.dao.HostDAO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecJobDO;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostDO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.*;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
@@ -24,9 +27,9 @@ import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
||||
import com.orion.ops.module.asset.enums.HostConfigTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.exec.job.ExecCommandJob;
|
||||
import com.orion.ops.module.asset.service.AssetAuthorizedDataService;
|
||||
import com.orion.ops.module.asset.service.ExecCommandService;
|
||||
import com.orion.ops.module.asset.service.ExecJobHostService;
|
||||
import com.orion.ops.module.asset.service.ExecJobService;
|
||||
import com.orion.ops.module.asset.service.ExecCommandService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -58,6 +61,9 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
@Resource
|
||||
private ExecLogDAO execLogDAO;
|
||||
|
||||
@Resource
|
||||
private HostDAO hostDAO;
|
||||
|
||||
@Resource
|
||||
private ExecJobHostService execJobHostService;
|
||||
|
||||
@@ -80,7 +86,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
// 查询主机是否有权限
|
||||
this.checkHostPermission(request.getHostIdList());
|
||||
// 插入任务
|
||||
record.setStatus(ExecJobStatusEnum.ENABLED.getStatus());
|
||||
record.setStatus(ExecJobStatusEnum.DISABLED.getStatus());
|
||||
int effect = execJobDAO.insert(record);
|
||||
Long id = record.getId();
|
||||
// 设置任务主机
|
||||
@@ -152,6 +158,9 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
// 查询任务主机
|
||||
List<Long> hostIdList = execJobHostService.getHostIdByJobId(id);
|
||||
vo.setHostIdList(hostIdList);
|
||||
// 查询主机列表
|
||||
List<HostDO> hostList = hostDAO.selectBatchIds(hostIdList);
|
||||
vo.setHostList(HostConvert.MAPPER.toList(hostList));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -175,6 +184,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
List<ExecLogDO> logList = execLogDAO.selectBatchIds(logIdList);
|
||||
Map<Long, ExecLogDO> logMap = logList.stream()
|
||||
.collect(Collectors.toMap(ExecLogDO::getId, Function.identity()));
|
||||
// 设置任务状态
|
||||
dataGrid.forEach(s -> {
|
||||
Long logId = s.getRecentLogId();
|
||||
if (logId == null) {
|
||||
@@ -184,8 +194,8 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
if (execLog == null) {
|
||||
return;
|
||||
}
|
||||
s.setRecentExecTime(execLog.getStartTime());
|
||||
s.setRecentExecStatus(execLog.getStatus());
|
||||
s.setRecentLogTime(execLog.getStartTime());
|
||||
s.setRecentLogStatus(execLog.getStatus());
|
||||
});
|
||||
}
|
||||
return dataGrid;
|
||||
@@ -305,8 +315,8 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
private LambdaQueryWrapper<ExecJobDO> buildQueryWrapper(ExecJobQueryRequest request) {
|
||||
return execJobDAO.wrapper()
|
||||
.eq(ExecJobDO::getId, request.getId())
|
||||
.eq(ExecJobDO::getName, request.getName())
|
||||
.eq(ExecJobDO::getCommand, request.getCommand())
|
||||
.like(ExecJobDO::getName, request.getName())
|
||||
.like(ExecJobDO::getCommand, request.getCommand())
|
||||
.eq(ExecJobDO::getStatus, request.getStatus())
|
||||
.orderByDesc(ExecJobDO::getId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user