#839 Rest of methods refactored.
This commit is contained in:
parent
82ec466a8b
commit
4704200f87
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.partition;
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.core.Instances;
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.partition;
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.cluster.servers.Server;
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.partition;
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* A consistency protocol algorithm called <b>Partition</b>
|
||||
* <p>
|
||||
* Use a partition algorithm to divide data into many blocks. Each Nacos server node takes
|
||||
* Use a distro algorithm to divide data into many blocks. Each Nacos server node takes
|
||||
* responsibility for exactly one block of data. Each block of data is generated, removed
|
||||
* and synchronized by its responsible server. So every Nacos server only handles writings
|
||||
* for a subset of the total service data.
|
||||
@ -54,8 +54,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@org.springframework.stereotype.Service("partitionConsistencyService")
|
||||
public class PartitionConsistencyServiceImpl implements EphemeralConsistencyService {
|
||||
@org.springframework.stereotype.Service("distroConsistencyService")
|
||||
public class DistroConsistencyServiceImpl implements EphemeralConsistencyService {
|
||||
|
||||
@Autowired
|
||||
private DistroMapper distroMapper;
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.partition;
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -27,19 +27,19 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class PartitionConfig {
|
||||
|
||||
@Value("${nacos.naming.partition.taskDispatchPeriod}")
|
||||
@Value("${nacos.naming.distro.taskDispatchPeriod}")
|
||||
private int taskDispatchPeriod = 2000;
|
||||
|
||||
@Value("${nacos.naming.partition.batchSyncKeyCount}")
|
||||
@Value("${nacos.naming.distro.batchSyncKeyCount}")
|
||||
private int batchSyncKeyCount = 1000;
|
||||
|
||||
@Value("${nacos.naming.partition.initDataRatio}")
|
||||
@Value("${nacos.naming.distro.initDataRatio}")
|
||||
private float initDataRatio = 0.9F;
|
||||
|
||||
@Value("${nacos.naming.partition.syncRetryDelay}")
|
||||
@Value("${nacos.naming.distro.syncRetryDelay}")
|
||||
private long syncRetryDelay = 5000L;
|
||||
|
||||
@Value("${nacos.naming.partition.taskDispatchThreadCount}")
|
||||
@Value("${nacos.naming.distro.taskDispatchThreadCount}")
|
||||
private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
public int getTaskDispatchPeriod() {
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.partition;
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.partition;
|
||||
package com.alibaba.nacos.naming.consistency.ephemeral.distro;
|
||||
|
||||
import com.alibaba.nacos.naming.cluster.servers.Server;
|
||||
import com.alibaba.nacos.naming.misc.GlobalExecutor;
|
@ -35,6 +35,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.javatuples.Pair;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@ -62,17 +63,17 @@ public class RaftCore {
|
||||
|
||||
public static final String API_BEAT = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/beat";
|
||||
|
||||
public static final String API_PUB = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/publish";
|
||||
public static final String API_PUB = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/datum";
|
||||
|
||||
public static final String API_DEL = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/delete";
|
||||
public static final String API_DEL = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/datum";
|
||||
|
||||
public static final String API_GET = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/get";
|
||||
public static final String API_GET = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/datum";
|
||||
|
||||
public static final String API_ON_PUB = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/onPublish";
|
||||
public static final String API_ON_PUB = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/datum/commit";
|
||||
|
||||
public static final String API_ON_DEL = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/onDelete";
|
||||
public static final String API_ON_DEL = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/datum/commit";
|
||||
|
||||
public static final String API_GET_PEER = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/getPeer";
|
||||
public static final String API_GET_PEER = UtilsAndCommons.NACOS_NAMING_CONTEXT + "/raft/peer";
|
||||
|
||||
private ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||
@Override
|
||||
@ -228,8 +229,7 @@ public class RaftCore {
|
||||
if (!isLeader()) {
|
||||
Map<String, String> params = new HashMap<>(1);
|
||||
params.put("key", URLEncoder.encode(key, "UTF-8"));
|
||||
|
||||
raftProxy.proxyGET(getLeader().ip, API_DEL, params);
|
||||
raftProxy.proxy(getLeader().ip, API_DEL, params, HttpMethod.DELETE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ public class RaftCore {
|
||||
|
||||
for (final String server : peers.allServersWithoutMySelf()) {
|
||||
String url = buildURL(server, API_ON_DEL);
|
||||
HttpClient.asyncHttpPostLarge(url, null, JSON.toJSONString(json)
|
||||
HttpClient.asyncHttpDeleteLarge(url, null, JSON.toJSONString(json)
|
||||
, new AsyncCompletionHandler<Integer>() {
|
||||
@Override
|
||||
public Integer onCompleted(Response response) throws Exception {
|
||||
|
@ -172,7 +172,7 @@ public class RaftPeerSet implements ServerChangeListener {
|
||||
if (!Objects.equals(peer, candidate) && peer.state == RaftPeer.State.LEADER) {
|
||||
try {
|
||||
String url = RaftCore.buildURL(peer.ip, RaftCore.API_GET_PEER);
|
||||
HttpClient.asyncHttpPost(url, null, params, new AsyncCompletionHandler<Integer>() {
|
||||
HttpClient.asyncHttpGet(url, null, params, new AsyncCompletionHandler<Integer>() {
|
||||
@Override
|
||||
public Integer onCompleted(Response response) throws Exception {
|
||||
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
|
||||
|
@ -15,9 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.consistency.persistent.raft;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||
import com.alibaba.nacos.naming.misc.HttpClient;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
@ -42,6 +44,32 @@ public class RaftProxy {
|
||||
}
|
||||
}
|
||||
|
||||
public void proxy(String server, String api, Map<String, String> params, HttpMethod method) throws Exception {
|
||||
// do proxy
|
||||
if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
|
||||
server = server + UtilsAndCommons.IP_PORT_SPLITER + RunningConfig.getServerPort();
|
||||
}
|
||||
String url = "http://" + server + RunningConfig.getContextPath() + api;
|
||||
HttpClient.HttpResult result;
|
||||
switch (method) {
|
||||
case GET:
|
||||
result = HttpClient.httpGet(url, null, params);
|
||||
break;
|
||||
case POST:
|
||||
result = HttpClient.httpPost(url, null, params);
|
||||
break;
|
||||
case DELETE:
|
||||
result = HttpClient.httpDelete(url, null, params);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("unsupported method:" + method);
|
||||
}
|
||||
|
||||
if (result.code != HttpURLConnection.HTTP_OK) {
|
||||
throw new IllegalStateException("leader failed, caused by: " + result.content);
|
||||
}
|
||||
}
|
||||
|
||||
public void proxyPostLarge(String server, String api, String content, Map<String, String> headers) throws Exception {
|
||||
// do proxy
|
||||
if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {
|
||||
|
@ -32,6 +32,7 @@ import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.map.HashedMap;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -49,54 +50,7 @@ public class CatalogController {
|
||||
@Autowired
|
||||
protected ServiceManager serviceManager;
|
||||
|
||||
@RequestMapping(value = "/serviceList")
|
||||
public JSONObject serviceList(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
int page = Integer.parseInt(WebUtils.required(request, "startPg"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pgSize"));
|
||||
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
|
||||
|
||||
List<Service> services = new ArrayList<>();
|
||||
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, services);
|
||||
|
||||
if (CollectionUtils.isEmpty(services)) {
|
||||
result.put("serviceList", Collections.emptyList());
|
||||
result.put("count", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray serviceJsonArray = new JSONArray();
|
||||
for (Service service : services) {
|
||||
ServiceView serviceView = new ServiceView();
|
||||
serviceView.setName(UtilsAndCommons.getServiceName(service.getName()));
|
||||
serviceView.setGroupName(UtilsAndCommons.getGroupName(service.getName()));
|
||||
serviceView.setClusterCount(service.getClusterMap().size());
|
||||
serviceView.setIpCount(service.allIPs().size());
|
||||
|
||||
// FIXME should be optimized:
|
||||
int validCount = 0;
|
||||
for (Instance instance : service.allIPs()) {
|
||||
if (instance.isHealthy()) {
|
||||
validCount++;
|
||||
}
|
||||
}
|
||||
|
||||
serviceView.setHealthyInstanceCount(validCount);
|
||||
|
||||
serviceJsonArray.add(serviceView);
|
||||
}
|
||||
|
||||
result.put("serviceList", serviceJsonArray);
|
||||
result.put("count", total);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/serviceDetail")
|
||||
@RequestMapping(value = "/service")
|
||||
public ServiceDetailView serviceDetail(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
@ -130,15 +84,15 @@ public class CatalogController {
|
||||
return detailView;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/instanceList")
|
||||
@RequestMapping(value = "/instances")
|
||||
public JSONObject instanceList(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME);
|
||||
int page = Integer.parseInt(WebUtils.required(request, "startPg"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pgSize"));
|
||||
int page = Integer.parseInt(WebUtils.required(request, "pageNo"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
|
||||
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
if (service == null) {
|
||||
@ -174,8 +128,11 @@ public class CatalogController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/services", method = RequestMethod.GET)
|
||||
public List<ServiceDetailInfo> listDetail(HttpServletRequest request) {
|
||||
public Object listDetail(HttpServletRequest request) throws Exception {
|
||||
|
||||
boolean withInstances = Boolean.parseBoolean(WebUtils.optional(request, "withInstances", "true"));
|
||||
|
||||
if (withInstances) {
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
|
||||
@ -197,14 +154,17 @@ public class CatalogController {
|
||||
});
|
||||
|
||||
return serviceDetailInfoList;
|
||||
|
||||
} else {
|
||||
return serviceList(request);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/rt4Service")
|
||||
@RequestMapping("/rt/service")
|
||||
public JSONObject rt4Service(HttpServletRequest request) {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
@ -231,38 +191,6 @@ public class CatalogController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/getServicesByIP")
|
||||
public JSONObject getServicesByIP(HttpServletRequest request) {
|
||||
String ip = WebUtils.required(request, "ip");
|
||||
|
||||
Set<String> serviceNames = new HashSet<>();
|
||||
Map<String, Set<String>> serviceNameMap = serviceManager.getAllServiceNames();
|
||||
|
||||
for (String namespaceId : serviceNameMap.keySet()) {
|
||||
for (String serviceName : serviceNameMap.get(namespaceId)) {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
List<Instance> instances = service.allIPs();
|
||||
for (Instance instance : instances) {
|
||||
if (ip.contains(":")) {
|
||||
if (StringUtils.equals(instance.getIp() + ":" + instance.getPort(), ip)) {
|
||||
serviceNames.add(namespaceId + UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR + service.getName());
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.equals(instance.getIp(), ip)) {
|
||||
serviceNames.add(namespaceId + UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR + service.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put("doms", serviceNames);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* getStringClusterInfoMap
|
||||
*
|
||||
@ -307,4 +235,52 @@ public class CatalogController {
|
||||
return ipAddressInfos;
|
||||
}
|
||||
|
||||
private JSONObject serviceList(HttpServletRequest request) throws Exception {
|
||||
|
||||
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.required(request, "instance");
|
||||
|
||||
List<Service> services = new ArrayList<>();
|
||||
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services);
|
||||
|
||||
if (CollectionUtils.isEmpty(services)) {
|
||||
result.put("serviceList", Collections.emptyList());
|
||||
result.put("count", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray serviceJsonArray = new JSONArray();
|
||||
for (Service service : services) {
|
||||
ServiceView serviceView = new ServiceView();
|
||||
serviceView.setName(UtilsAndCommons.getServiceName(service.getName()));
|
||||
serviceView.setGroupName(UtilsAndCommons.getGroupName(service.getName()));
|
||||
serviceView.setClusterCount(service.getClusterMap().size());
|
||||
serviceView.setIpCount(service.allIPs().size());
|
||||
|
||||
// FIXME should be optimized:
|
||||
int validCount = 0;
|
||||
for (Instance instance : service.allIPs()) {
|
||||
if (instance.isHealthy()) {
|
||||
validCount++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
serviceView.setHealthyInstanceCount(validCount);
|
||||
|
||||
serviceJsonArray.add(serviceView);
|
||||
}
|
||||
|
||||
result.put("serviceList", serviceJsonArray);
|
||||
result.put("count", total);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import com.alibaba.nacos.naming.cluster.ServerMode;
|
||||
import com.alibaba.nacos.naming.cluster.transport.Serializer;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.consistency.ephemeral.partition.DataStore;
|
||||
import com.alibaba.nacos.naming.consistency.ephemeral.partition.PartitionConsistencyServiceImpl;
|
||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.DataStore;
|
||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.DistroConsistencyServiceImpl;
|
||||
import com.alibaba.nacos.naming.core.Instances;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
@ -48,14 +48,14 @@ import java.util.Map;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/partition")
|
||||
public class PartitionController {
|
||||
@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/distro")
|
||||
public class DistroController {
|
||||
|
||||
@Autowired
|
||||
private Serializer serializer;
|
||||
|
||||
@Autowired
|
||||
private PartitionConsistencyServiceImpl consistencyService;
|
||||
private DistroConsistencyServiceImpl consistencyService;
|
||||
|
||||
@Autowired
|
||||
private DataStore dataStore;
|
@ -68,7 +68,7 @@ public class HealthController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.PUT)
|
||||
@RequestMapping(value = {"", "/instance"}, method = RequestMethod.PUT)
|
||||
public String update(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
|
@ -52,7 +52,7 @@ import java.util.*;
|
||||
* @author nkorange
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT)
|
||||
@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance")
|
||||
public class InstanceController {
|
||||
|
||||
@Autowired
|
||||
@ -89,7 +89,7 @@ public class InstanceController {
|
||||
};
|
||||
|
||||
@CanDistro
|
||||
@RequestMapping(value = "/instance", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public String register(HttpServletRequest request) throws Exception {
|
||||
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
@ -100,7 +100,7 @@ public class InstanceController {
|
||||
}
|
||||
|
||||
@CanDistro
|
||||
@RequestMapping(value = "/instance", method = RequestMethod.DELETE)
|
||||
@RequestMapping(value = "", method = RequestMethod.DELETE)
|
||||
public String deregister(HttpServletRequest request) throws Exception {
|
||||
Instance instance = getIPAddress(request);
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
@ -117,7 +117,7 @@ public class InstanceController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/instance", method = RequestMethod.PUT)
|
||||
@RequestMapping(value = "", method = RequestMethod.PUT)
|
||||
public String update(HttpServletRequest request) throws Exception {
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
|
||||
@ -126,7 +126,7 @@ public class InstanceController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/instances", "/instance/list"}, method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public JSONObject list(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
@ -152,7 +152,7 @@ public class InstanceController {
|
||||
return doSrvIPXT(namespaceId, serviceName, agent, clusters, clientIP, udpPort, env, isCheck, app, tenant, healthyOnly);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/instance", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
public JSONObject detail(HttpServletRequest request) throws Exception {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
@ -194,7 +194,7 @@ public class InstanceController {
|
||||
}
|
||||
|
||||
@CanDistro
|
||||
@RequestMapping(value = "/instance/beat", method = RequestMethod.PUT)
|
||||
@RequestMapping(value = "/beat", method = RequestMethod.PUT)
|
||||
public JSONObject beat(HttpServletRequest request) throws Exception {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
@ -254,7 +254,7 @@ public class InstanceController {
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/instance/listWithHealthStatus")
|
||||
@RequestMapping("/statuses")
|
||||
public JSONObject listWithHealthStatus(HttpServletRequest request) throws NacosException {
|
||||
|
||||
String key = WebUtils.required(request, "key");
|
||||
|
@ -34,6 +34,7 @@ import com.alibaba.nacos.naming.push.PushService;
|
||||
import com.alibaba.nacos.naming.web.NeedAuth;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -72,7 +73,7 @@ public class OperatorController {
|
||||
@Autowired
|
||||
private DistroMapper distroMapper;
|
||||
|
||||
@RequestMapping("/pushState")
|
||||
@RequestMapping("/push/state")
|
||||
public JSONObject pushState(HttpServletRequest request) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
@ -112,7 +113,7 @@ public class OperatorController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/switches")
|
||||
@RequestMapping(value = "/switches", method = RequestMethod.GET)
|
||||
public SwitchDomain switches(HttpServletRequest request) {
|
||||
return switchDomain;
|
||||
}
|
||||
@ -152,12 +153,12 @@ public class OperatorController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/getResponsibleServer4Dom")
|
||||
public JSONObject getResponsibleServer4Dom(HttpServletRequest request) {
|
||||
@RequestMapping(value = "/distro/server", method = RequestMethod.GET)
|
||||
public JSONObject getResponsibleServer4Service(HttpServletRequest request) {
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String dom = WebUtils.required(request, "dom");
|
||||
Service service = serviceManager.getService(namespaceId, dom);
|
||||
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("service not found");
|
||||
@ -165,39 +166,12 @@ public class OperatorController {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put("responsibleServer", distroMapper.mapSrv(dom));
|
||||
result.put("responsibleServer", distroMapper.mapSrv(serviceName));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/getHealthyServerList")
|
||||
public JSONObject getHealthyServerList(HttpServletRequest request) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("healthyList", distroMapper.getHealthyList());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/responsible")
|
||||
public JSONObject responsible(HttpServletRequest request) {
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
String dom = WebUtils.required(request, "dom");
|
||||
Service service = serviceManager.getService(namespaceId, dom);
|
||||
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("service not found");
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
result.put("responsible", distroMapper.responsible(dom));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/distroStatus")
|
||||
@RequestMapping(value = "/distro/status", method = RequestMethod.GET)
|
||||
public JSONObject distroStatus(HttpServletRequest request) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
@ -216,7 +190,21 @@ public class OperatorController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/serverStatus")
|
||||
@RequestMapping(value = "/servers", method = RequestMethod.GET)
|
||||
public JSONObject getHealthyServerList(HttpServletRequest request) {
|
||||
|
||||
boolean healthy = Boolean.parseBoolean(WebUtils.optional(request, "healthy", "false"));
|
||||
JSONObject result = new JSONObject();
|
||||
if (healthy) {
|
||||
result.put("servers", serverListManager.getHealthyServers());
|
||||
} else {
|
||||
result.put("servers", serverListManager.getServers());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/server/status")
|
||||
public String serverStatus(HttpServletRequest request) {
|
||||
String serverStatus = WebUtils.required(request, "serverStatus");
|
||||
serverListManager.onReceiveServerStatus(serverStatus);
|
||||
|
@ -96,7 +96,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping("/getPeer")
|
||||
@RequestMapping(value = "/peer", method = RequestMethod.GET)
|
||||
public JSONObject getPeer(HttpServletRequest request, HttpServletResponse response) {
|
||||
List<RaftPeer> peers = raftCore.getPeers();
|
||||
RaftPeer peer = null;
|
||||
@ -116,7 +116,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping("/reloadDatum")
|
||||
@RequestMapping(value = "/datum/reload", method = RequestMethod.PUT)
|
||||
public String reloadDatum(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
String key = WebUtils.required(request, "key");
|
||||
raftCore.loadDatum(key);
|
||||
@ -124,7 +124,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping(value = "/publish", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/datum", method = RequestMethod.POST)
|
||||
public String publish(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
|
||||
@ -155,7 +155,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/datum", method = RequestMethod.DELETE)
|
||||
public String delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
|
||||
@ -166,7 +166,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping("/get")
|
||||
@RequestMapping(value = "/datum", method = RequestMethod.GET)
|
||||
public String get(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
|
||||
@ -185,7 +185,7 @@ public class RaftController {
|
||||
return JSON.toJSONString(datums);
|
||||
}
|
||||
|
||||
@RequestMapping("/state")
|
||||
@RequestMapping(value = "/state", method = RequestMethod.GET)
|
||||
public JSONObject state(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
|
||||
@ -200,7 +200,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping(value = "/onPublish", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/datum/commit", method = RequestMethod.POST)
|
||||
public String onPublish(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
|
||||
@ -232,7 +232,7 @@ public class RaftController {
|
||||
}
|
||||
|
||||
@NeedAuth
|
||||
@RequestMapping(value = "/onDelete", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/datum/commit", method = RequestMethod.DELETE)
|
||||
public String onDelete(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
|
||||
@ -252,7 +252,7 @@ public class RaftController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping("/getLeader")
|
||||
@RequestMapping(value = "/leader", method = RequestMethod.GET)
|
||||
public JSONObject getLeader(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
@ -260,7 +260,7 @@ public class RaftController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping("/getAllListeners")
|
||||
@RequestMapping(value = "/listeners", method = RequestMethod.GET)
|
||||
public JSONObject getAllListeners(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
|
@ -561,7 +561,7 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
return serviceMap.get(namespaceId);
|
||||
}
|
||||
|
||||
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, List<Service> serviceList) {
|
||||
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<Service> serviceList) {
|
||||
|
||||
List<Service> matchList;
|
||||
|
||||
@ -572,7 +572,34 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
if (StringUtils.isNotBlank(keyword)) {
|
||||
matchList = searchServices(namespaceId, ".*" + keyword + ".*");
|
||||
} else {
|
||||
matchList = new ArrayList<Service>(chooseServiceMap(namespaceId).values());
|
||||
matchList = new ArrayList<>(chooseServiceMap(namespaceId).values());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(containedInstance)) {
|
||||
|
||||
boolean contained;
|
||||
for (int i = 0; i < matchList.size(); i++) {
|
||||
Service service = matchList.get(i);
|
||||
contained = false;
|
||||
List<Instance> instances = service.allIPs();
|
||||
for (Instance instance : instances) {
|
||||
if (containedInstance.contains(":")) {
|
||||
if (StringUtils.equals(instance.getIp() + ":" + instance.getPort(), containedInstance)) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.equals(instance.getIp(), containedInstance)) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!contained) {
|
||||
matchList.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pageSize >= matchList.size()) {
|
||||
|
@ -56,7 +56,7 @@ public class GlobalExecutor {
|
||||
Thread t = new Thread(r);
|
||||
|
||||
t.setDaemon(true);
|
||||
t.setName("com.alibaba.nacos.naming.partition.task.dispatcher");
|
||||
t.setName("com.alibaba.nacos.naming.distro.task.dispatcher");
|
||||
|
||||
return t;
|
||||
}
|
||||
@ -70,7 +70,7 @@ public class GlobalExecutor {
|
||||
Thread t = new Thread(r);
|
||||
|
||||
t.setDaemon(true);
|
||||
t.setName("com.alibaba.nacos.naming.partition.data.syncer");
|
||||
t.setName("com.alibaba.nacos.naming.distro.data.syncer");
|
||||
|
||||
return t;
|
||||
}
|
||||
|
@ -200,6 +200,29 @@ public class HttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
public static void asyncHttpDeleteLarge(String url, List<String> headers, String content, AsyncCompletionHandler handler) throws Exception {
|
||||
AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.prepareDelete(url);
|
||||
|
||||
if (!CollectionUtils.isEmpty(headers)) {
|
||||
for (String header : headers) {
|
||||
builder.setHeader(header.split("=")[0], header.split("=")[1]);
|
||||
}
|
||||
}
|
||||
|
||||
builder.setBody(content.getBytes());
|
||||
|
||||
builder.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
builder.setHeader("Accept-Charset", "UTF-8");
|
||||
builder.setHeader("Accept-Encoding", "gzip");
|
||||
builder.setHeader("Content-Encoding", "gzip");
|
||||
|
||||
if (handler != null) {
|
||||
builder.execute(handler);
|
||||
} else {
|
||||
builder.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpResult httpPost(String url, List<String> headers, Map<String, String> paramValues) {
|
||||
return httpPost(url, headers, paramValues, "UTF-8");
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ import java.util.*;
|
||||
*/
|
||||
public class NamingProxy {
|
||||
|
||||
private static final String DATA_ON_SYNC_URL = "/partition/datum";
|
||||
private static final String DATA_ON_SYNC_URL = "/distro/datum";
|
||||
|
||||
private static final String DATA_GET_URL = "/partition/datum";
|
||||
private static final String DATA_GET_URL = "/distro/datum";
|
||||
|
||||
private static final String ALL_DATA_GET_URL = "/partition/datums";
|
||||
private static final String ALL_DATA_GET_URL = "/distro/datums";
|
||||
|
||||
private static final String TIMESTAMP_SYNC_URL = "/partition/checksum";
|
||||
private static final String TIMESTAMP_SYNC_URL = "/distro/checksum";
|
||||
|
||||
public static void syncChecksums(Map<String, String> checksumMap, String server) {
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class UtilsAndCommons {
|
||||
|
||||
public static final String NACOS_NAMING_RAFT_CONTEXT = "/raft";
|
||||
|
||||
public static final String NACOS_NAMING_PARTITION_CONTEXT = "/partition";
|
||||
public static final String NACOS_NAMING_PARTITION_CONTEXT = "/distro";
|
||||
|
||||
public static final String NACOS_NAMING_OPERATOR_CONTEXT = "/operator";
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.web;
|
||||
|
||||
import com.alibaba.nacos.naming.boot.RunningConfig;
|
||||
import com.alibaba.nacos.naming.controllers.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -46,7 +45,7 @@ public class FilterBase {
|
||||
initClassMethod(CatalogController.class);
|
||||
initClassMethod(HealthController.class);
|
||||
initClassMethod(RaftController.class);
|
||||
initClassMethod(PartitionController.class);
|
||||
initClassMethod(DistroController.class);
|
||||
initClassMethod(OperatorController.class);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user