新增:HPC常用指令封装

This commit is contained in:
yangyang01000846
2025-11-17 20:35:23 +08:00
parent 29b8b81ecc
commit 5c6041becb
51 changed files with 3490 additions and 11 deletions

View File

@@ -30,6 +30,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
@@ -77,6 +81,11 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
<!-- Actuator for health checks -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 并行的依赖要放在最后,不然里面的旧版本依赖会覆盖引入的新版本依赖 -->
<!-- 并行HPC -->
@@ -93,11 +102,7 @@
</exclusion>
</exclusions>
</dependency>
<!-- Actuator for health checks -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>

View File

@@ -0,0 +1,109 @@
package com.sdm.pbs.controller;
import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.req.pbs.hpc.*;
import com.sdm.pbs.service.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
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;
@RestController
@RequestMapping("/pbs")
@Tag(name = "HPC调度", description = "与hpc交互的接口")
public class TaskController {
@Autowired
private TaskService taskService;
@PostMapping("/nodeList")
@Operation(summary = "节点列表查询")
public SdmResponse nodeList(@RequestBody NodeListReq req) {
return taskService.nodeList(req);
}
@PostMapping("/nodeListCore")
@Operation(summary = "节点核心列表查询")
public SdmResponse nodeListCore(@RequestBody NodeListCoreReq req) {
return taskService.nodeListCore(req);
}
@PostMapping("/nodeView")
@Operation(summary = "节点详情查询")
public SdmResponse nodeView(@RequestBody NodeViewReq req) {
return taskService.nodeView(req);
}
@PostMapping("/jobNew")
@Operation(summary = "创建job任务")
public SdmResponse jobNew(@RequestBody NewJobReq req) {
return taskService.jobNew(req);
}
@PostMapping("/jobAdd")
@Operation(summary = "添加job任务")
public SdmResponse jobAdd(@RequestBody AddJobReq req) {
return taskService.jobAdd(req);
}
@PostMapping("/jobSubmit")
@Operation(summary = "提交job任务")
public SdmResponse jobSubmit(@RequestBody SubmitHpcJobReq req) {
return taskService.jobSubmit(req);
}
@PostMapping("/jobCancel")
@Operation(summary = "取消job任务")
public SdmResponse jobCancel(@RequestBody CancelJobReq req) {
return taskService.jobCancel(req);
}
@PostMapping("/jobClone")
@Operation(summary = "克隆job任务")
public SdmResponse jobClone(@RequestBody CloneJobReq req) {
return taskService.jobClone(req);
}
@PostMapping("/jobFinish")
@Operation(summary = "优雅完成job任务")
public SdmResponse jobFinish(@RequestBody FinishJobReq req) {
return taskService.jobFinish(req);
}
@PostMapping("/jobList")
@Operation(summary = "有条件查询所有job任务")
public SdmResponse jobList(@RequestBody ListJobReq req) {
return taskService.jobList(req);
}
@PostMapping("/jobTasks")
@Operation(summary = "查询所有作业列表")
public SdmResponse jobTasks(@RequestBody ListTasksReq req) {
return taskService.jobTasks(req);
}
@PostMapping("/jobModify")
@Operation(summary = "修改作业属性")
public SdmResponse jobModify(@RequestBody JobModifyReq req) {
return taskService.jobModify(req);
}
@PostMapping("/jobRequeue")
@Operation(summary = "作业重新排队")
public SdmResponse jobRequeue(@RequestBody JobRequeueReq req) {
return taskService.jobRequeue(req);
}
@PostMapping("/jobView")
@Operation(summary = "查看作业视图")
public SdmResponse jobView(@RequestBody JobViewReq req) {
return taskService.jobView(req);
}
}

View File

@@ -0,0 +1,38 @@
package com.sdm.pbs.service;
import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.req.pbs.hpc.*;
import org.springframework.stereotype.Service;
@Service
public interface TaskService {
SdmResponse nodeList(NodeListReq req);
SdmResponse nodeListCore(NodeListCoreReq req);
SdmResponse nodeView(NodeViewReq req);
SdmResponse jobNew(NewJobReq req);
SdmResponse jobAdd(AddJobReq req);
SdmResponse jobSubmit(SubmitHpcJobReq req);
SdmResponse jobCancel(CancelJobReq req);
SdmResponse jobClone(CloneJobReq req);
SdmResponse jobFinish(FinishJobReq req);
SdmResponse jobList(ListJobReq req);
SdmResponse jobTasks(ListTasksReq req);
SdmResponse jobModify(JobModifyReq req);
SdmResponse jobRequeue(JobRequeueReq req);
SdmResponse jobView(JobViewReq req);
}

View File

