use of com.alibaba.nacos.naming.pojo.ServiceView in project nacos by alibaba.
the class CatalogServiceV1Impl method pageListService.
@Override
public Object pageListService(String namespaceId, String groupName, String serviceName, int pageNo, int pageSize, String instancePattern, boolean ignoreEmptyService) throws NacosException {
String param = StringUtils.isBlank(serviceName) && StringUtils.isBlank(groupName) ? StringUtils.EMPTY : NamingUtils.getGroupedNameOptional(serviceName, groupName);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
List<Service> services = new ArrayList<>();
final int total = serviceManager.getPagedService(namespaceId, pageNo - 1, pageSize, param, instancePattern, services, ignoreEmptyService);
if (CollectionUtils.isEmpty(services)) {
result.replace(FieldsConstants.SERVICE_LIST, JacksonUtils.transferToJsonNode(Collections.emptyList()));
result.put(FieldsConstants.COUNT, 0);
return result;
}
List<ServiceView> serviceViews = new LinkedList<>();
for (Service each : services) {
ServiceView serviceView = new ServiceView();
serviceView.setName(NamingUtils.getServiceName(each.getName()));
serviceView.setGroupName(NamingUtils.getGroupName(each.getName()));
serviceView.setClusterCount(each.getClusterMap().size());
serviceView.setIpCount(each.allIPs().size());
serviceView.setHealthyInstanceCount(each.healthyInstanceCount());
serviceView.setTriggerFlag(each.triggerFlag() ? "true" : "false");
serviceViews.add(serviceView);
}
result.set(FieldsConstants.SERVICE_LIST, JacksonUtils.transferToJsonNode(serviceViews));
result.put(FieldsConstants.COUNT, total);
return result;
}
use of com.alibaba.nacos.naming.pojo.ServiceView in project nacos by alibaba.
the class CatalogServiceV2Impl method pageListService.
@Override
public Object pageListService(String namespaceId, String groupName, String serviceName, int pageNo, int pageSize, String instancePattern, boolean ignoreEmptyService) throws NacosException {
ObjectNode result = JacksonUtils.createEmptyJsonNode();
List<ServiceView> serviceViews = new LinkedList<>();
Collection<Service> services = patternServices(namespaceId, groupName, serviceName);
if (ignoreEmptyService) {
services = services.stream().filter(each -> 0 != serviceStorage.getData(each).ipCount()).collect(Collectors.toList());
}
result.put(FieldsConstants.COUNT, services.size());
services = doPage(services, pageNo - 1, pageSize);
for (Service each : services) {
ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(each).orElseGet(ServiceMetadata::new);
ServiceView serviceView = new ServiceView();
serviceView.setName(each.getName());
serviceView.setGroupName(each.getGroup());
serviceView.setClusterCount(serviceStorage.getClusters(each).size());
serviceView.setIpCount(serviceStorage.getData(each).ipCount());
serviceView.setHealthyInstanceCount(countHealthyInstance(serviceStorage.getData(each)));
serviceView.setTriggerFlag(isProtectThreshold(serviceView, serviceMetadata) ? "true" : "false");
serviceViews.add(serviceView);
}
result.set(FieldsConstants.SERVICE_LIST, JacksonUtils.transferToJsonNode(serviceViews));
return result;
}
Aggregations