🔨 抽象执行日志.

This commit is contained in:
lijiahang
2024-04-12 15:23:15 +08:00
parent 40d0ec2025
commit a4c5d25815
42 changed files with 1304 additions and 388 deletions

View File

@@ -20,14 +20,5 @@ Authorization: {{token}}
"logId": 1
}
### 中断执行命令
POST {{baseUrl}}/asset/exec-command/interrupt
Content-Type: application/json
Authorization: {{token}}
{
"logId": 7
}
###

View File

@@ -1,24 +1,22 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.HttpWrapper;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.biz.operator.log.core.enums.ReturnType;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecCommandOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecInterruptRequest;
import com.orion.ops.module.asset.entity.request.exec.ReExecCommandRequest;
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
import com.orion.ops.module.asset.enums.ExecSourceEnum;
import com.orion.ops.module.asset.service.ExecCommandService;
import com.orion.ops.module.asset.service.ExecLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@@ -38,14 +36,9 @@ import javax.annotation.Resource;
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
public class ExecCommandController {
private static final String SOURCE = ExecSourceEnum.BATCH.name();
@Resource
private ExecCommandService execCommandService;
@Resource
private ExecLogService execLogService;
@OperatorLog(value = ExecCommandOperatorType.EXEC, ret = ReturnType.IGNORE)
@PostMapping("/exec")
@Operation(summary = "批量执行命令")
@@ -62,24 +55,4 @@ public class ExecCommandController {
return execCommandService.reExecCommand(request.getLogId());
}
@OperatorLog(ExecCommandOperatorType.INTERRUPT_EXEC)
@PutMapping("/interrupt")
@Operation(summary = "中断执行命令")
@PreAuthorize("@ss.hasPermission('asset:exec-command:interrupt')")
public HttpWrapper<?> interruptExecCommand(@RequestBody ExecInterruptRequest request) {
Long logId = Valid.notNull(request.getLogId());
execLogService.interruptExec(logId, SOURCE);
return HttpWrapper.ok();
}
@OperatorLog(ExecCommandOperatorType.INTERRUPT_HOST)
@PutMapping("/interrupt-host")
@Operation(summary = "中断执行主机命令")
@PreAuthorize("@ss.hasPermission('asset:exec-command:interrupt')")
public HttpWrapper<?> interruptHostExecCommand(@RequestBody ExecInterruptRequest request) {
Long hostLogId = Valid.notNull(request.getHostLogId());
execLogService.interruptHostExec(hostLogId, SOURCE);
return HttpWrapper.ok();
}
}

View File

@@ -40,9 +40,19 @@ Authorization: {{token}}
}
### 下载执行日志文件
### 下载批量执行日志文件
GET {{baseUrl}}/asset/exec-command-log/download?id=83
Authorization: {{token}}
### 中断批量执行命令
POST {{baseUrl}}/asset/exec-command-log/interrupt
Content-Type: application/json
Authorization: {{token}}
{
"logId": 7
}
###

View File

@@ -1,13 +1,17 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.define.wrapper.HttpWrapper;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.framework.common.validator.group.Page;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
import com.orion.ops.framework.security.core.utils.SecurityUtils;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecCommandLogOperatorType;
import com.orion.ops.module.asset.define.operator.ExecCommandOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecInterruptRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecLogQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecLogTailRequest;
import com.orion.ops.module.asset.entity.vo.ExecHostLogVO;
@@ -156,5 +160,25 @@ public class ExecCommandLogController {
execLogService.downloadLogFile(id, SOURCE, response);
}
@OperatorLog(ExecCommandLogOperatorType.INTERRUPT)
@PutMapping("/interrupt")
@Operation(summary = "中断批量执行命令")
@PreAuthorize("@ss.hasPermission('asset:exec-command-log:interrupt')")
public HttpWrapper<?> interruptExecCommand(@RequestBody ExecInterruptRequest request) {
Long logId = Valid.notNull(request.getLogId());
execLogService.interruptExec(logId, SOURCE);
return HttpWrapper.ok();
}
@OperatorLog(ExecCommandLogOperatorType.INTERRUPT_HOST)
@PutMapping("/interrupt-host")
@Operation(summary = "中断批量执行主机命令")
@PreAuthorize("@ss.hasPermission('asset:exec-command-log:interrupt')")
public HttpWrapper<?> interruptHostExecCommand(@RequestBody ExecInterruptRequest request) {
Long hostLogId = Valid.notNull(request.getHostLogId());
execLogService.interruptHostExec(hostLogId, SOURCE);
return HttpWrapper.ok();
}
}

View File

