Search in sources :

Example 1 with ClusterInfo

use of com.alibaba.nacos.naming.pojo.ClusterInfo in project nacos by alibaba.

the class CatalogServiceV1Impl method pageListServiceDetail.

@Override
public Object pageListServiceDetail(String namespaceId, String groupName, String serviceName, int pageNo, int pageSize) throws NacosException {
    String param = StringUtils.isBlank(serviceName) && StringUtils.isBlank(groupName) ? StringUtils.EMPTY : NamingUtils.getGroupedNameOptional(serviceName, groupName);
    List<ServiceDetailInfo> serviceDetailInfoList = new ArrayList<>();
    List<Service> services = new ArrayList<>(8);
    serviceManager.getPagedService(namespaceId, pageNo, pageSize, param, StringUtils.EMPTY, services, false);
    for (Service each : services) {
        ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
        serviceDetailInfo.setServiceName(NamingUtils.getServiceName(each.getName()));
        serviceDetailInfo.setGroupName(NamingUtils.getGroupName(each.getName()));
        serviceDetailInfo.setMetadata(each.getMetadata());
        Map<String, ClusterInfo> clusterInfoMap = getStringClusterInfoMap(each);
        serviceDetailInfo.setClusterMap(clusterInfoMap);
        serviceDetailInfoList.add(serviceDetailInfo);
    }
    return serviceDetailInfoList;
}
Also used : ClusterInfo(com.alibaba.nacos.naming.pojo.ClusterInfo) ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) ArrayList(java.util.ArrayList)

Example 2 with ClusterInfo

use of com.alibaba.nacos.naming.pojo.ClusterInfo in project nacos by alibaba.

the class CatalogServiceV2Impl method getClusterMap.

private Map<String, ClusterInfo> getClusterMap(Service service) {
    Map<String, ClusterInfo> result = new HashMap<>(1);
    for (Instance each : serviceStorage.getData(service).getHosts()) {
        final IpAddressInfo info = transferToIpAddressInfo(each);
        if (!result.containsKey(each.getClusterName())) {
            ClusterInfo clusterInfo = new ClusterInfo();
            clusterInfo.setHosts(new LinkedList<>());
            result.put(each.getClusterName(), clusterInfo);
        }
        result.get(each.getClusterName()).getHosts().add(info);
    }
    return result;
}
Also used : ClusterInfo(com.alibaba.nacos.naming.pojo.ClusterInfo) HashMap(java.util.HashMap) Instance(com.alibaba.nacos.api.naming.pojo.Instance) IpAddressInfo(com.alibaba.nacos.naming.pojo.IpAddressInfo)

Example 3 with ClusterInfo

use of com.alibaba.nacos.naming.pojo.ClusterInfo in project nacos by alibaba.

the class ServiceOperatorV2Impl method newClusterNodeV2.

private ClusterInfo newClusterNodeV2(String clusterName, ClusterMetadata clusterMetadata) {
    ClusterInfo result = new ClusterInfo();
    result.setClusterName(clusterName);
    result.setHealthChecker(clusterMetadata.getHealthChecker());
    result.setMetadata(clusterMetadata.getExtendData());
    return result;
}
Also used : ClusterInfo(com.alibaba.nacos.naming.pojo.ClusterInfo)

Example 4 with ClusterInfo

use of com.alibaba.nacos.naming.pojo.ClusterInfo in project nacos by alibaba.

the class CatalogServiceV1Impl method getStringClusterInfoMap.

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;
}
Also used : ClusterInfo(com.alibaba.nacos.naming.pojo.ClusterInfo) HashMap(java.util.HashMap) IpAddressInfo(com.alibaba.nacos.naming.pojo.IpAddressInfo)

Example 5 with ClusterInfo

use of com.alibaba.nacos.naming.pojo.ClusterInfo in project nacos by alibaba.

the class ServiceOperatorV2Impl method queryService.

/**
 * Query service detail.
 *
 * @param service service
 * @return service detail with cluster info
 * @throws NacosException nacos exception during query
 */
public ServiceDetailInfo queryService(Service service) throws NacosException {
    if (!ServiceManager.getInstance().containSingleton(service)) {
        throw new NacosException(NacosException.INVALID_PARAM, "service not found, namespace: " + service.getNamespace() + ", serviceName: " + service.getGroupedServiceName());
    }
    Service singleton = ServiceManager.getInstance().getSingleton(service);
    ServiceDetailInfo result = new ServiceDetailInfo();
    ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(singleton).orElse(new ServiceMetadata());
    setServiceMetadata(result, serviceMetadata, singleton);
    Map<String, ClusterInfo> clusters = new HashMap<>(2);
    for (String each : serviceStorage.getClusters(singleton)) {
        ClusterMetadata clusterMetadata = serviceMetadata.getClusters().containsKey(each) ? serviceMetadata.getClusters().get(each) : new ClusterMetadata();
        clusters.put(each, newClusterNodeV2(each, clusterMetadata));
    }
    result.setClusterMap(clusters);
    result.setEphemeral(singleton.isEphemeral());
    return result;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) ClusterInfo(com.alibaba.nacos.naming.pojo.ClusterInfo) HashMap(java.util.HashMap) ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) NacosException(com.alibaba.nacos.api.exception.NacosException) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Aggregations

ClusterInfo (com.alibaba.nacos.naming.pojo.ClusterInfo)5 HashMap (java.util.HashMap)3 IpAddressInfo (com.alibaba.nacos.naming.pojo.IpAddressInfo)2 ServiceDetailInfo (com.alibaba.nacos.naming.pojo.ServiceDetailInfo)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)1 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)1 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