Search in sources :

Example 1 with IpAddressInfo

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

the class CatalogServiceV2Impl method transferToIpAddressInfo.

private IpAddressInfo transferToIpAddressInfo(Instance instance) {
    IpAddressInfo result = new IpAddressInfo();
    result.setIp(instance.getIp());
    result.setPort(instance.getPort());
    result.setEnabled(instance.isEnabled());
    result.setValid(instance.isHealthy());
    result.setWeight(instance.getWeight());
    result.setMetadata(instance.getMetadata());
    return result;
}
Also used : IpAddressInfo(com.alibaba.nacos.naming.pojo.IpAddressInfo)

Example 2 with IpAddressInfo

use of com.alibaba.nacos.naming.pojo.IpAddressInfo 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 IpAddressInfo

use of com.alibaba.nacos.naming.pojo.IpAddressInfo 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 4 with IpAddressInfo

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

the class CatalogServiceV1Impl method getIpAddressInfos.

private List<IpAddressInfo> getIpAddressInfos(List<com.alibaba.nacos.naming.core.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;
}
Also used : ArrayList(java.util.ArrayList) IpAddressInfo(com.alibaba.nacos.naming.pojo.IpAddressInfo)

Aggregations

IpAddressInfo (com.alibaba.nacos.naming.pojo.IpAddressInfo)4 ClusterInfo (com.alibaba.nacos.naming.pojo.ClusterInfo)2 HashMap (java.util.HashMap)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 ArrayList (java.util.ArrayList)1