chore(clusterNode): adjust some code
This commit is contained in:
parent
4fe09db8ab
commit
d08557a725
@ -99,8 +99,8 @@ const I18N_CONF = {
|
||||
pubNoData: 'No results found.',
|
||||
nodeState: 'NodeState',
|
||||
clusterTerm: 'ClusterTerm',
|
||||
leaderDueMs: 'LeaderDueMs',
|
||||
heartbeatDueMs: 'HeartbeatDueMs',
|
||||
leaderDueMs: 'LeaderDue(ms)',
|
||||
heartbeatDueMs: 'HeartbeatDue(ms)',
|
||||
voteFor: 'VoteFor',
|
||||
},
|
||||
EditClusterDialog: {
|
||||
|
@ -99,8 +99,8 @@ const I18N_CONF = {
|
||||
pubNoData: '没有数据',
|
||||
nodeState: '节点状态',
|
||||
clusterTerm: '集群任期',
|
||||
leaderDueMs: 'Leader止时',
|
||||
heartbeatDueMs: '心跳止时',
|
||||
leaderDueMs: 'Leader止时(ms)',
|
||||
heartbeatDueMs: '心跳止时(ms)',
|
||||
voteFor: '投票对象',
|
||||
},
|
||||
EditClusterDialog: {
|
||||
|
@ -77,7 +77,7 @@ class ClusterNodeList extends React.Component {
|
||||
`keyword=${keyword}`,
|
||||
];
|
||||
request({
|
||||
url: `v1/ns/cluster/states?${parameter.join('&')}`,
|
||||
url: `v1/ns/operator/cluster/states?${parameter.join('&')}`,
|
||||
beforeSend: () => this.openLoading(),
|
||||
success: ({ count = 0, clusterStateList = [] } = {}) => {
|
||||
this.setState({
|
||||
|
@ -56,9 +56,6 @@ public class ClusterController {
|
||||
@Autowired
|
||||
protected ServiceManager serviceManager;
|
||||
|
||||
@Autowired
|
||||
private RaftPeerSet raftPeerSet;
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.PUT)
|
||||
public String update(HttpServletRequest request) throws Exception {
|
||||
|
||||
@ -107,41 +104,4 @@ public class ClusterController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/states", method = RequestMethod.GET)
|
||||
public Object listStates(HttpServletRequest request) {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
JSONObject result = new JSONObject();
|
||||
int page = Integer.parseInt(WebUtils.required(request, "pageNo"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
|
||||
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
|
||||
String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY);
|
||||
|
||||
List<RaftPeer> raftPeerLists = new ArrayList<>();
|
||||
|
||||
int total = serviceManager.getPagedClusterState(namespaceId, page - 1, pageSize, keyword, containedInstance, raftPeerLists, raftPeerSet);
|
||||
|
||||
if (CollectionUtils.isEmpty(raftPeerLists)) {
|
||||
result.put("clusterStateList", Collections.emptyList());
|
||||
result.put("count", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray clusterStateJsonArray = new JSONArray();
|
||||
for(RaftPeer raftPeer: raftPeerLists) {
|
||||
ClusterStateView clusterStateView = new ClusterStateView();
|
||||
clusterStateView.setClusterTerm(raftPeer.term.intValue());
|
||||
clusterStateView.setNodeIp(raftPeer.ip);
|
||||
clusterStateView.setNodeState(raftPeer.state.name());
|
||||
clusterStateView.setVoteFor(raftPeer.voteFor);
|
||||
clusterStateView.setHeartbeatDueMs(raftPeer.heartbeatDueMs);
|
||||
clusterStateView.setLeaderDueMs(raftPeer.leaderDueMs);
|
||||
clusterStateJsonArray.add(clusterStateView);
|
||||
}
|
||||
result.put("clusterStateList", clusterStateJsonArray);
|
||||
result.put("count", total);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.cluster.ServerStatusManager;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftCore;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet;
|
||||
import com.alibaba.nacos.naming.core.DistroMapper;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
@ -31,8 +33,10 @@ import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.misc.SwitchEntry;
|
||||
import com.alibaba.nacos.naming.misc.SwitchManager;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.ClusterStateView;
|
||||
import com.alibaba.nacos.naming.push.PushService;
|
||||
import com.alibaba.nacos.naming.web.NeedAuth;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
|
||||
@ -42,6 +46,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -77,6 +83,9 @@ public class OperatorController {
|
||||
@Autowired
|
||||
private RaftCore raftCore;
|
||||
|
||||
@Autowired
|
||||
private RaftPeerSet raftPeerSet;
|
||||
|
||||
@RequestMapping("/push/state")
|
||||
public JSONObject pushState(HttpServletRequest request) {
|
||||
|
||||
@ -215,4 +224,41 @@ public class OperatorController {
|
||||
serverListManager.onReceiveServerStatus(serverStatus);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cluster/states", method = RequestMethod.GET)
|
||||
public Object listStates(HttpServletRequest request) {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
JSONObject result = new JSONObject();
|
||||
int page = Integer.parseInt(WebUtils.required(request, "pageNo"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
|
||||
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
|
||||
String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY);
|
||||
|
||||
List<RaftPeer> raftPeerLists = new ArrayList<>();
|
||||
|
||||
int total = serviceManager.getPagedClusterState(namespaceId, page - 1, pageSize, keyword, containedInstance, raftPeerLists, raftPeerSet);
|
||||
|
||||
if (CollectionUtils.isEmpty(raftPeerLists)) {
|
||||
result.put("clusterStateList", Collections.emptyList());
|
||||
result.put("count", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray clusterStateJsonArray = new JSONArray();
|
||||
for(RaftPeer raftPeer: raftPeerLists) {
|
||||
ClusterStateView clusterStateView = new ClusterStateView();
|
||||
clusterStateView.setClusterTerm(raftPeer.term.intValue());
|
||||
clusterStateView.setNodeIp(raftPeer.ip);
|
||||
clusterStateView.setNodeState(raftPeer.state.name());
|
||||
clusterStateView.setVoteFor(raftPeer.voteFor);
|
||||
clusterStateView.setHeartbeatDueMs(raftPeer.heartbeatDueMs);
|
||||
clusterStateView.setLeaderDueMs(raftPeer.leaderDueMs);
|
||||
clusterStateJsonArray.add(clusterStateView);
|
||||
}
|
||||
result.put("clusterStateList", clusterStateJsonArray);
|
||||
result.put("count", total);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -229,6 +229,41 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
}
|
||||
}
|
||||
|
||||
public int getPagedClusterState(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<RaftPeer> raftPeerList, RaftPeerSet raftPeerSet) {
|
||||
|
||||
List<RaftPeer> matchList = new ArrayList<>(raftPeerSet.allPeers());
|
||||
|
||||
List<RaftPeer> tempList = new ArrayList<>();
|
||||
if(StringUtils.isNotBlank(keyword)) {
|
||||
for(RaftPeer raftPeer: matchList) {
|
||||
String ip = raftPeer.ip.split(":")[0];
|
||||
if(keyword.equals(ip)) {
|
||||
tempList.add(raftPeer);
|
||||
}
|
||||
}
|
||||
matchList = tempList;
|
||||
}
|
||||
|
||||
if (pageSize >= matchList.size()) {
|
||||
raftPeerList.addAll(matchList);
|
||||
return matchList.size();
|
||||
}
|
||||
|
||||
for (int i = 0; i < matchList.size(); i++) {
|
||||
if (i < startPage * pageSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
raftPeerList.add(matchList.get(i));
|
||||
|
||||
if (raftPeerList.size() >= pageSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matchList.size();
|
||||
}
|
||||
|
||||
public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) {
|
||||
Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName));
|
||||
JSONObject serviceJson = JSON.parseObject(msg.getData());
|
||||
@ -651,41 +686,6 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
return matchList.size();
|
||||
}
|
||||
|
||||
public int getPagedClusterState(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<RaftPeer> raftPeerList, RaftPeerSet raftPeerSet) {
|
||||
|
||||
List<RaftPeer> matchList = new ArrayList<>(raftPeerSet.allPeers());
|
||||
|
||||
List<RaftPeer> tempList = new ArrayList<>();
|
||||
if(StringUtils.isNotBlank(keyword)) {
|
||||
for(RaftPeer raftPeer: matchList) {
|
||||
String ip = raftPeer.ip.split(":")[0];
|
||||
if(keyword.equals(ip)) {
|
||||
tempList.add(raftPeer);
|
||||
}
|
||||
}
|
||||
matchList = tempList;
|
||||
}
|
||||
|
||||
if (pageSize >= matchList.size()) {
|
||||
raftPeerList.addAll(matchList);
|
||||
return matchList.size();
|
||||
}
|
||||
|
||||
for (int i = 0; i < matchList.size(); i++) {
|
||||
if (i < startPage * pageSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
raftPeerList.add(matchList.get(i));
|
||||
|
||||
if (raftPeerList.size() >= pageSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matchList.size();
|
||||
}
|
||||
|
||||
public static class ServiceChecksum {
|
||||
|
||||
public String namespaceId;
|
||||
|
Loading…
Reference in New Issue
Block a user