#839 Rest of methods refactored.

This commit is contained in:
nkorange 2019-03-07 17:59:08 +08:00
parent 82ec466a8b
commit 4704200f87
21 changed files with 237 additions and 196 deletions

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.consistency.Datum;
import com.alibaba.nacos.naming.core.Instances; import com.alibaba.nacos.naming.core.Instances;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.ServerListManager;
import com.alibaba.nacos.naming.cluster.servers.Server; import com.alibaba.nacos.naming.cluster.servers.Server;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.common.Constants;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
/** /**
* A consistency protocol algorithm called <b>Partition</b> * A consistency protocol algorithm called <b>Partition</b>
* <p> * <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 * 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 * and synchronized by its responsible server. So every Nacos server only handles writings
* for a subset of the total service data. * for a subset of the total service data.
@ -54,8 +54,8 @@ import java.util.concurrent.ConcurrentHashMap;
* @author nkorange * @author nkorange
* @since 1.0.0 * @since 1.0.0
*/ */
@org.springframework.stereotype.Service("partitionConsistencyService") @org.springframework.stereotype.Service("distroConsistencyService")
public class PartitionConsistencyServiceImpl implements EphemeralConsistencyService { public class DistroConsistencyServiceImpl implements EphemeralConsistencyService {
@Autowired @Autowired
private DistroMapper distroMapper; private DistroMapper distroMapper;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -27,19 +27,19 @@ import org.springframework.stereotype.Component;
@Component @Component
public class PartitionConfig { public class PartitionConfig {
@Value("${nacos.naming.partition.taskDispatchPeriod}") @Value("${nacos.naming.distro.taskDispatchPeriod}")
private int taskDispatchPeriod = 2000; private int taskDispatchPeriod = 2000;
@Value("${nacos.naming.partition.batchSyncKeyCount}") @Value("${nacos.naming.distro.batchSyncKeyCount}")
private int batchSyncKeyCount = 1000; private int batchSyncKeyCount = 1000;
@Value("${nacos.naming.partition.initDataRatio}") @Value("${nacos.naming.distro.initDataRatio}")
private float initDataRatio = 0.9F; private float initDataRatio = 0.9F;
@Value("${nacos.naming.partition.syncRetryDelay}") @Value("${nacos.naming.distro.syncRetryDelay}")
private long syncRetryDelay = 5000L; private long syncRetryDelay = 5000L;
@Value("${nacos.naming.partition.taskDispatchThreadCount}") @Value("${nacos.naming.distro.taskDispatchThreadCount}")
private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors(); private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors();
public int getTaskDispatchPeriod() { public int getTaskDispatchPeriod() {

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.naming.consistency.ephemeral.partition; package com.alibaba.nacos.naming.consistency.ephemeral.distro;
import java.util.List; import java.util.List;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.cluster.servers.Server;
import com.alibaba.nacos.naming.misc.GlobalExecutor; import com.alibaba.nacos.naming.misc.GlobalExecutor;

View File

@ -35,6 +35,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.javatuples.Pair; import org.javatuples.Pair;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; 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_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() { private ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override @Override
@ -228,8 +229,7 @@ public class RaftCore {
if (!isLeader()) { if (!isLeader()) {
Map<String, String> params = new HashMap<>(1); Map<String, String> params = new HashMap<>(1);
params.put("key", URLEncoder.encode(key, "UTF-8")); params.put("key", URLEncoder.encode(key, "UTF-8"));
raftProxy.proxy(getLeader().ip, API_DEL, params, HttpMethod.DELETE);
raftProxy.proxyGET(getLeader().ip, API_DEL, params);
return; return;
} }
@ -244,7 +244,7 @@ public class RaftCore {
for (final String server : peers.allServersWithoutMySelf()) { for (final String server : peers.allServersWithoutMySelf()) {
String url = buildURL(server, API_ON_DEL); String url = buildURL(server, API_ON_DEL);
HttpClient.asyncHttpPostLarge(url, null, JSON.toJSONString(json) HttpClient.asyncHttpDeleteLarge(url, null, JSON.toJSONString(json)
, new AsyncCompletionHandler<Integer>() { , new AsyncCompletionHandler<Integer>() {
@Override @Override
public Integer onCompleted(Response response) throws Exception { public Integer onCompleted(Response response) throws Exception {

View File

@ -172,7 +172,7 @@ public class RaftPeerSet implements ServerChangeListener {
if (!Objects.equals(peer, candidate) && peer.state == RaftPeer.State.LEADER) { if (!Objects.equals(peer, candidate) && peer.state == RaftPeer.State.LEADER) {
try { try {
String url = RaftCore.buildURL(peer.ip, RaftCore.API_GET_PEER); 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 @Override
public Integer onCompleted(Response response) throws Exception { public Integer onCompleted(Response response) throws Exception {
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) { if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {

View File

@ -15,9 +15,11 @@
*/ */
package com.alibaba.nacos.naming.consistency.persistent.raft; 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.boot.RunningConfig;
import com.alibaba.nacos.naming.misc.HttpClient; import com.alibaba.nacos.naming.misc.HttpClient;
import com.alibaba.nacos.naming.misc.UtilsAndCommons; import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.net.HttpURLConnection; 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 { public void proxyPostLarge(String server, String api, String content, Map<String, String> headers) throws Exception {
// do proxy // do proxy
if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) { if (!server.contains(UtilsAndCommons.IP_PORT_SPLITER)) {

View File

@ -32,6 +32,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -49,54 +50,7 @@ public class CatalogController {
@Autowired @Autowired
protected ServiceManager serviceManager; protected ServiceManager serviceManager;
@RequestMapping(value = "/serviceList") @RequestMapping(value = "/service")
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")
public ServiceDetailView serviceDetail(HttpServletRequest request) throws Exception { public ServiceDetailView serviceDetail(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
@ -130,15 +84,15 @@ public class CatalogController {
return detailView; return detailView;
} }
@RequestMapping(value = "/instanceList") @RequestMapping(value = "/instances")
public JSONObject instanceList(HttpServletRequest request) throws Exception { public JSONObject instanceList(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID); Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME);
int page = Integer.parseInt(WebUtils.required(request, "startPg")); int page = Integer.parseInt(WebUtils.required(request, "pageNo"));
int pageSize = Integer.parseInt(WebUtils.required(request, "pgSize")); int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
Service service = serviceManager.getService(namespaceId, serviceName); Service service = serviceManager.getService(namespaceId, serviceName);
if (service == null) { if (service == null) {
@ -174,8 +128,11 @@ public class CatalogController {
} }
@RequestMapping(value = "/services", method = RequestMethod.GET) @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, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID); Constants.DEFAULT_NAMESPACE_ID);
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>(); List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
@ -197,14 +154,17 @@ public class CatalogController {
}); });
return serviceDetailInfoList; return serviceDetailInfoList;
} else {
return serviceList(request);
}
} }
@RequestMapping("/rt4Service") @RequestMapping("/rt/service")
public JSONObject rt4Service(HttpServletRequest request) { public JSONObject rt4Service(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID); Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName); Service service = serviceManager.getService(namespaceId, serviceName);
@ -231,38 +191,6 @@ public class CatalogController {
return result; 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 * getStringClusterInfoMap
* *
@ -307,4 +235,52 @@ public class CatalogController {
return ipAddressInfos; 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;
}
} }

View File

@ -21,8 +21,8 @@ import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.cluster.transport.Serializer; import com.alibaba.nacos.naming.cluster.transport.Serializer;
import com.alibaba.nacos.naming.consistency.Datum; import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder; import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.consistency.ephemeral.partition.DataStore; import com.alibaba.nacos.naming.consistency.ephemeral.distro.DataStore;
import com.alibaba.nacos.naming.consistency.ephemeral.partition.PartitionConsistencyServiceImpl; import com.alibaba.nacos.naming.consistency.ephemeral.distro.DistroConsistencyServiceImpl;
import com.alibaba.nacos.naming.core.Instances; import com.alibaba.nacos.naming.core.Instances;
import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.exception.NacosException; import com.alibaba.nacos.naming.exception.NacosException;
@ -48,14 +48,14 @@ import java.util.Map;
* @since 1.0.0 * @since 1.0.0
*/ */
@RestController @RestController
@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/partition") @RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/distro")
public class PartitionController { public class DistroController {
@Autowired @Autowired
private Serializer serializer; private Serializer serializer;
@Autowired @Autowired
private PartitionConsistencyServiceImpl consistencyService; private DistroConsistencyServiceImpl consistencyService;
@Autowired @Autowired
private DataStore dataStore; private DataStore dataStore;

View File

@ -68,7 +68,7 @@ public class HealthController {
return result; return result;
} }
@RequestMapping(value = "", method = RequestMethod.PUT) @RequestMapping(value = {"", "/instance"}, method = RequestMethod.PUT)
public String update(HttpServletRequest request) throws Exception { public String update(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,

View File

@ -52,7 +52,7 @@ import java.util.*;
* @author nkorange * @author nkorange
*/ */
@RestController @RestController
@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT) @RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance")
public class InstanceController { public class InstanceController {
@Autowired @Autowired
@ -89,7 +89,7 @@ public class InstanceController {
}; };
@CanDistro @CanDistro
@RequestMapping(value = "/instance", method = RequestMethod.POST) @RequestMapping(value = "", method = RequestMethod.POST)
public String register(HttpServletRequest request) throws Exception { public String register(HttpServletRequest request) throws Exception {
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
@ -100,7 +100,7 @@ public class InstanceController {
} }
@CanDistro @CanDistro
@RequestMapping(value = "/instance", method = RequestMethod.DELETE) @RequestMapping(value = "", method = RequestMethod.DELETE)
public String deregister(HttpServletRequest request) throws Exception { public String deregister(HttpServletRequest request) throws Exception {
Instance instance = getIPAddress(request); Instance instance = getIPAddress(request);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
@ -117,7 +117,7 @@ public class InstanceController {
return "ok"; return "ok";
} }
@RequestMapping(value = "/instance", method = RequestMethod.PUT) @RequestMapping(value = "", method = RequestMethod.PUT)
public String update(HttpServletRequest request) throws Exception { public String update(HttpServletRequest request) throws Exception {
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID); String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
@ -126,7 +126,7 @@ public class InstanceController {
return "ok"; return "ok";
} }
@RequestMapping(value = {"/instances", "/instance/list"}, method = RequestMethod.GET) @RequestMapping(value = "/list", method = RequestMethod.GET)
public JSONObject list(HttpServletRequest request) throws Exception { public JSONObject list(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, 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); 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 { public JSONObject detail(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
@ -194,7 +194,7 @@ public class InstanceController {
} }
@CanDistro @CanDistro
@RequestMapping(value = "/instance/beat", method = RequestMethod.PUT) @RequestMapping(value = "/beat", method = RequestMethod.PUT)
public JSONObject beat(HttpServletRequest request) throws Exception { public JSONObject beat(HttpServletRequest request) throws Exception {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
@ -254,7 +254,7 @@ public class InstanceController {
} }
@RequestMapping("/instance/listWithHealthStatus") @RequestMapping("/statuses")
public JSONObject listWithHealthStatus(HttpServletRequest request) throws NacosException { public JSONObject listWithHealthStatus(HttpServletRequest request) throws NacosException {
String key = WebUtils.required(request, "key"); String key = WebUtils.required(request, "key");

View File

@ -34,6 +34,7 @@ import com.alibaba.nacos.naming.push.PushService;
import com.alibaba.nacos.naming.web.NeedAuth; import com.alibaba.nacos.naming.web.NeedAuth;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -72,7 +73,7 @@ public class OperatorController {
@Autowired @Autowired
private DistroMapper distroMapper; private DistroMapper distroMapper;
@RequestMapping("/pushState") @RequestMapping("/push/state")
public JSONObject pushState(HttpServletRequest request) { public JSONObject pushState(HttpServletRequest request) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
@ -112,7 +113,7 @@ public class OperatorController {
return result; return result;
} }
@RequestMapping("/switches") @RequestMapping(value = "/switches", method = RequestMethod.GET)
public SwitchDomain switches(HttpServletRequest request) { public SwitchDomain switches(HttpServletRequest request) {
return switchDomain; return switchDomain;
} }
@ -152,12 +153,12 @@ public class OperatorController {
return result; return result;
} }
@RequestMapping("/getResponsibleServer4Dom") @RequestMapping(value = "/distro/server", method = RequestMethod.GET)
public JSONObject getResponsibleServer4Dom(HttpServletRequest request) { public JSONObject getResponsibleServer4Service(HttpServletRequest request) {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID); Constants.DEFAULT_NAMESPACE_ID);
String dom = WebUtils.required(request, "dom"); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, dom); Service service = serviceManager.getService(namespaceId, serviceName);
if (service == null) { if (service == null) {
throw new IllegalArgumentException("service not found"); throw new IllegalArgumentException("service not found");
@ -165,39 +166,12 @@ public class OperatorController {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("responsibleServer", distroMapper.mapSrv(dom)); result.put("responsibleServer", distroMapper.mapSrv(serviceName));
return result; return result;
} }
@RequestMapping("/getHealthyServerList") @RequestMapping(value = "/distro/status", method = RequestMethod.GET)
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")
public JSONObject distroStatus(HttpServletRequest request) { public JSONObject distroStatus(HttpServletRequest request) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
@ -216,7 +190,21 @@ public class OperatorController {
return result; 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) { public String serverStatus(HttpServletRequest request) {
String serverStatus = WebUtils.required(request, "serverStatus"); String serverStatus = WebUtils.required(request, "serverStatus");
serverListManager.onReceiveServerStatus(serverStatus); serverListManager.onReceiveServerStatus(serverStatus);

View File

@ -96,7 +96,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping("/getPeer") @RequestMapping(value = "/peer", method = RequestMethod.GET)
public JSONObject getPeer(HttpServletRequest request, HttpServletResponse response) { public JSONObject getPeer(HttpServletRequest request, HttpServletResponse response) {
List<RaftPeer> peers = raftCore.getPeers(); List<RaftPeer> peers = raftCore.getPeers();
RaftPeer peer = null; RaftPeer peer = null;
@ -116,7 +116,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping("/reloadDatum") @RequestMapping(value = "/datum/reload", method = RequestMethod.PUT)
public String reloadDatum(HttpServletRequest request, HttpServletResponse response) throws Exception { public String reloadDatum(HttpServletRequest request, HttpServletResponse response) throws Exception {
String key = WebUtils.required(request, "key"); String key = WebUtils.required(request, "key");
raftCore.loadDatum(key); raftCore.loadDatum(key);
@ -124,7 +124,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping(value = "/publish", method = RequestMethod.POST) @RequestMapping(value = "/datum", method = RequestMethod.POST)
public String publish(HttpServletRequest request, HttpServletResponse response) throws Exception { public String publish(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
@ -155,7 +155,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping(value = "/delete", method = RequestMethod.POST) @RequestMapping(value = "/datum", method = RequestMethod.DELETE)
public String delete(HttpServletRequest request, HttpServletResponse response) throws Exception { public String delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
@ -166,7 +166,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping("/get") @RequestMapping(value = "/datum", method = RequestMethod.GET)
public String get(HttpServletRequest request, HttpServletResponse response) throws Exception { public String get(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
@ -185,7 +185,7 @@ public class RaftController {
return JSON.toJSONString(datums); return JSON.toJSONString(datums);
} }
@RequestMapping("/state") @RequestMapping(value = "/state", method = RequestMethod.GET)
public JSONObject state(HttpServletRequest request, HttpServletResponse response) throws Exception { public JSONObject state(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
@ -200,7 +200,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping(value = "/onPublish", method = RequestMethod.POST) @RequestMapping(value = "/datum/commit", method = RequestMethod.POST)
public String onPublish(HttpServletRequest request, HttpServletResponse response) throws Exception { public String onPublish(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
@ -232,7 +232,7 @@ public class RaftController {
} }
@NeedAuth @NeedAuth
@RequestMapping(value = "/onDelete", method = RequestMethod.POST) @RequestMapping(value = "/datum/commit", method = RequestMethod.DELETE)
public String onDelete(HttpServletRequest request, HttpServletResponse response) throws Exception { public String onDelete(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request)); response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
@ -252,7 +252,7 @@ public class RaftController {
return "ok"; return "ok";
} }
@RequestMapping("/getLeader") @RequestMapping(value = "/leader", method = RequestMethod.GET)
public JSONObject getLeader(HttpServletRequest request, HttpServletResponse response) { public JSONObject getLeader(HttpServletRequest request, HttpServletResponse response) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
@ -260,7 +260,7 @@ public class RaftController {
return result; return result;
} }
@RequestMapping("/getAllListeners") @RequestMapping(value = "/listeners", method = RequestMethod.GET)
public JSONObject getAllListeners(HttpServletRequest request, HttpServletResponse response) { public JSONObject getAllListeners(HttpServletRequest request, HttpServletResponse response) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();

View File

@ -561,7 +561,7 @@ public class ServiceManager implements RecordListener<Service> {
return serviceMap.get(namespaceId); 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; List<Service> matchList;
@ -572,7 +572,34 @@ public class ServiceManager implements RecordListener<Service> {
if (StringUtils.isNotBlank(keyword)) { if (StringUtils.isNotBlank(keyword)) {
matchList = searchServices(namespaceId, ".*" + keyword + ".*"); matchList = searchServices(namespaceId, ".*" + keyword + ".*");
} else { } 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()) { if (pageSize >= matchList.size()) {

View File

@ -56,7 +56,7 @@ public class GlobalExecutor {
Thread t = new Thread(r); Thread t = new Thread(r);
t.setDaemon(true); t.setDaemon(true);
t.setName("com.alibaba.nacos.naming.partition.task.dispatcher"); t.setName("com.alibaba.nacos.naming.distro.task.dispatcher");
return t; return t;
} }
@ -70,7 +70,7 @@ public class GlobalExecutor {
Thread t = new Thread(r); Thread t = new Thread(r);
t.setDaemon(true); t.setDaemon(true);
t.setName("com.alibaba.nacos.naming.partition.data.syncer"); t.setName("com.alibaba.nacos.naming.distro.data.syncer");
return t; return t;
} }

View File

@ -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) { public static HttpResult httpPost(String url, List<String> headers, Map<String, String> paramValues) {
return httpPost(url, headers, paramValues, "UTF-8"); return httpPost(url, headers, paramValues, "UTF-8");
} }

View File

@ -31,13 +31,13 @@ import java.util.*;
*/ */
public class NamingProxy { 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) { public static void syncChecksums(Map<String, String> checksumMap, String server) {

View File

@ -62,7 +62,7 @@ public class UtilsAndCommons {
public static final String NACOS_NAMING_RAFT_CONTEXT = "/raft"; 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"; public static final String NACOS_NAMING_OPERATOR_CONTEXT = "/operator";

View File

@ -15,7 +15,6 @@
*/ */
package com.alibaba.nacos.naming.web; package com.alibaba.nacos.naming.web;
import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.controllers.*; import com.alibaba.nacos.naming.controllers.*;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -46,7 +45,7 @@ public class FilterBase {
initClassMethod(CatalogController.class); initClassMethod(CatalogController.class);
initClassMethod(HealthController.class); initClassMethod(HealthController.class);
initClassMethod(RaftController.class); initClassMethod(RaftController.class);
initClassMethod(PartitionController.class); initClassMethod(DistroController.class);
initClassMethod(OperatorController.class); initClassMethod(OperatorController.class);
} }