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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations