后端支持

This commit is contained in:
赵禹光 2019-07-31 21:03:49 +08:00
parent b10402a6a8
commit ee0c469471
4 changed files with 17 additions and 17 deletions

View File

@ -153,7 +153,7 @@ public class CatalogController {
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
List<Service> serviceList = new ArrayList<>(8);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList);
serviceManager.getPagedService(namespaceId, pageNo, pageSize, keyword, StringUtils.EMPTY, serviceList, false);
for (Service service : serviceList) {
ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
@ -259,9 +259,10 @@ public class CatalogController {
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
String keyword = WebUtils.optional(request, "keyword", StringUtils.EMPTY);
String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY);
boolean hasIpCount = Boolean.parseBoolean(WebUtils.optional(request, "hasIpCount", "false"));
List<Service> services = new ArrayList<>();
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services);
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, keyword, containedInstance, services, hasIpCount);
if (CollectionUtils.isEmpty(services)) {
result.put("serviceList", Collections.emptyList());

View File

@ -269,10 +269,10 @@ public class ServiceController {
Map<String, List<Service>> services = new HashMap<>(16);
if (StringUtils.isNotBlank(namespaceId)) {
services.put(namespaceId, serviceManager.searchServices(namespaceId, ".*" + expr + ".*"));
services.put(namespaceId, serviceManager.searchServices(namespaceId, ".*" + expr + ".*", false));
} else {
for (String namespace : serviceManager.getAllNamespaces()) {
services.put(namespace, serviceManager.searchServices(namespace, ".*" + expr + ".*"));
services.put(namespace, serviceManager.searchServices(namespace, ".*" + expr + ".*", false));
}
}

View File

@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@ -601,14 +602,18 @@ public class ServiceManager implements RecordListener<Service> {
serviceMap.get(service.getNamespaceId()).put(service.getName(), service);
}
public List<Service> searchServices(String namespaceId, String regex) {
public List<Service> searchServices(String namespaceId, String regex, boolean hasIpCount) {
List<Service> result = new ArrayList<>();
for (Map.Entry<String, Service> entry : chooseServiceMap(namespaceId).entrySet()) {
Service service = entry.getValue();
String key = service.getName() + ":" + ArrayUtils.toString(service.getOwners());
if (key.matches(regex)) {
result.add(service);
if (StringUtils.isBlank(regex) || !key.matches(regex)) {
continue;
}
if (hasIpCount && CollectionUtils.isEmpty(service.allIPs())) {
continue;
}
result.add(service);
}
return result;
@ -636,19 +641,13 @@ public class ServiceManager implements RecordListener<Service> {
return serviceMap.get(namespaceId);
}
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<Service> serviceList) {
public int getPagedService(String namespaceId, int startPage, int pageSize, String keyword, String containedInstance, List<Service> serviceList, boolean hasIpCount) {
List<Service> matchList;
if (chooseServiceMap(namespaceId) == null) {
if (chooseServiceMap(namespaceId) == null ) {
return 0;
}
if (StringUtils.isNotBlank(keyword)) {
matchList = searchServices(namespaceId, ".*" + keyword + ".*");
} else {
matchList = new ArrayList<>(chooseServiceMap(namespaceId).values());
}
List<Service> matchList = searchServices(namespaceId, StringUtils.isNotBlank(keyword)?".*" + keyword + ".*":null, hasIpCount);
if (StringUtils.isNotBlank(containedInstance)) {

View File

@ -60,7 +60,7 @@ public class DomainsManagerTest extends BaseTest {
service.setNamespaceId(TEST_NAMESPACE);
manager.putService(service);
List<Service> list = manager.searchServices(TEST_NAMESPACE, "test.*");
List<Service> list = manager.searchServices(TEST_NAMESPACE, "test.*", false);
Assert.assertNotNull(list);
Assert.assertEquals(1, list.size());
Assert.assertEquals(TEST_SERVICE_NAME, list.get(0).getName());