use of com.alibaba.nacos.api.naming.pojo.Cluster in project nacos by alibaba.
the class CatalogServiceV2Impl method getServiceDetail.
@Override
public Object getServiceDetail(String namespaceId, String groupName, String serviceName) throws NacosException {
Service service = Service.newService(namespaceId, groupName, serviceName);
if (!ServiceManager.getInstance().containSingleton(service)) {
throw new NacosException(NacosException.NOT_FOUND, String.format("service %s@@%s is not found!", groupName, serviceName));
}
Optional<ServiceMetadata> metadata = metadataManager.getServiceMetadata(service);
ServiceMetadata detailedService = metadata.orElseGet(ServiceMetadata::new);
ObjectNode serviceObject = JacksonUtils.createEmptyJsonNode();
serviceObject.put(FieldsConstants.NAME, serviceName);
serviceObject.put(FieldsConstants.GROUP_NAME, groupName);
serviceObject.put(FieldsConstants.PROTECT_THRESHOLD, detailedService.getProtectThreshold());
serviceObject.replace(FieldsConstants.SELECTOR, JacksonUtils.transferToJsonNode(detailedService.getSelector()));
serviceObject.replace(FieldsConstants.METADATA, JacksonUtils.transferToJsonNode(detailedService.getExtendData()));
ObjectNode detailView = JacksonUtils.createEmptyJsonNode();
detailView.replace(FieldsConstants.SERVICE, serviceObject);
List<com.alibaba.nacos.api.naming.pojo.Cluster> clusters = new ArrayList<>();
for (String each : serviceStorage.getClusters(service)) {
ClusterMetadata clusterMetadata = detailedService.getClusters().containsKey(each) ? detailedService.getClusters().get(each) : new ClusterMetadata();
com.alibaba.nacos.api.naming.pojo.Cluster clusterView = new Cluster();
clusterView.setName(each);
clusterView.setHealthChecker(clusterMetadata.getHealthChecker());
clusterView.setMetadata(clusterMetadata.getExtendData());
clusterView.setUseIPPort4Check(clusterMetadata.isUseInstancePortForCheck());
clusterView.setDefaultPort(DEFAULT_PORT);
clusterView.setDefaultCheckPort(clusterMetadata.getHealthyCheckPort());
clusterView.setServiceName(service.getGroupedServiceName());
clusters.add(clusterView);
}
detailView.replace(FieldsConstants.CLUSTERS, JacksonUtils.transferToJsonNode(clusters));
return detailView;
}
Aggregations