Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature support grpc core #4204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion address/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion cmdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion consistency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<relativePath>../pom.xml</relativePath>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>nacos-console</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion istio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion naming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>2.0.0-ALPHA</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,21 @@
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.CommonParams;
import com.alibaba.nacos.api.naming.pojo.Cluster;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.utils.NamingUtils;
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.auth.common.ActionTypes;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.CatalogServiceV1Impl;
import com.alibaba.nacos.naming.core.CatalogServiceV2Impl;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.healthcheck.HealthCheckTask;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.pojo.ClusterInfo;
import com.alibaba.nacos.naming.pojo.IpAddressInfo;
import com.alibaba.nacos.naming.pojo.ServiceDetailInfo;
import com.alibaba.nacos.naming.pojo.ServiceView;
import com.alibaba.nacos.naming.web.NamingResourceParser;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -47,10 +42,6 @@
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand All @@ -66,6 +57,12 @@ public class CatalogController {
@Autowired
protected ServiceManager serviceManager;

@Autowired
private CatalogServiceV1Impl catalogServiceV1;

@Autowired
private CatalogServiceV2Impl catalogServiceV2;

/**
* Get service detail.
*
Expand All @@ -76,41 +73,11 @@ public class CatalogController {
*/
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ)
@GetMapping("/service")
public ObjectNode serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
public Object serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
String serviceName) throws NacosException {

Service detailedService = serviceManager.getService(namespaceId, serviceName);

if (detailedService == null) {
throw new NacosException(NacosException.NOT_FOUND, "service " + serviceName + " is not found!");
}
ObjectNode serviceObject = JacksonUtils.createEmptyJsonNode();
serviceObject.put("name", NamingUtils.getServiceName(serviceName));
serviceObject.put("protectThreshold", detailedService.getProtectThreshold());
serviceObject.put("groupName", NamingUtils.getGroupName(serviceName));
serviceObject.replace("selector", JacksonUtils.transferToJsonNode(detailedService.getSelector()));
serviceObject.replace("metadata", JacksonUtils.transferToJsonNode(detailedService.getMetadata()));

ObjectNode detailView = JacksonUtils.createEmptyJsonNode();
detailView.replace("service", serviceObject);

List<Cluster> clusters = new ArrayList<>();

for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) {
Cluster clusterView = new Cluster();
clusterView.setName(cluster.getName());
clusterView.setHealthChecker(cluster.getHealthChecker());
clusterView.setMetadata(cluster.getMetadata());
clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check());
clusterView.setDefaultPort(cluster.getDefaultPort());
clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort());
clusterView.setServiceName(cluster.getService().getName());
clusters.add(clusterView);
}

detailView.replace("clusters", JacksonUtils.transferToJsonNode(clusters));

return detailView;
String serviceNameWithoutGroup = NamingUtils.getServiceName(serviceName);
String groupName = NamingUtils.getGroupName(serviceName);
return catalogServiceV2.getServiceDetail(namespaceId, groupName, serviceNameWithoutGroup);
}

