From ac28b23531622a2fac2b07f5ded10a3a3b7eae0c Mon Sep 17 00:00:00 2001 From: yangyang01000846 <15195822163@163.com> Date: Tue, 18 Nov 2025 09:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9AHPC=20job=20clone,?= =?UTF-8?q?=E9=87=8D=E6=8E=92=E9=98=9F=E6=8C=87=E4=BB=A4=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=9B=86=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/resp/pbs/hpc/CloneJobResp.java | 8 +++++ .../entity/resp/pbs/hpc/JobRequeueResp.java | 12 +++++++ .../utils/HpcCommandResulParseUtil.java | 35 +++++++++++++++++++ .../sdm/pbs/service/impl/TaskServiceImpl.java | 10 +++--- 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/CloneJobResp.java create mode 100644 common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/JobRequeueResp.java diff --git a/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/CloneJobResp.java b/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/CloneJobResp.java new file mode 100644 index 00000000..0ab41ce8 --- /dev/null +++ b/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/CloneJobResp.java @@ -0,0 +1,8 @@ +package com.sdm.common.entity.resp.pbs.hpc; + +import lombok.Data; + +@Data +public class CloneJobResp { + private String jobId; +} diff --git a/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/JobRequeueResp.java b/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/JobRequeueResp.java new file mode 100644 index 00000000..33ddf3de --- /dev/null +++ b/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/JobRequeueResp.java @@ -0,0 +1,12 @@ +package com.sdm.common.entity.resp.pbs.hpc; + +import lombok.Data; + +@Data +public class JobRequeueResp { + + private Boolean requeued; + + private String jobId; + +} diff --git a/common/src/main/java/com/sdm/common/utils/HpcCommandResulParseUtil.java b/common/src/main/java/com/sdm/common/utils/HpcCommandResulParseUtil.java index b08661a6..d9b81bf2 100644 --- a/common/src/main/java/com/sdm/common/utils/HpcCommandResulParseUtil.java +++ b/common/src/main/java/com/sdm/common/utils/HpcCommandResulParseUtil.java @@ -522,4 +522,39 @@ public class HpcCommandResulParseUtil { } + public static CloneJobResp parseJobCloneResult(String cmdOutput) { + CloneJobResp cloneJobResp = new CloneJobResp(); + try { + // 按逗号分割,然后按冒号分割 + String[] parts = cmdOutput.split(","); + for (String part : parts) { + if (part.trim().startsWith("ID:")) { + String idStr = part.split(":")[1].trim(); + cloneJobResp.setJobId(idStr); + return cloneJobResp; + } + } + } catch (Exception e) { + CoreLogger.error("parseJobCloneResult error:{}",cmdOutput); + } + return cloneJobResp; + } + + public static JobRequeueResp parseJobRequeue(String cmdOutput) { + JobRequeueResp jobRequeueResp = new JobRequeueResp(); + if (StringUtils.isBlank(cmdOutput)) return jobRequeueResp; + String line = cmdOutput.trim(); + // 正常返回格式:Requeue job #6 + Pattern p = Pattern.compile("Requeue job #?(\\d+)", Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(line); + if (m.find()) { + jobRequeueResp.setRequeued(true); + String requeuedJobId = m.group(1); + jobRequeueResp.setJobId(requeuedJobId); + return jobRequeueResp; + } + jobRequeueResp.setRequeued(false); + return jobRequeueResp; + } + } diff --git a/pbs/src/main/java/com/sdm/pbs/service/impl/TaskServiceImpl.java b/pbs/src/main/java/com/sdm/pbs/service/impl/TaskServiceImpl.java index 8a6d6c39..40c5b2ff 100644 --- a/pbs/src/main/java/com/sdm/pbs/service/impl/TaskServiceImpl.java +++ b/pbs/src/main/java/com/sdm/pbs/service/impl/TaskServiceImpl.java @@ -134,9 +134,10 @@ public class TaskServiceImpl implements TaskService { BeanUtils.copyProperties(req, cloneJobParam); String cloneJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, cloneJobParam, ""); String result = hpcCommandExcuteUtil.excuteCmd(cloneJobCommand,hpcExcuteWay); - Map map = new HashMap<>(); + CloneJobResp cloneJobResp = HpcCommandResulParseUtil.parseJobCloneResult(result); + Map map = new HashMap<>(); map.put("hpcCommand", cloneJobCommand); - map.put("result", result); + map.put("result", cloneJobResp); return SdmResponse.success(map); } @@ -203,9 +204,10 @@ public class TaskServiceImpl implements TaskService { BeanUtils.copyProperties(req, jobRequeueParam); String requeueJobCommand = HpcCommandBuilderUtil.buildHpcCommandStr(prefixStr, jobRequeueParam, ""); String result = hpcCommandExcuteUtil.excuteCmd(requeueJobCommand,hpcExcuteWay); - Map map = new HashMap<>(); + JobRequeueResp jobRequeueResp = HpcCommandResulParseUtil.parseJobRequeue(result); + Map map = new HashMap<>(); map.put("hpcCommand", requeueJobCommand); - map.put("result", result); + map.put("result", jobRequeueResp); return SdmResponse.success(map); }