🔨 批量执行.

This commit is contained in:
lijiahang
2024-03-12 19:01:33 +08:00
parent 2c025c800f
commit 0ea7593c8f
7 changed files with 92 additions and 22 deletions

View File

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

View File

@@ -1,9 +1,11 @@
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.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecRequest;
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.service.ExecService;
import io.swagger.v3.oas.annotations.Operation;
@@ -37,12 +39,23 @@ public class ExecController {
@Resource
private ExecService execService;
@OperatorLog(ExecOperatorType.START)
@PostMapping("/start")
@Operation(summary = "批量执行")
@PreAuthorize("@ss.hasPermission('asset:exec:start')")
public ExecVO startExecCommand(@RequestBody ExecRequest request) {
return execService.startExecCommand(request);
@OperatorLog(ExecOperatorType.EXEC_COMMAND)
@PostMapping("/exec-command")
@Operation(summary = "批量执行命令")
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
public ExecVO execCommand(@RequestBody ExecCommandRequest request) {
return execService.execCommand(request);
}
@OperatorLog(ExecOperatorType.INTERRUPT_COMMAND)
@PostMapping("/interrupt-command")
@Operation(summary = "中断执行命令")
@PreAuthorize("@ss.hasPermission('asset:exec:interrupt-command')")
public HttpWrapper<?> interruptCommand(@RequestBody ExecInterruptRequest request) {
execService.interruptCommand(request);
return HttpWrapper.ok();
}
// log
}

View File

@@ -17,15 +17,21 @@ import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLe
@Module("asset:exec")
public class ExecOperatorType extends InitializingOperatorTypes {
public static final String START = "exec:start";
public static final String EXEC_COMMAND = "exec:exec-command";
public static final String INTERRUPT_COMMAND = "exec:interrupt-command";
public static final String DELETE_LOG = "exec:delete-log";
public static final String CLEAR_LOG = "exec:clear-log";
@Override
public OperatorType[] types() {
return new OperatorType[]{
new OperatorType(M, START, "批量执行主机命令"),
new OperatorType(H, DELETE_LOG, "删除批量执行日志"),
new OperatorType(M, EXEC_COMMAND, "执行主机命令"),
new OperatorType(M, INTERRUPT_COMMAND, "中断执行命令"),
new OperatorType(H, DELETE_LOG, "删除执行日志 ${count} 条"),
new OperatorType(H, CLEAR_LOG, "清理执行日志 ${count} 条"),
};
}

View File

@@ -1,6 +1,5 @@
package com.orion.ops.module.asset.entity.request.exec;
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@@ -10,7 +9,7 @@ import javax.validation.constraints.Size;
import java.util.List;
/**
* 批量执行 请求对象
* 批量执行命令 请求对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -20,9 +19,8 @@ import java.util.List;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "ExecRequest", description = "批量执行 请求对象")
public class ExecRequest extends PageRequest {
@Schema(name = "ExecCommandRequest", description = "批量执行命令 请求对象")
public class ExecCommandRequest {
@Schema(description = "执行模板id")
private Long templateId;

View File

@@ -0,0 +1,29 @@
package com.orion.ops.module.asset.entity.request.exec;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 中断执行命令
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/3/12 18:36
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecInterruptRequest", description = "中断执行命令 请求对象")
public class ExecInterruptRequest {
@Schema(description = "执行日志id")
private Long logId;
@Schema(description = "执行主机日志id")
private Long hostLogId;
}

View File

@@ -1,6 +1,7 @@
package com.orion.ops.module.asset.service;
import com.orion.ops.module.asset.entity.request.exec.ExecRequest;
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;
/**
@@ -13,11 +14,18 @@ import com.orion.ops.module.asset.entity.vo.ExecVO;
public interface ExecService {
/**
* 批量执行
* 批量执行命令
*
* @param request request
* @return result
*/
ExecVO startExecCommand(ExecRequest request);
ExecVO execCommand(ExecCommandRequest request);
/**
* 中断命令执行
*
* @param request request
*/
void interruptCommand(ExecInterruptRequest request);
}

View File

@@ -22,7 +22,8 @@ import com.orion.ops.module.asset.dao.HostDAO;
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.ExecRequest;
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.enums.ExecHostStatusEnum;
import com.orion.ops.module.asset.enums.ExecSourceEnum;
@@ -75,7 +76,7 @@ public class ExecServiceImpl implements ExecService {
@Override
@Transactional(rollbackFor = Exception.class)
public ExecVO startExecCommand(ExecRequest request) {
public ExecVO execCommand(ExecCommandRequest request) {
log.info("ExecService.startExecCommand start params: {}", JSON.toJSONString(request));
LoginUser user = Objects.requireNonNull(SecurityUtils.getLoginUser());
Long userId = user.getId();
@@ -141,6 +142,11 @@ public class ExecServiceImpl implements ExecService {
.build();
}
@Override
public void interruptCommand(ExecInterruptRequest request) {
}
/**
* 构建日志路径
*