com.alibaba.nacos.api.naming.pojo.ListView Java Examples

The following examples show how to use com.alibaba.nacos.api.naming.pojo.ListView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NacosSyncQueryClientImpl.java    From nacos-sync with Apache License 2.0 6 votes vote down vote up
@Override
public List<TaskModel> getAllInstance(InstanceQueryModel instanceQueryModel) {
    NamingService namingService = nacosServerHolder
            .get(instanceQueryModel.getSourceClusterId(), instanceQueryModel.getGroupName());
    try {
        ListView<String> servicesOfServer = namingService
                .getServicesOfServer(instanceQueryModel.getPageNo(),
                        instanceQueryModel.getPageSize());
        return servicesOfServer.getData().stream()
                .map(serviceName -> buildTaskModel(instanceQueryModel, serviceName))
                .collect(Collectors.toList());

    } catch (NacosException e) {
        log.error("When using nacos client failure query tasks", e);
        return Collections.emptyList();
    }
}
 
Example #2
Source File: MossInstanceDiscoveryListener.java    From Moss with Apache License 2.0 5 votes vote down vote up
public List<String> getServicesByNacos() {
    try {
        ListView<String> services =namingServiceThreadLocal.get()
                .getServicesOfServer(1, Integer.MAX_VALUE);
        return services.getData();
    }
    catch (Exception e) {
        log.error("get service name from nacos server fail,", e);
        return Collections.emptyList();
    }
}
 
Example #3
Source File: NacosServiceDiscovery.java    From dubbo-registry-nacos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getServices() {
    return ThrowableFunction.execute(namingService, service -> {
        ListView<String> view = service.getServicesOfServer(0, Integer.MAX_VALUE, group);
        return new LinkedHashSet<>(view.getData());
    });
}
 
Example #4
Source File: NacosRegistry.java    From dubbo-registry-nacos with Apache License 2.0 5 votes vote down vote up
private Set<String> getAllServiceNames() {

        final Set<String> serviceNames = new LinkedHashSet<>();

        execute(namingService -> {

            int pageIndex = 1;
            ListView<String> listView = namingService.getServicesOfServer(pageIndex, PAGINATION_SIZE);
            // First page data
            List<String> firstPageData = listView.getData();
            // Append first page into list
            serviceNames.addAll(firstPageData);
            // the total count
            int count = listView.getCount();
            // the number of pages
            int pageNumbers = count / PAGINATION_SIZE;
            int remainder = count % PAGINATION_SIZE;
            // remain
            if (remainder > 0) {
                pageNumbers += 1;
            }
            // If more than 1 page
            while (pageIndex < pageNumbers) {
                listView = namingService.getServicesOfServer(++pageIndex, PAGINATION_SIZE);
                serviceNames.addAll(listView.getData());
            }

        });

        return serviceNames;
    }
 
Example #5
Source File: NacosServiceDiscovery.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
/**
 * Return the names of all services.
 * @return list of service names
 * @throws NacosException nacosException
 */
public List<String> getServices() throws NacosException {
	String group = discoveryProperties.getGroup();
	ListView<String> services = discoveryProperties.namingServiceInstance()
			.getServicesOfServer(1, Integer.MAX_VALUE, group);
	return services.getData();
}
 
Example #6
Source File: NacosServiceDiscoveryTest.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetServices() throws NacosException {
	ListView<String> nacosServices = new ListView<>();

	nacosServices.setData(new LinkedList<>());

	nacosServices.getData().add(serviceName + "1");
	nacosServices.getData().add(serviceName + "2");
	nacosServices.getData().add(serviceName + "3");

	NacosDiscoveryProperties nacosDiscoveryProperties = mock(
			NacosDiscoveryProperties.class);

	NamingService namingService = mock(NamingService.class);

	when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService);
	when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT");
	when(namingService.getServicesOfServer(eq(1), eq(Integer.MAX_VALUE),
			eq("DEFAULT"))).thenReturn(nacosServices);

	NacosServiceDiscovery serviceDiscovery = new NacosServiceDiscovery(
			nacosDiscoveryProperties);

	List<String> services = serviceDiscovery.getServices();

	assertThat(services.size()).isEqualTo(3);
	assertThat(services.contains(serviceName + "1"));
	assertThat(services.contains(serviceName + "2"));
	assertThat(services.contains(serviceName + "3"));
}
 
Example #7
Source File: DelegatingNamingService.java    From nacos-spring-project with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize)
		throws NacosException {
	return delegate.getServicesOfServer(pageNo, pageSize);
}
 
Example #8
Source File: DelegatingNamingService.java    From nacos-spring-project with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
		String groupName) throws NacosException {
	return delegate.getServicesOfServer(pageNo, pageSize, groupName);
}
 
Example #9
Source File: DelegatingNamingService.java    From nacos-spring-project with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
		AbstractSelector selector) throws NacosException {
	return delegate.getServicesOfServer(pageNo, pageSize, selector);
}
 
Example #10
Source File: DelegatingNamingService.java    From nacos-spring-project with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
		String groupName, AbstractSelector selector) throws NacosException {
	return delegate.getServicesOfServer(pageNo, pageSize, groupName, selector);
}
 
Example #11
Source File: MockNamingService.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize)
		throws NacosException {
	return null;
}
 
Example #12
Source File: MockNamingService.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
		String groupName) throws NacosException {
	return null;
}
 
Example #13
Source File: MockNamingService.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
		AbstractSelector selector) throws NacosException {
	return null;
}
 
Example #14
Source File: MockNamingService.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
public ListView<String> getServicesOfServer(int pageNo, int pageSize,
		String groupName, AbstractSelector selector) throws NacosException {
	return null;
}