修改:hpc节点查询返回自定义对象
This commit is contained in:
@@ -3,7 +3,7 @@ package com.sdm.common.entity.resp.pbs.hpc;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NodeViewResp {
|
||||
public class NodeViewResp extends HpcBaseResp {
|
||||
private String systemId;
|
||||
private String systemGuid;
|
||||
private String jobTypes;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.sdm.common.entity.resp.pbs.hpc;
|
||||
package com.sdm.common.entity.resp.pbs.hpc.nodecore;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NodeListCoreResp {
|
||||
public class NodeListCore {
|
||||
private String nodeProcessor; // 如:CARSAFECLIENT - 0
|
||||
private String state; // Idle / Running / Offline
|
||||
private String jobId; // 可能为空
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.sdm.common.entity.resp.pbs.hpc.nodecore;
|
||||
|
||||
import com.sdm.common.entity.resp.pbs.hpc.HpcBaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class NodeListCoreResp extends HpcBaseResp {
|
||||
|
||||
private List<NodeListCore> nodeCores;
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.sdm.common.entity.resp.pbs.hpc;
|
||||
package com.sdm.common.entity.resp.pbs.hpc.nodelist;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NodeListResp {
|
||||
public class NodeList {
|
||||
private String nodeName;
|
||||
private String state;
|
||||
private String max;
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sdm.common.entity.resp.pbs.hpc.nodelist;
|
||||
|
||||
import com.sdm.common.entity.resp.pbs.hpc.HpcBaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class NodeListResp extends HpcBaseResp {
|
||||
private List<NodeList> nodes;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.sdm.common.utils;
|
||||
|
||||
import com.sdm.common.entity.resp.pbs.hpc.*;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodecore.NodeListCore;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodelist.NodeList;
|
||||
import com.sdm.common.log.CoreLogger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -343,13 +345,13 @@ public class HpcCommandResulParseUtil {
|
||||
|
||||
|
||||
|
||||
public static List<NodeListResp> parseNodList(String cmdOutput) {
|
||||
List<NodeListResp> result = new ArrayList<>();
|
||||
public static List<NodeList> parseNodList(String cmdOutput) {
|
||||
List<NodeList> result = new ArrayList<>();
|
||||
if (cmdOutput == null || cmdOutput.trim().isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
String[] lines = cmdOutput.split("\r?\n");
|
||||
NodeListResp current = null;
|
||||
NodeList current = null;
|
||||
for (String line : lines) {
|
||||
String trimmed = line.trim();
|
||||
// 空行 = 一个节点结束
|
||||
@@ -362,7 +364,7 @@ public class HpcCommandResulParseUtil {
|
||||
}
|
||||
// 新的 Node 记录开始
|
||||
if (trimmed.startsWith("Node Name")) {
|
||||
current = new NodeListResp();
|
||||
current = new NodeList();
|
||||
}
|
||||
if (current != null && trimmed.contains(":")) {
|
||||
String[] kv = trimmed.split(":", 2);
|
||||
@@ -387,12 +389,12 @@ public class HpcCommandResulParseUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<NodeListCoreResp> parseNodeCoreList(String cmdOutput) {
|
||||
List<NodeListCoreResp> list = new ArrayList<>();
|
||||
public static List<NodeListCore> parseNodeCoreList(String cmdOutput) {
|
||||
List<NodeListCore> list = new ArrayList<>();
|
||||
// 按空行分割每个 Core 的块
|
||||
String[] blocks = cmdOutput.split("\\n\\s*\\n");
|
||||
for (String block : blocks) {
|
||||
NodeListCoreResp resp = new NodeListCoreResp();
|
||||
NodeListCore resp = new NodeListCore();
|
||||
String[] lines = block.split("\\n");
|
||||
String lastKey = null;
|
||||
StringBuilder lastValue = new StringBuilder();
|
||||
@@ -422,7 +424,7 @@ public class HpcCommandResulParseUtil {
|
||||
}
|
||||
|
||||
// 将字段名映射到 Java 对象
|
||||
private static void applyField(NodeListCoreResp resp, String key, String value) {
|
||||
private static void applyField(NodeListCore resp, String key, String value) {
|
||||
switch (key) {
|
||||
case "Node Processor":
|
||||
resp.setNodeProcessor(value);
|
||||
@@ -444,12 +446,9 @@ public class HpcCommandResulParseUtil {
|
||||
|
||||
public static NodeViewResp parseNodeView(String cmdOutput) {
|
||||
NodeViewResp resp = new NodeViewResp();
|
||||
|
||||
String[] lines = cmdOutput.split("\\n");
|
||||
|
||||
String lastKey = null;
|
||||
StringBuilder lastValue = new StringBuilder();
|
||||
|
||||
for (String line : lines) {
|
||||
if (line.contains(":")) {
|
||||
// 保存上一对 key-value
|
||||
|
||||
@@ -4,7 +4,10 @@ import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.req.pbs.hpc.*;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.AddJobResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.NewJobResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.NodeViewResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.SubmitHpcJobResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodecore.NodeListCoreResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodelist.NodeListResp;
|
||||
import com.sdm.pbs.service.TaskService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -27,19 +30,19 @@ public class TaskController {
|
||||
|
||||
@PostMapping("/nodeList")
|
||||
@Operation(summary = "节点列表查询")
|
||||
public SdmResponse nodeList(@RequestBody NodeListReq req) {
|
||||
public SdmResponse<NodeListResp> nodeList(@RequestBody NodeListReq req) {
|
||||
return taskService.nodeList(req);
|
||||
}
|
||||
|
||||
@PostMapping("/nodeListCore")
|
||||
@Operation(summary = "节点核心列表查询")
|
||||
public SdmResponse nodeListCore(@RequestBody NodeListCoreReq req) {
|
||||
public SdmResponse<NodeListCoreResp> nodeListCore(@RequestBody NodeListCoreReq req) {
|
||||
return taskService.nodeListCore(req);
|
||||
}
|
||||
|
||||
@PostMapping("/nodeView")
|
||||
@Operation(summary = "节点详情查询")
|
||||
public SdmResponse nodeView(@RequestBody NodeViewReq req) {
|
||||
public SdmResponse<NodeViewResp> nodeView(@RequestBody NodeViewReq req) {
|
||||
return taskService.nodeView(req);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.req.pbs.hpc.*;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.AddJobResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.NewJobResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.NodeViewResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.SubmitHpcJobResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodecore.NodeListCoreResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodelist.NodeListResp;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||
@@ -12,11 +15,11 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
|
||||
@Service
|
||||
public interface TaskService {
|
||||
|
||||
SdmResponse nodeList(NodeListReq req);
|
||||
SdmResponse<NodeListResp> nodeList(NodeListReq req);
|
||||
|
||||
SdmResponse nodeListCore(NodeListCoreReq req);
|
||||
SdmResponse<NodeListCoreResp> nodeListCore(NodeListCoreReq req);
|
||||
|
||||
SdmResponse nodeView(NodeViewReq req);
|
||||
SdmResponse<NodeViewResp> nodeView(NodeViewReq req);
|
||||
|
||||
SdmResponse<NewJobResp> jobNew(NewJobReq req);
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ import com.sdm.common.entity.constants.PermConstants;
|
||||
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.entity.resp.pbs.hpc.nodecore.NodeListCore;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodecore.NodeListCoreResp;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodelist.NodeList;
|
||||
import com.sdm.common.entity.resp.pbs.hpc.nodelist.NodeListResp;
|
||||
import com.sdm.common.log.CoreLogger;
|
||||
import com.sdm.common.utils.HpcCommandBuilderUtil;
|
||||
import com.sdm.common.utils.HpcCommandExcuteUtil;
|
||||
@@ -52,45 +56,43 @@ public class TaskServiceImpl implements TaskService {
|
||||
private static final long MAP_SIZE = 10 * 1024 * 1024;
|
||||
|
||||
@Override
|
||||
public SdmResponse nodeList(NodeListReq req) {
|
||||
public SdmResponse<NodeListResp> nodeList(NodeListReq req) {
|
||||
NodeListResp nodeListResp = new NodeListResp();
|
||||
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);
|
||||
List<NodeList> nodeList = HpcCommandResulParseUtil.parseNodList(result);
|
||||
nodeListResp.setNodes(nodeList);
|
||||
nodeListResp.setHpcCommand(nodeListCommand);
|
||||
return SdmResponse.success(nodeListResp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse nodeListCore(NodeListCoreReq req) {
|
||||
public SdmResponse<NodeListCoreResp> 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);
|
||||
List<NodeListCore> nodeListCore = HpcCommandResulParseUtil.parseNodeCoreList(result);
|
||||
NodeListCoreResp nodeListCoreResp = new NodeListCoreResp();
|
||||
nodeListCoreResp.setNodeCores(nodeListCore);
|
||||
nodeListCoreResp.setHpcCommand(nodeListCoreCommand);
|
||||
return SdmResponse.success(nodeListCoreResp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse nodeView(NodeViewReq req) {
|
||||
public SdmResponse<NodeViewResp> 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);
|
||||
nodeViewResp.setHpcCommand(nodeViewCommand);
|
||||
return SdmResponse.success(nodeViewResp);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user