⚡ 优化执行逻辑.
This commit is contained in:
@@ -9,7 +9,7 @@ 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.ExecLogTailRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ReExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
import com.orion.ops.module.asset.service.ExecService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -44,7 +44,7 @@ public class ExecController {
|
||||
@PostMapping("/exec-command")
|
||||
@Operation(summary = "批量执行命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
|
||||
public ExecCommandVO execCommand(@Validated @RequestBody ExecCommandRequest request) {
|
||||
public ExecLogVO execCommand(@Validated @RequestBody ExecCommandRequest request) {
|
||||
return execService.execCommand(request);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ExecController {
|
||||
@PostMapping("/re-exec-command")
|
||||
@Operation(summary = "重新执行命令")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
|
||||
public ExecCommandVO reExecCommand(@Validated @RequestBody ReExecCommandRequest request) {
|
||||
public ExecLogVO reExecCommand(@Validated @RequestBody ReExecCommandRequest request) {
|
||||
return execService.reExecCommand(request.getLogId());
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,14 @@ public class ExecLogController {
|
||||
return execLogService.getExecLogPage(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "查询执行日志")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-log:query')")
|
||||
public ExecLogVO getExecLog(@RequestParam("id") Long id) {
|
||||
return execLogService.getExecLog(id, ExecSourceEnum.BATCH.name());
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/host-list")
|
||||
@Operation(summary = "查询全部执行主机日志")
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 命令执行主机 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/3/11 14:57
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecCommandHostVO", description = "命令执行主机 视图响应对象")
|
||||
public class ExecCommandHostVO implements Serializable {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "hostId")
|
||||
private Long hostId;
|
||||
|
||||
@Schema(description = "主机名称")
|
||||
private String hostName;
|
||||
|
||||
@Schema(description = "主机地址")
|
||||
private String hostAddress;
|
||||
|
||||
@Schema(description = "执行状态")
|
||||
private String status;
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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 = "执行状态")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "主机 id 映射")
|
||||
private List<ExecCommandHostVO> hosts;
|
||||
|
||||
}
|
||||
@@ -59,4 +59,7 @@ public class ExecLogVO implements Serializable {
|
||||
@Schema(description = "执行主机id")
|
||||
private List<Long> hostIdList;
|
||||
|
||||
@Schema(description = "执行主机")
|
||||
private List<ExecHostLogVO> hosts;
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,15 @@ public interface ExecLogService {
|
||||
*/
|
||||
DataGrid<ExecLogVO> getExecLogPage(ExecLogQueryRequest request);
|
||||
|
||||
/**
|
||||
* 获取执行日志
|
||||
*
|
||||
* @param id id
|
||||
* @param source source
|
||||
* @return row
|
||||
*/
|
||||
ExecLogVO getExecLog(Long id, String source);
|
||||
|
||||
/**
|
||||
* 获取执行历史
|
||||
*
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.orion.ops.module.asset.service;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecLogTailDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecLogTailRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface ExecService {
|
||||
* @param request request
|
||||
* @return result
|
||||
*/
|
||||
ExecCommandVO execCommand(ExecCommandRequest request);
|
||||
ExecLogVO execCommand(ExecCommandRequest request);
|
||||
|
||||
/**
|
||||
* 重新执行命令
|
||||
@@ -30,7 +30,7 @@ public interface ExecService {
|
||||
* @param id id
|
||||
* @return result
|
||||
*/
|
||||
ExecCommandVO reExecCommand(Long id);
|
||||
ExecLogVO reExecCommand(Long id);
|
||||
|
||||
/**
|
||||
* 中断命令执行
|
||||
|
||||
@@ -65,6 +65,24 @@ public class ExecLogServiceImpl implements ExecLogService {
|
||||
.dataGrid(ExecLogConvert.MAPPER::to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecLogVO getExecLog(Long id, String source) {
|
||||
// 查询执行日志
|
||||
ExecLogDO row = execLogDAO.of()
|
||||
.createValidateWrapper()
|
||||
.eq(ExecLogDO::getId, id)
|
||||
.eq(ExecLogDO::getSource, source)
|
||||
.then()
|
||||
.getOne();
|
||||
Valid.notNull(row, ErrorMessage.LOG_ABSENT);
|
||||
// 查询执行主机
|
||||
List<ExecHostLogDO> hosts = execHostLogDAO.selectByLogId(id);
|
||||
// 返回
|
||||
ExecLogVO vo = ExecLogConvert.MAPPER.to(row);
|
||||
vo.setHosts(ExecHostLogConvert.MAPPER.to(hosts));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExecLogVO> getExecHistory(ExecLogQueryRequest request) {
|
||||
// 查询执行记录
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.orion.ops.framework.common.security.LoginUser;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.convert.ExecHostLogConvert;
|
||||
import com.orion.ops.module.asset.convert.ExecLogConvert;
|
||||
import com.orion.ops.module.asset.dao.ExecHostLogDAO;
|
||||
import com.orion.ops.module.asset.dao.ExecLogDAO;
|
||||
import com.orion.ops.module.asset.dao.HostDAO;
|
||||
@@ -35,8 +37,8 @@ import com.orion.ops.module.asset.entity.dto.ExecLogTailDTO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecParameterSchemaDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecCommandRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecLogTailRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandHostVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecCommandVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecHostLogVO;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
|
||||
import com.orion.ops.module.asset.entity.vo.HostConfigVO;
|
||||
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
||||
import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
||||
@@ -102,7 +104,7 @@ public class ExecServiceImpl implements ExecService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExecCommandVO execCommand(ExecCommandRequest request) {
|
||||
public ExecLogVO execCommand(ExecCommandRequest request) {
|
||||
log.info("ExecService.startExecCommand start params: {}", JSON.toJSONString(request));
|
||||
LoginUser user = Objects.requireNonNull(SecurityUtils.getLoginUser());
|
||||
Long userId = user.getId();
|
||||
@@ -156,25 +158,15 @@ public class ExecServiceImpl implements ExecService {
|
||||
// 开始执行
|
||||
this.startExec(execLog, execHostLogs);
|
||||
// 返回
|
||||
List<ExecCommandHostVO> hostResult = execHostLogs.stream()
|
||||
.map(s -> ExecCommandHostVO.builder()
|
||||
.id(s.getId())
|
||||
.hostId(s.getHostId())
|
||||
.hostName(s.getHostName())
|
||||
.hostAddress(s.getHostAddress())
|
||||
.status(s.getStatus())
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
return ExecCommandVO.builder()
|
||||
.id(execId)
|
||||
.status(execLog.getStatus())
|
||||
.hosts(hostResult)
|
||||
.build();
|
||||
ExecLogVO result = ExecLogConvert.MAPPER.to(execLog);
|
||||
List<ExecHostLogVO> resultHosts = ExecHostLogConvert.MAPPER.to(execHostLogs);
|
||||
result.setHosts(resultHosts);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExecCommandVO reExecCommand(Long logId) {
|
||||
public ExecLogVO reExecCommand(Long logId) {
|
||||
log.info("ExecService.reExecCommand start logId: {}", logId);
|
||||
// 获取执行记录
|
||||
ExecLogDO execLog = execLogDAO.selectById(logId);
|
||||
|
||||
Reference in New Issue
Block a user