@@ -0,0 +1,226 @@
package com.sdm.pbs.service.impl;
import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.pojo.pbs.hpc.*;
import com.sdm.common.entity.req.pbs.hpc.*;
import com.sdm.common.entity.resp.pbs.hpc.*;
import com.sdm.common.utils.HpcCommandBuilderUtil;
import com.sdm.common.utils.HpcCommandExcuteUtil;
import com.sdm.common.utils.HpcCommandResulParseUtil;
import com.sdm.pbs.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class TaskServiceImpl implements TaskService {
@Value("${hpc.excuteWay:}")
private String hpcExcuteWay;
@Autowired
private HpcCommandExcuteUtil hpcCommandExcuteUtil;
@Override
public SdmResponse nodeList(NodeListReq req) {
String prefixStr = HpcCommandBuilderUtil.initNodeListPrefixStr(req.getActiveheadnode());
NodeListParam nodeListParam = new NodeListParam();
BeanUtils.copyProperties(req, nodeListParam);
String nodeListCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, nodeListParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(nodeListCommand,hpcExcuteWay);
List<NodeListResp> nodeListResp = HpcCommandResulParseUtil.parseNodList(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", nodeListCommand);
map.put("result", nodeListResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse nodeListCore(NodeListCoreReq req) {
String prefixStr = HpcCommandBuilderUtil.initNodeListCorePrefixStr();
NodeListCoreParam nodeListCoreParam = new NodeListCoreParam();
BeanUtils.copyProperties(req, nodeListCoreParam);
String nodeListCoreCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, nodeListCoreParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(nodeListCoreCommand,hpcExcuteWay);
List<NodeListCoreResp> nodeListCoreResp = HpcCommandResulParseUtil.parseNodeCoreList(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", nodeListCoreCommand);
map.put("result", nodeListCoreResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse nodeView(NodeViewReq req) {
String prefixStr = HpcCommandBuilderUtil.initNodeViewPrefixStr(req.getNodeName());
NodeViewParam nodeViewParam = new NodeViewParam();
BeanUtils.copyProperties(req, nodeViewParam);
String nodeViewCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, nodeViewParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(nodeViewCommand,hpcExcuteWay);
NodeViewResp nodeViewResp = HpcCommandResulParseUtil.parseNodeView(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", nodeViewCommand);
map.put("result", nodeViewResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobNew(NewJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initNewJobPrefixStr();
NewJobParam newJobParam = new NewJobParam();
BeanUtils.copyProperties(req, newJobParam);
String newJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, newJobParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(newJobCommand,hpcExcuteWay);
NewJobResp newJobResp = HpcCommandResulParseUtil.parseJobNewResult(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", newJobCommand);
map.put("result", newJobResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobAdd(AddJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initAddJobPrefixStr(req.getJobId());
AddJobParam addJobParam = new AddJobParam();
BeanUtils.copyProperties(req, addJobParam);
String addJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, addJobParam, req.getCommand());
String result = hpcCommandExcuteUtil.excuteCmd(addJobCommand,hpcExcuteWay);
AddJobResp addJobResp = HpcCommandResulParseUtil.parseJoAddResult(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", addJobCommand);
map.put("result", addJobResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobSubmit(SubmitHpcJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initSubmitJobPrefixStr(req.getId());
SubmitHpcJobParam submitHpcJobParam = new SubmitHpcJobParam();
BeanUtils.copyProperties(req, submitHpcJobParam);
String submitJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, submitHpcJobParam, req.getCommand());
String result = hpcCommandExcuteUtil.excuteCmd(submitJobCommand,hpcExcuteWay);
SubmitHpcJobResp submitHpcJobResp = HpcCommandResulParseUtil.parseJobSubmitResult(result);
submitHpcJobResp.setJobId(req.getId());
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", submitJobCommand);
map.put("result", submitHpcJobResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobCancel(CancelJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initCancelJobPrefixStr(req.getJobId(),req.getCancelWay());
CancelJobParam cancelJobParam = new CancelJobParam();
BeanUtils.copyProperties(req, cancelJobParam);
String cancelJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, cancelJobParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(cancelJobCommand,hpcExcuteWay);
JobCancelResp jobCancelResp = HpcCommandResulParseUtil.parseJobCancel(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", cancelJobCommand);
map.put("result", jobCancelResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobClone(CloneJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initCloneJobPrefixStr(req.getJobId());
CloneJobParam cloneJobParam = new CloneJobParam();
BeanUtils.copyProperties(req, cloneJobParam);
String cloneJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, cloneJobParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(cloneJobCommand,hpcExcuteWay);
Map<String, String> map = new HashMap<>();
map.put("hpcCommand", cloneJobCommand);
map.put("result", result);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobFinish(FinishJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initFinishJobPrefixStr(req.getJobId(),req.getFinshWay());
FinishJobParam finishJobParam = new FinishJobParam();
BeanUtils.copyProperties(req, finishJobParam);
String finishJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, finishJobParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(finishJobCommand,hpcExcuteWay);
JobFinishResp jobFinishResp = HpcCommandResulParseUtil.parseJobFinish(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", finishJobCommand);
map.put("result", jobFinishResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobList(ListJobReq req) {
String prefixStr = HpcCommandBuilderUtil.initListJobPrefixStr(req.getAll());
ListJobParam listJobParam = new ListJobParam();
BeanUtils.copyProperties(req, listJobParam);
String listJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, listJobParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(listJobCommand,hpcExcuteWay);
List<ListJobResp> jobLists = HpcCommandResulParseUtil.parseJobLists(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", listJobCommand);
map.put("result", jobLists);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobTasks(ListTasksReq req) {
String prefixStr = HpcCommandBuilderUtil.initTasksJobPrefixStr(req.getJobId(),req.getExpand());
ListTasksParam listTasksParam = new ListTasksParam();
BeanUtils.copyProperties(req, listTasksParam);
String listTasksJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, listTasksParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(listTasksJobCommand,hpcExcuteWay);
List<ListTasksResp> jobTaskResp = HpcCommandResulParseUtil.parseJobTasks(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", listTasksJobCommand);
map.put("result", jobTaskResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobModify(JobModifyReq req) {
String prefixStr = HpcCommandBuilderUtil.initModifyJobPrefixStr(req.getJobId(),req.getClearexcludednodes());
JobModifyParam jobModifyParam = new JobModifyParam();
BeanUtils.copyProperties(req, jobModifyParam);
String modifyJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, jobModifyParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(modifyJobCommand,hpcExcuteWay);
JobModifyResp jobModifyResp = HpcCommandResulParseUtil.parseJobModify(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", modifyJobCommand);
map.put("result", jobModifyResp);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobRequeue(JobRequeueReq req) {
String prefixStr = HpcCommandBuilderUtil.initRequeueJobPrefixStr(req.getJobId());
JobRequeueParam jobRequeueParam = new JobRequeueParam();
BeanUtils.copyProperties(req, jobRequeueParam);
String requeueJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, jobRequeueParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(requeueJobCommand,hpcExcuteWay);
Map<String, String> map = new HashMap<>();
map.put("hpcCommand", requeueJobCommand);
map.put("result", result);
return SdmResponse.success(map);
}
@Override
public SdmResponse jobView(JobViewReq req) {
String prefixStr = HpcCommandBuilderUtil.initViewJobPrefixStr(req.getJobId());
JobViewParam jobViewParam = new JobViewParam();
BeanUtils.copyProperties(req, jobViewParam);
String viewJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, jobViewParam, "");
String result = hpcCommandExcuteUtil.excuteCmd(viewJobCommand,hpcExcuteWay);
JobViewResp jobViewResp = HpcCommandResulParseUtil.parseJobView(result);
Map<String, Object> map = new HashMap<>();
map.put("hpcCommand", viewJobCommand);
map.put("result", jobViewResp);
return SdmResponse.success(map);
}
}

View File

@@ -7,24 +7,24 @@ spring:
datasource:
username: root
password: mysql
jdbc-url: jdbc:mysql://192.168.2.166:3306/sdm_base_line?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
jdbc-url: jdbc:mysql://192.168.65.161:3306/spdm_baseline?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
master:
username: root
password: mysql
jdbc-url: jdbc:mysql://192.168.2.166:3306/sdm_base_line?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
jdbc-url: jdbc:mysql://192.168.65.161:3306/spdm_baseline?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
slave:
username: root
password: mysql
jdbc-url: jdbc:mysql://192.168.2.166:3306/sdm_base_line?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
jdbc-url: jdbc:mysql://192.168.65.161:3306/spdm_baseline?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
enable: true
cloud:
nacos:
discovery:
server-addr: 192.168.2.166:8848
# server-addr: 127.0.0.1:8848
server-addr: 192.168.65.161:8848
roup: DEV_GROUP
enabled: true
namespace: 3
# username: nacos
@@ -100,6 +100,11 @@ file:
hpc:
url: http://172.27.3.135/JSONAPI/JSONAPI.ashx
# 这个是spdm mock执行cmd命令
# remoteCmdUrl: http://127.0.0.1:9097/doProcess
# remote hpc借助工具http远程调用local:该服务和hpc部署在同一机器
excuteWay: remote
remoteCmdUrl: http://192.168.65.55:9097/doProcess
#logging:
# config: ./config/logback.xml

View File

@@ -6,7 +6,7 @@
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr([%15.15t]){faint} %clr(%logger){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr([%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr([%15.15t]){faint} %clr(%logger){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="/home/app/pbs/logs" />
<!-- 控制台输出 -->
@@ -36,6 +36,24 @@
<!-- </triggeringPolicy>-->
</appender>
<!-- 4. core.log 专用输出器(保留 callerInfo 格式) -->
<appender name="CORE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/core.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/core.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
<TotalSizeCap>500MB</TotalSizeCap>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!-- 仅 core.log 显示真实调用位置(类名.方法名(行号) -->
<pattern>[%X{traceId}] %d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%15.15t] %X{callerInfo} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="STDOUT" />
@@ -48,6 +66,12 @@
<appender-ref ref="STDOUT" />
</logger>
<!-- 绑定 coreLogger → 输出到 core.log + 控制台 -->
<logger name="coreLogger" level="INFO" additivity="false">
<appender-ref ref="CORE_FILE" /> <!-- 核心日志写入 core.log -->
<appender-ref ref="STDOUT" /> <!-- 同时输出到控制台(显示 CoreLogger -->
</logger>
<!-- MyBatis SQL语句输出配置 -->
<logger name="org.apache.ibatis" level="DEBUG"/>
<logger name="org.apache.ibatis.session.AutoMappingUnknownColumnBehavior" level="ERROR"/>