Search in sources :

Example 1 with ServiceView

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;
}
Also used : ServiceView(com.alibaba.nacos.naming.pojo.ServiceView) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with ServiceView

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;
}
Also used : ServiceView(com.alibaba.nacos.naming.pojo.ServiceView) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) LinkedList(java.util.LinkedList) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Aggregations

ServiceView (com.alibaba.nacos.naming.pojo.ServiceView)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 LinkedList (java.util.LinkedList)2 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)1 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)1 ArrayList (java.util.ArrayList)1