Search in sources :

Example 1 with ServiceDetailInfo

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

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

the class CatalogServiceV2Impl method pageListServiceDetail.

@Override
public Object pageListServiceDetail(String namespaceId, String groupName, String serviceName, int pageNo, int pageSize) throws NacosException {
    List<ServiceDetailInfo> result = new ArrayList<>();
    Collection<Service> services = patternServices(namespaceId, groupName, serviceName);
    services = doPage(services, pageNo - 1, pageSize);
    for (Service each : services) {
        ServiceDetailInfo serviceDetailInfo = new ServiceDetailInfo();
        serviceDetailInfo.setServiceName(each.getName());
        serviceDetailInfo.setGroupName(each.getGroup());
        ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(each).orElseGet(ServiceMetadata::new);
        serviceDetailInfo.setMetadata(serviceMetadata.getExtendData());
        serviceDetailInfo.setClusterMap(getClusterMap(each));
        result.add(serviceDetailInfo);
    }
    return result;
}
Also used : ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) ArrayList(java.util.ArrayList) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 3 with ServiceDetailInfo

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

the class ServiceControllerV2Test method testDetail.

@Test
public void testDetail() throws Exception {
    ServiceDetailInfo expected = new ServiceDetailInfo();
    when(serviceOperatorV2.queryService(Service.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "service"))).thenReturn(expected);
    RestResult<ServiceDetailInfo> actual = serviceController.detail(Constants.DEFAULT_NAMESPACE_ID, "service", Constants.DEFAULT_GROUP);
    assertEquals(200, actual.getCode());
    assertEquals(expected, actual.getData());
}
Also used : ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) Test(org.junit.Test)

Example 4 with ServiceDetailInfo

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

the class CatalogServiceV2ImplTest method testPageListServiceDetail.

@Test
public void testPageListServiceDetail() {
    try {
        ServiceMetadata metadata = new ServiceMetadata();
        Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
        Instance instance = new Instance();
        instance.setServiceName("C");
        instance.setClusterName("D");
        List<Instance> instances = Collections.singletonList(instance);
        ServiceInfo serviceInfo = new ServiceInfo();
        serviceInfo.setHosts(instances);
        Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
        List<ServiceDetailInfo> result = (List<ServiceDetailInfo>) catalogServiceV2Impl.pageListServiceDetail("A", "B", "C", 1, 10);
        Assert.assertEquals(1, result.size());
    } catch (NacosException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) List(java.util.List) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 5 with ServiceDetailInfo

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

ServiceDetailInfo (com.alibaba.nacos.naming.pojo.ServiceDetailInfo)5 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)3 NacosException (com.alibaba.nacos.api.exception.NacosException)2 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)2 ClusterInfo (com.alibaba.nacos.naming.pojo.ClusterInfo)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)1 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)1 HashMap (java.util.HashMap)1 List (java.util.List)1