From 2ad31a50befe659d009aa1a3d145494cb9b28b73 Mon Sep 17 00:00:00 2001 From: xue_meng_en <1836611252@qq.com> Date: Mon, 19 Sep 2022 22:12:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E8=87=AA=E5=AE=9A=E4=B9=89=E8=B5=84=E6=BA=90=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../opengauss/cmrestapi/CMRestAPIServer.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opengauss/cmrestapi/CMRestAPIServer.java b/src/main/java/org/opengauss/cmrestapi/CMRestAPIServer.java index 804dbbc..18e541b 100644 --- a/src/main/java/org/opengauss/cmrestapi/CMRestAPIServer.java +++ b/src/main/java/org/opengauss/cmrestapi/CMRestAPIServer.java @@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import java.util.ArrayList; +import java.util.List; /** * @Title: CMRestAPIServer @@ -86,6 +87,23 @@ public class CMRestAPIServer { } } + /** + * @Title: DefResStatus + * @author: xuemengen + * @Description: Defined Resource State + * Created on: 2022/09/19 + */ + class DefResStatus { + int nodeId; + String resName; + String state; + public DefResStatus(int nodeId, String state, String resName) { + this.nodeId = nodeId; + this.state = state; + this.resName = resName; + } + } + /** * @Title: ClusterStatus * @author: xuemengen @@ -95,7 +113,8 @@ public class CMRestAPIServer { */ class ClusterStatus { String clusterState; - ArrayList nodesStatus; + List nodesStatus; + List defResStatus; } @PreDestroy @@ -198,12 +217,31 @@ public class CMRestAPIServer { .status(HttpStatus.INTERNAL_SERVER_ERROR) .body(msg); } - String[] nodesStatus = cmdResult.resultString.split("\\s+-+\\s+"); - String clusterState = CMRestAPI.matchRegex("cluster_state.*: (.*)\\s+", nodesStatus[0]); ClusterStatus clusterStatus = new ClusterStatus(); + String[] nodesStatus = cmdResult.resultString.split("\\s+-{70,}\\s+"); + int startPos = 0; + if (nodesStatus[0].contains("Defined Resource State")) { + startPos = 1; + // get defined resource state + clusterStatus.defResStatus = new ArrayList(); + String defResStatusString = nodesStatus[0].split("\\s+-+\\s+")[1]; + String[] resStateList = defResStatusString.split("\\r?\\n"); + for (String resState : resStateList) { + if (!resState.trim().isEmpty()) { + String[] items = resState.split("\\s+"); + int nodeId = Integer.parseInt(items[0]); + String resName = items[2]; + String state = items[4]; + clusterStatus.defResStatus.add(new DefResStatus(nodeId, state, resName)); + } + } + } else { + clusterStatus.defResStatus = null; + } + String clusterState = CMRestAPI.matchRegex("cluster_state.*: (.*)\\s+", nodesStatus[startPos]); clusterStatus.clusterState = clusterState; clusterStatus.nodesStatus = new ArrayList(); - for(int i = 1; i < nodesStatus.length; ++i) { + for(int i = startPos + 1; i < nodesStatus.length; ++i) { if (nodesStatus[i] != null && !nodesStatus[i].trim().isEmpty()) { String nodeIp = CMRestAPI.matchRegex("node_ip.*: (.*)\\s+", nodesStatus[i]); String cmServerState = CMRestAPI.matchRegex("type.*CMServer\\s+instance_state.*: (.*)\\s+", nodesStatus[i]); -- Gitee