🔨 执行日志.
This commit is contained in:
@@ -7,17 +7,14 @@ import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.define.operator.ExecOperatorType;
|
||||
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.vo.ExecVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandVO;
|
||||
import com.orion.ops.module.asset.service.ExecService;
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -44,12 +41,12 @@ public class ExecController {
|
||||
@PostMapping("/exec-command")
|
||||
@Operation(summary = "批量执行命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
|
||||
public ExecVO execCommand(@RequestBody ExecCommandRequest request) {
|
||||
public ExecCommandVO execCommand(@RequestBody ExecCommandRequest request) {
|
||||
return execService.execCommand(request);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecOperatorType.INTERRUPT_EXEC)
|
||||
@PostMapping("/interrupt")
|
||||
@PutMapping("/interrupt")
|
||||
@Operation(summary = "中断执行命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:interrupt-exec')")
|
||||
public HttpWrapper<?> interruptExec(@RequestBody ExecInterruptRequest request) {
|
||||
@@ -59,8 +56,8 @@ public class ExecController {
|
||||
}
|
||||
|
||||
@OperatorLog(ExecOperatorType.INTERRUPT_HOST)
|
||||
@PostMapping("/interrupt-host")
|
||||
@Operation(summary = "中断执行命令")
|
||||
@PutMapping("/interrupt-host")
|
||||
@Operation(summary = "中断执行主机命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:interrupt-exec')")
|
||||
public HttpWrapper<?> interruptHostExec(@RequestBody ExecInterruptRequest request) {
|
||||
Long hostLogId = Valid.notNull(request.getHostLogId());
|
||||
@@ -69,5 +66,7 @@ public class ExecController {
|
||||
}
|
||||
|
||||
// TODO tail log
|
||||
// TODO 重新执行
|
||||
// TODO 删除时 中断
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.orion.ops.module.asset.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.common.validator.group.Batch;
|
||||
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;
|
||||
@@ -48,15 +47,6 @@ public class ExecLogController {
|
||||
@Resource
|
||||
private ExecHostLogService execHostLogService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "查询执行日志")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-log:query')")
|
||||
public ExecLogVO getExecLog(@RequestParam("id") Long id) {
|
||||
return execLogService.getExecLogById(id);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询执行日志")
|
||||
@@ -76,10 +66,11 @@ public class ExecLogController {
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "查询执行日志状态")
|
||||
@Operation(summary = "查询命令执行状态")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-log:query')")
|
||||
public ExecLogStatusVO getExecLogStatus(@Validated(Batch.class) @RequestBody ExecLogQueryRequest request) {
|
||||
return execLogService.getExecLogStatus(request.getIdList());
|
||||
public ExecLogStatusVO getExecLogStatus(@RequestParam("idList") List<Long> idList) {
|
||||
return execLogService.getExecLogStatus(idList);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecOperatorType.DELETE_LOG)
|
||||
|
||||
@@ -2,14 +2,11 @@ package com.orion.ops.module.asset.entity.request.exec;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.orion.ops.framework.common.entity.PageRequest;
|
||||
import com.orion.ops.framework.common.validator.group.Batch;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量执行日志 查询请求对象
|
||||
@@ -29,10 +26,6 @@ public class ExecLogQueryRequest extends PageRequest {
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@NotEmpty(groups = Batch.class)
|
||||
@Schema(description = "id")
|
||||
private List<Long> idList;
|
||||
|
||||
@Schema(description = "执行用户id")
|
||||
private Long userId;
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 批量执行 视图响应对象
|
||||
* 命令执行主机 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -20,13 +19,13 @@ import java.util.Map;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecVO", description = "批量执行 视图响应对象")
|
||||
public class ExecVO implements Serializable {
|
||||
@Schema(name = "ExecCommandHostVO", description = "命令执行主机 视图响应对象")
|
||||
public class ExecCommandHostVO implements Serializable {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "主机 id 映射 host:id")
|
||||
private Map<String, Long> hostIdRel;
|
||||
@Schema(description = "hostId")
|
||||
private Long hostId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.orion.ops.module.asset.entity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 命令执行 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/3/11 14:57
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecCommandVO", description = "命令执行 视图响应对象")
|
||||
public class ExecCommandVO implements Serializable {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "主机 id 映射")
|
||||
private List<ExecCommandHostVO> hosts;
|
||||
|
||||
}
|
||||
@@ -16,14 +16,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface ExecLogService {
|
||||
|
||||
/**
|
||||
* 查询批量执行日志
|
||||
*
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
ExecLogVO getExecLogById(Long id);
|
||||
|
||||
/**
|
||||
* 分页查询批量执行日志
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.orion.ops.module.asset.service;
|
||||
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandVO;
|
||||
|
||||
/**
|
||||
* 批量执行服务
|
||||
@@ -18,7 +18,7 @@ public interface ExecService {
|
||||
* @param request request
|
||||
* @return result
|
||||
*/
|
||||
ExecVO execCommand(ExecCommandRequest request);
|
||||
ExecCommandVO execCommand(ExecCommandRequest request);
|
||||
|
||||
/**
|
||||
* 中断命令执行
|
||||
|
||||
@@ -48,15 +48,6 @@ public class ExecLogServiceImpl implements ExecLogService {
|
||||
@Resource
|
||||
private ExecHostLogService execHostLogService;
|
||||
|
||||
@Override
|
||||
public ExecLogVO getExecLogById(Long id) {
|
||||
// 查询
|
||||
ExecLogDO record = execLogDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
return ExecLogConvert.MAPPER.to(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataGrid<ExecLogVO> getExecLogPage(ExecLogQueryRequest request) {
|
||||
// 条件
|
||||
|
||||
@@ -24,7 +24,8 @@ import com.orion.ops.module.asset.entity.domain.ExecHostLogDO;
|
||||
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.ExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandHostVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandVO;
|
||||
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecStatusEnum;
|
||||
@@ -82,7 +83,7 @@ public class ExecServiceImpl implements ExecService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExecVO execCommand(ExecCommandRequest request) {
|
||||
public ExecCommandVO execCommand(ExecCommandRequest request) {
|
||||
log.info("ExecService.startExecCommand start params: {}", JSON.toJSONString(request));
|
||||
LoginUser user = Objects.requireNonNull(SecurityUtils.getLoginUser());
|
||||
Long userId = user.getId();
|
||||
@@ -141,11 +142,15 @@ public class ExecServiceImpl implements ExecService {
|
||||
// 操作日志
|
||||
OperatorLogs.add(OperatorLogs.ID, execId);
|
||||
// 返回
|
||||
Map<String, Long> hostIdRel = execHostLogs.stream()
|
||||
.collect(Collectors.toMap(s -> String.valueOf(s.getHostId()), ExecHostLogDO::getId));
|
||||
return ExecVO.builder()
|
||||
List<ExecCommandHostVO> hostResult = execHostLogs.stream()
|
||||
.map(s -> ExecCommandHostVO.builder()
|
||||
.id(s.getId())
|
||||
.hostId(s.getHostId())
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
return ExecCommandVO.builder()
|
||||
.id(execId)
|
||||
.hostIdRel(hostIdRel)
|
||||
.hosts(hostResult)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user