/**
Expand All @@ -129,18 +96,10 @@ public ObjectNode serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_N
public ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
@RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page,
@RequestParam int pageSize) throws NacosException {

Service service = serviceManager.getService(namespaceId, serviceName);
if (service == null) {
throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!");
}

if (!service.getClusterMap().containsKey(clusterName)) {
throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!");
}

List<Instance> instances = service.getClusterMap().get(clusterName).allIPs();

String serviceNameWithoutGroup = NamingUtils.getServiceName(serviceName);
String groupName = NamingUtils.getGroupName(serviceName);
List<? extends Instance> instances = catalogServiceV2
.listInstances(namespaceId, groupName, serviceNameWithoutGroup, clusterName);
int start = (page - 1) * pageSize;
int end = page * pageSize;

Expand Down Expand Up @@ -184,58 +143,13 @@ public Object listDetail(@RequestParam(required = false) boolean withInstances,
@RequestParam(name = "serviceNameParam", defaultValue = StringUtils.EMPTY) String serviceName,
@RequestParam(name = "groupNameParam", defaultValue = StringUtils.EMPTY) String groupName,
@RequestParam(name = "instance", defaultValue = StringUtils.EMPTY) String containedInstance,
@RequestParam(required = false) boolean hasIpCount) {

String param = StringUtils.isBlank(serviceName) && StringUtils.isBlank(groupName) ? StringUtils.EMPTY
: NamingUtils.getGroupedName(serviceName, groupName);
@RequestParam(required = false) boolean hasIpCount) throws NacosException {

if (withInstances) {
List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();

List<Service> services = new ArrayList<>(8);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, param, StringUtils.EMPTY, services, false);

for (Service service : services) {
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
serviceDetailInfo.setServiceName(NamingUtils.getServiceName(service.getName()));
serviceDetailInfo.setGroupName(NamingUtils.getGroupName(service.getName()));
serviceDetailInfo.setMetadata(service.getMetadata());

Map<String, ClusterInfo> clusterInfoMap = getStringClusterInfoMap(service);
serviceDetailInfo.setClusterMap(clusterInfoMap);

serviceDetailInfoList.add(serviceDetailInfo);
}

return serviceDetailInfoList;
}

ObjectNode result = JacksonUtils.createEmptyJsonNode();

List<Service> services = new ArrayList<>();
final int total = serviceManager.getPagedService(namespaceId, pageNo - 1, pageSize, param, containedInstance, services, hasIpCount);
if (CollectionUtils.isEmpty(services)) {
result.replace("serviceList", JacksonUtils.transferToJsonNode(Collections.emptyList()));
result.put("count", 0);
return result;
}

List<ServiceView> serviceViews = new LinkedList<>();
for (Service service : services) {
ServiceView serviceView = new ServiceView();
serviceView.setName(NamingUtils.getServiceName(service.getName()));
serviceView.setGroupName(NamingUtils.getGroupName(service.getName()));
serviceView.setClusterCount(service.getClusterMap().size());
serviceView.setIpCount(service.allIPs().size());
serviceView.setHealthyInstanceCount(service.healthyInstanceCount());
serviceView.setTriggerFlag(service.triggerFlag() ? "true" : "false");
serviceViews.add(serviceView);
return catalogServiceV2.pageListServiceDetail(namespaceId, groupName, serviceName, pageNo, pageSize);
}

result.replace("serviceList", JacksonUtils.transferToJsonNode(serviceViews));
result.put("count", total);

return result;
return catalogServiceV2
.pageListService(namespaceId, groupName, serviceName, pageNo, pageSize, containedInstance, hasIpCount);
}

/**
Expand Down Expand Up @@ -273,37 +187,4 @@ public ObjectNode rt4Service(HttpServletRequest request) {
result.replace("clusters", clusters);
return result;
}

private Map<String, ClusterInfo> getStringClusterInfoMap(Service service) {
Map<String, ClusterInfo> clusterInfoMap = new HashMap<>(8);

service.getClusterMap().forEach((clusterName, cluster) -> {

ClusterInfo clusterInfo = new ClusterInfo();
List<IpAddressInfo> ipAddressInfos = getIpAddressInfos(cluster.allIPs());
clusterInfo.setHosts(ipAddressInfos);
clusterInfoMap.put(clusterName, clusterInfo);

});
return clusterInfoMap;
}

private List<IpAddressInfo> getIpAddressInfos(List<Instance> instances) {
List<IpAddressInfo> ipAddressInfos = new ArrayList<>();

instances.forEach((ipAddress) -> {

IpAddressInfo ipAddressInfo = new IpAddressInfo();
ipAddressInfo.setIp(ipAddress.getIp());
ipAddressInfo.setPort(ipAddress.getPort());
ipAddressInfo.setMetadata(ipAddress.getMetadata());
ipAddressInfo.setValid(ipAddress.isHealthy());
ipAddressInfo.setWeight(ipAddress.getWeight());
ipAddressInfo.setEnabled(ipAddress.isEnabled());
ipAddressInfos.add(ipAddressInfo);

});
return ipAddressInfos;
}

}
Loading