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