Search in sources :

Example 1 with Cluster

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

Aggregations

NacosException (com.alibaba.nacos.api.exception.NacosException)1 Cluster (com.alibaba.nacos.api.naming.pojo.Cluster)1 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)1 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)1 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1