@@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 计划任务 api
@@ -73,6 +74,14 @@ public class ExecJobController {
return execJobService.getExecJobById(id);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/list")
@Operation(summary = "查询全部计划任务")
@PreAuthorize("@ss.hasPermission('asset:exec-job:query')")
public List<ExecJobVO> getExecJobList() {
return execJobService.getExecJobList();
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询计划任务")

View File

@@ -30,7 +30,7 @@ DELETE {{baseUrl}}/asset/exec-job-log/batch-delete?idList=1,2,3
Authorization: {{token}}
### 查看执行日志
### 查看计划任务日志
POST {{baseUrl}}/asset/exec-job-log/tail
Content-Type: application/json
Authorization: {{token}}
@@ -40,9 +40,18 @@ Authorization: {{token}}
}
### 下载执行日志文件
### 下载计划任务日志文件
GET {{baseUrl}}/asset/exec-job-log/download?id=83
Authorization: {{token}}
### 中断计划任务命令
POST {{baseUrl}}/asset/exec-command-log/interrupt
Content-Type: application/json
Authorization: {{token}}
{
"logId": 7
}
###

View File

@@ -1,12 +1,16 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.define.wrapper.HttpWrapper;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.framework.common.validator.group.Page;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecCommandLogOperatorType;
import com.orion.ops.module.asset.define.operator.ExecJobLogOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecInterruptRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecLogQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecLogTailRequest;
import com.orion.ops.module.asset.entity.vo.ExecHostLogVO;
@@ -145,5 +149,25 @@ public class ExecJobLogController {
execLogService.downloadLogFile(id, SOURCE, response);
}
@OperatorLog(ExecJobLogOperatorType.INTERRUPT)
@PutMapping("/interrupt")
@Operation(summary = "中断计划任务命令")
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:interrupt')")
public HttpWrapper<?> interruptExecCommand(@RequestBody ExecInterruptRequest request) {
Long logId = Valid.notNull(request.getLogId());
execLogService.interruptExec(logId, SOURCE);
return HttpWrapper.ok();
}
@OperatorLog(ExecJobLogOperatorType.INTERRUPT_HOST)
@PutMapping("/interrupt-host")
@Operation(summary = "中断计划任务主机命令")
@PreAuthorize("@ss.hasPermission('asset:exec-job-log:interrupt')")
public HttpWrapper<?> interruptHostExecCommand(@RequestBody ExecInterruptRequest request) {
Long hostLogId = Valid.notNull(request.getHostLogId());
execLogService.interruptHostExec(hostLogId, SOURCE);
return HttpWrapper.ok();
}
}

View File

@@ -4,8 +4,7 @@ import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.H;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.L;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.*;
/**
* 批量执行日志 操作记录类型
@@ -25,6 +24,10 @@ public class ExecCommandLogOperatorType extends InitializingOperatorTypes {
public static final String DOWNLOAD = "exec-command-log:download";
public static final String INTERRUPT = "exec-command-log:interrupt";
public static final String INTERRUPT_HOST = "exec-command-log:interrupt-host";
@Override
public OperatorType[] types() {
return new OperatorType[]{
@@ -32,6 +35,8 @@ public class ExecCommandLogOperatorType extends InitializingOperatorTypes {
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>"),
new OperatorType(M, INTERRUPT, "中断批量执行命令"),
new OperatorType(M, INTERRUPT_HOST, "中断批量执行主机命令 <sb>${logId}</sb> <sb>${hostName}</sb>"),
};
}

View File

@@ -18,16 +18,10 @@ public class ExecCommandOperatorType extends InitializingOperatorTypes {
public static final String EXEC = "exec-command:exec";
public static final String INTERRUPT_EXEC = "exec-command:interrupt-exec";
public static final String INTERRUPT_HOST = "exec-command:interrupt-host";
@Override
public OperatorType[] types() {
return new OperatorType[]{
new OperatorType(M, EXEC, "执行主机命令"),
new OperatorType(M, INTERRUPT_EXEC, "中断执行命令"),
new OperatorType(M, INTERRUPT_HOST, "中断主机执行命令 <sb>${logId}</sb> <sb>${hostName}</sb>"),
};
}

View File

@@ -4,8 +4,7 @@ import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.H;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.L;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.*;
/**
* 计划任务执行日志 操作记录类型
@@ -25,6 +24,10 @@ public class ExecJobLogOperatorType extends InitializingOperatorTypes {
public static final String DOWNLOAD = "exec-job-log:download";
public static final String INTERRUPT = "exec-job-log:interrupt";
public static final String INTERRUPT_HOST = "exec-job-log:interrupt-host";
@Override
public OperatorType[] types() {
return new OperatorType[]{
@@ -32,6 +35,8 @@ public class ExecJobLogOperatorType extends InitializingOperatorTypes {
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>"),
new OperatorType(M, INTERRUPT, "中断计划任务执行命令"),
new OperatorType(M, INTERRUPT_HOST, "中断计划任务执行主机命令 <sb>${logId}</sb> <sb>${hostName}</sb>"),
};
}

View File

@@ -4,6 +4,8 @@ import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.module.asset.entity.request.exec.*;
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
import java.util.List;
/**
* 计划任务 服务类
*
@@ -45,6 +47,13 @@ public interface ExecJobService {
*/
ExecJobVO getExecJobById(Long id);
/**
* 查询全部计划任务
*
* @return rows
*/
List<ExecJobVO> getExecJobList();
/**
* 分页查询计划任务
*

View File

@@ -164,6 +164,15 @@ public class ExecJobServiceImpl implements ExecJobService {
return vo;
}
@Override
public List<ExecJobVO> getExecJobList() {
return execJobDAO.of()
.createWrapper()
.select(ExecJobDO::getId, ExecJobDO::getName)
.then()
.list(ExecJobConvert.MAPPER::to);
}
@Override
public DataGrid<ExecJobVO> getExecJobPage(ExecJobQueryRequest request) {
// 条件