🔨 批量执行.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
### 批量执行
|
### 批量执行命令
|
||||||
POST {{baseUrl}}/asset/exec/start
|
POST {{baseUrl}}/asset/exec/exec-command
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
|
|
||||||
@@ -12,4 +12,14 @@ Authorization: {{token}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
### 中断执行命令
|
||||||
|
POST {{baseUrl}}/asset/exec/interrupt-command
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"logId": 7
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.orion.ops.module.asset.controller;
|
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.annotation.OperatorLog;
|
||||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||||
import com.orion.ops.module.asset.define.operator.ExecOperatorType;
|
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.entity.vo.ExecVO;
|
||||||
import com.orion.ops.module.asset.service.ExecService;
|
import com.orion.ops.module.asset.service.ExecService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -37,12 +39,23 @@ public class ExecController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ExecService execService;
|
private ExecService execService;
|
||||||
|
|
||||||
@OperatorLog(ExecOperatorType.START)
|
@OperatorLog(ExecOperatorType.EXEC_COMMAND)
|
||||||
@PostMapping("/start")
|
@PostMapping("/exec-command")
|
||||||
@Operation(summary = "批量执行")
|
@Operation(summary = "批量执行命令")
|
||||||
@PreAuthorize("@ss.hasPermission('asset:exec:start')")
|
@PreAuthorize("@ss.hasPermission('asset:exec:exec-command')")
|
||||||
public ExecVO startExecCommand(@RequestBody ExecRequest request) {
|
public ExecVO execCommand(@RequestBody ExecCommandRequest request) {
|
||||||
return execService.startExecCommand(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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,21 @@ import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLe
|
|||||||
@Module("asset:exec")
|
@Module("asset:exec")
|
||||||
public class ExecOperatorType extends InitializingOperatorTypes {
|
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 DELETE_LOG = "exec:delete-log";
|
||||||
|
|
||||||
|
public static final String CLEAR_LOG = "exec:clear-log";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OperatorType[] types() {
|
public OperatorType[] types() {
|
||||||
return new OperatorType[]{
|
return new OperatorType[]{
|
||||||
new OperatorType(M, START, "批量执行主机命令"),
|
new OperatorType(M, EXEC_COMMAND, "执行主机命令"),
|
||||||
new OperatorType(H, DELETE_LOG, "删除批量执行日志"),
|
new OperatorType(M, INTERRUPT_COMMAND, "中断执行命令"),
|
||||||
|
new OperatorType(H, DELETE_LOG, "删除执行日志 ${count} 条"),
|
||||||
|
new OperatorType(H, CLEAR_LOG, "清理执行日志 ${count} 条"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.orion.ops.module.asset.entity.request.exec;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ import javax.validation.constraints.Size;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量执行 请求对象
|
* 批量执行命令 请求对象
|
||||||
*
|
*
|
||||||
* @author Jiahang Li
|
* @author Jiahang Li
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
@@ -20,9 +19,8 @@ import java.util.List;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@Schema(name = "ExecCommandRequest", description = "批量执行命令 请求对象")
|
||||||
@Schema(name = "ExecRequest", description = "批量执行 请求对象")
|
public class ExecCommandRequest {
|
||||||
public class ExecRequest extends PageRequest {
|
|
||||||
|
|
||||||
@Schema(description = "执行模板id")
|
@Schema(description = "执行模板id")
|
||||||
private Long templateId;
|
private Long templateId;
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.orion.ops.module.asset.service;
|
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;
|
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 {
|
public interface ExecService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量执行
|
* 批量执行命令
|
||||||
*
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
ExecVO startExecCommand(ExecRequest request);
|
ExecVO execCommand(ExecCommandRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 中断命令执行
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
*/
|
||||||
|
void interruptCommand(ExecInterruptRequest request);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.ExecHostLogDO;
|
||||||
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
|
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.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.entity.vo.ExecVO;
|
||||||
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
import com.orion.ops.module.asset.enums.ExecHostStatusEnum;
|
||||||
import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
import com.orion.ops.module.asset.enums.ExecSourceEnum;
|
||||||
@@ -75,7 +76,7 @@ public class ExecServiceImpl implements ExecService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ExecVO startExecCommand(ExecRequest request) {
|
public ExecVO execCommand(ExecCommandRequest request) {
|
||||||
log.info("ExecService.startExecCommand start params: {}", JSON.toJSONString(request));
|
log.info("ExecService.startExecCommand start params: {}", JSON.toJSONString(request));
|
||||||
LoginUser user = Objects.requireNonNull(SecurityUtils.getLoginUser());
|
LoginUser user = Objects.requireNonNull(SecurityUtils.getLoginUser());
|
||||||
Long userId = user.getId();
|
Long userId = user.getId();
|
||||||
@@ -141,6 +142,11 @@ public class ExecServiceImpl implements ExecService {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void interruptCommand(ExecInterruptRequest request) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建日志路径
|
* 构建日志路径
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user