Merge remote-tracking branch 'upstream/develop' into develop
# Conflicts: # naming/src/main/java/com/alibaba/nacos/naming/controllers/OperatorController.java
This commit is contained in:
commit
977e2f76b7
@ -18,8 +18,8 @@ const request = () => {
|
||||
},
|
||||
error => {
|
||||
if (error.response) {
|
||||
const { status } = error.response;
|
||||
Message.error(`HTTP ERROR: ${status}`);
|
||||
const { data, status } = error.response;
|
||||
Message.error(data && typeof data === 'string' ? data : `HTTP ERROR: ${status}`);
|
||||
} else {
|
||||
Message.error(API_GENERAL_ERROR_MESSAGE);
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -137,6 +137,12 @@ public class DataSyncer {
|
||||
server.setServePort(Integer.parseInt(syncTask.getTargetServer().split(":")[1]));
|
||||
if (!getServers().contains(server)) {
|
||||
// if server is no longer in healthy server list, ignore this task:
|
||||
//fix #1665 remove existing tasks
|
||||
if (syncTask.getKeys() != null) {
|
||||
for (String key : syncTask.getKeys()) {
|
||||
taskMap.remove(buildKey(key, syncTask.getTargetServer()));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
@ -23,7 +24,6 @@ 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;
|
||||
@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -75,9 +76,6 @@ public class OperatorController {
|
||||
@Autowired
|
||||
private RaftCore raftCore;
|
||||
|
||||
@Autowired
|
||||
private RaftPeerSet raftPeerSet;
|
||||
|
||||
@RequestMapping("/push/state")
|
||||
public JSONObject pushState(@RequestParam(required = false) boolean detail, @RequestParam(required = false) boolean reset) {
|
||||
|
||||
@ -175,6 +173,7 @@ public class OperatorController {
|
||||
public JSONObject distroStatus(@RequestParam(defaultValue = "view") String action) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
String action = WebUtils.optional(request, "action", "view");
|
||||
|
||||
if (StringUtils.equals(SwitchEntry.ACTION_VIEW, action)) {
|
||||
result.put("status", serverListManager.getDistroConfig());
|
||||
@ -218,14 +217,16 @@ public class OperatorController {
|
||||
public Object listStates(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
|
||||
@RequestParam int pageNo,
|
||||
@RequestParam int pageSize,
|
||||
@RequestParam(defaultValue = StringUtils.EMPTY) String keyword,
|
||||
@RequestParam(defaultValue = StringUtils.EMPTY) String instance) {
|
||||
@RequestParam(defaultValue = StringUtils.EMPTY) String keyword) {
|
||||
|
||||
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);
|
||||
|
||||
List<RaftPeer> raftPeerLists = new ArrayList<>();
|
||||
|
||||
int total = serviceManager.getPagedClusterState(namespaceId, pageNo - 1, pageSize, keyword, instance, raftPeerLists, raftPeerSet);
|
||||
int total = serviceManager.getPagedClusterState(namespaceId, page - 1, pageSize, keyword, raftPeerLists);
|
||||
|
||||
if (CollectionUtils.isEmpty(raftPeerLists)) {
|
||||
result.put("clusterStateList", Collections.emptyList());
|
||||
@ -248,4 +249,13 @@ public class OperatorController {
|
||||
result.put("count", total);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cluster/state", method = RequestMethod.GET)
|
||||
public JSONObject getClusterStates() {
|
||||
|
||||
RaftPeer peer = serviceManager.getMySelfClusterState();
|
||||
|
||||
return JSON.parseObject(JSON.toJSONString(peer));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet;
|
||||
import com.alibaba.nacos.naming.misc.*;
|
||||
import com.alibaba.nacos.naming.push.PushService;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -83,6 +84,9 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
@Autowired
|
||||
private PushService pushService;
|
||||
|
||||
@Autowired
|
||||
private RaftPeerSet raftPeerSet;
|
||||
|
||||
private final Object putServiceLock = new Object();
|
||||
|
||||
@PostConstruct
|
||||
@ -230,10 +234,30 @@ 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());
|
||||
public int getPagedClusterState(String namespaceId, int startPage, int pageSize, String keyword, List<RaftPeer> raftPeerList) {
|
||||
|
||||
List<RaftPeer> matchList = new ArrayList<>();
|
||||
RaftPeer localRaftPeer = raftPeerSet.local();
|
||||
matchList.add(localRaftPeer);
|
||||
Set<String> otherServerSet = raftPeerSet.allServersWithoutMySelf();
|
||||
if (null != otherServerSet && otherServerSet.size() > 0) {
|
||||
for (String server: otherServerSet) {
|
||||
String path = UtilsAndCommons.NACOS_NAMING_OPERATOR_CONTEXT + UtilsAndCommons.NACOS_NAMING_CLUSTER_CONTEXT + "/state";
|
||||
Map<String, String> params = Maps.newHashMapWithExpectedSize(2);
|
||||
try {
|
||||
String content = NamingProxy.reqCommon(path, params, server, false);
|
||||
if (!StringUtils.EMPTY.equals(content)) {
|
||||
RaftPeer raftPeer = JSONObject.parseObject(content, RaftPeer.class);
|
||||
if (null != raftPeer) {
|
||||
matchList.add(raftPeer);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("[QUERY-CLUSTER-STATE] Exception while query cluster state from {}, error: {}",
|
||||
server, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<RaftPeer> tempList = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(keyword)) {
|
||||
for (RaftPeer raftPeer : matchList) {
|
||||
@ -265,6 +289,10 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
return matchList.size();
|
||||
}
|
||||
|
||||
public RaftPeer getMySelfClusterState() {
|
||||
return raftPeerSet.local();
|
||||
}
|
||||
|
||||
public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) {
|
||||
Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName));
|
||||
JSONObject serviceJson = JSON.parseObject(msg.getData());
|
||||
|
@ -215,6 +215,47 @@ public class NamingProxy {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
public static String reqCommon(String path, Map<String, String> params, String curServer, boolean isPost) throws Exception {
|
||||
try {
|
||||
List<String> headers = Arrays.asList("Client-Version", UtilsAndCommons.SERVER_VERSION,
|
||||
"User-Agent", UtilsAndCommons.SERVER_VERSION,
|
||||
"Accept-Encoding", "gzip,deflate,sdch",
|
||||
"Connection", "Keep-Alive",
|
||||
"Content-Encoding", "gzip");
|
||||
|
||||
|
||||
HttpClient.HttpResult result;
|
||||
|
||||
if (!curServer.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
|
||||
curServer = curServer + UtilsAndCommons.IP_PORT_SPLITER + RunningConfig.getServerPort();
|
||||
}
|
||||
|
||||
if (isPost) {
|
||||
result = HttpClient.httpPost("http://" + curServer + RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + path, headers, params);
|
||||
} else {
|
||||
result = HttpClient.httpGet("http://" + curServer + RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + path, headers, params);
|
||||
}
|
||||
|
||||
if (HttpURLConnection.HTTP_OK == result.code) {
|
||||
return result.content;
|
||||
}
|
||||
|
||||
if (HttpURLConnection.HTTP_NOT_MODIFIED == result.code) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
throw new IOException("failed to req API:" + "http://" + curServer
|
||||
+ RunningConfig.getContextPath()
|
||||
+ UtilsAndCommons.NACOS_NAMING_CONTEXT + path + ". code:"
|
||||
+ result.code + " msg: " + result.content);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("NamingProxy", e);
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
public static class Request {
|
||||
|
||||
private Map<String, String> params = new HashMap<>(8);
|
||||
|
Loading…
Reference in New Issue
Block a user