Search in sources :

Example 1 with ServiceListResponse

use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testGetServiceList.

@Test
public void testGetServiceList() throws Exception {
    ServiceListResponse res = new ServiceListResponse();
    List<String> services = Arrays.asList("service1", "service2");
    res.setServiceNames(services);
    res.setCount(5);
    when(this.rpcClient.request(any())).thenReturn(res);
    AbstractSelector selector = new NoneSelector();
    ListView<String> serviceList = client.getServiceList(1, 10, GROUP_NAME, selector);
    Assert.assertEquals(5, serviceList.getCount());
    Assert.assertEquals(services, serviceList.getData());
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 2 with ServiceListResponse

use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.

the class NamingGrpcClientProxy method getServiceList.

@Override
public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
    ServiceListRequest request = new ServiceListRequest(namespaceId, groupName, pageNo, pageSize);
    if (selector != null) {
        if (SelectorType.valueOf(selector.getType()) == SelectorType.label) {
            request.setSelector(JacksonUtils.toJson(selector));
        }
    }
    ServiceListResponse response = requestToServer(request, ServiceListResponse.class);
    ListView<String> result = new ListView<String>();
    result.setCount(response.getCount());
    result.setData(response.getServiceNames());
    return result;
}
Also used : ListView(com.alibaba.nacos.api.naming.pojo.ListView) ServiceListRequest(com.alibaba.nacos.api.naming.remote.request.ServiceListRequest) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse)

Example 3 with ServiceListResponse

use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.

the class ServiceListRequestHandler method handle.

@Override
@Secured(action = ActionTypes.READ)
public ServiceListResponse handle(ServiceListRequest request, RequestMeta meta) throws NacosException {
    Collection<Service> serviceSet = ServiceManager.getInstance().getSingletons(request.getNamespace());
    ServiceListResponse result = ServiceListResponse.buildSuccessResponse(0, new LinkedList<>());
    if (!serviceSet.isEmpty()) {
        Collection<String> serviceNameSet = selectServiceWithGroupName(serviceSet, request.getGroupName());
        // TODO select service by selector
        List<String> serviceNameList = ServiceUtil.pageServiceName(request.getPageNo(), request.getPageSize(), serviceNameSet);
        result.setCount(serviceNameSet.size());
        result.setServiceNames(serviceNameList);
    }
    return result;
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 4 with ServiceListResponse

use of com.alibaba.nacos.api.naming.remote.response.ServiceListResponse in project nacos by alibaba.

the class ServiceListRequestHandlerTest method testHandle.

@Test
public void testHandle() throws NacosException {
    ServiceListRequest serviceListRequest = new ServiceListRequest();
    serviceListRequest.setNamespace("A");
    serviceListRequest.setPageNo(1);
    serviceListRequest.setPageSize(10);
    serviceListRequest.setGroupName("B");
    ServiceListRequestHandler serviceListRequestHandler = new ServiceListRequestHandler();
    ServiceListResponse serviceListResponse = serviceListRequestHandler.handle(serviceListRequest, new RequestMeta());
    Assert.assertEquals(serviceListResponse.getCount(), 1);
    Assert.assertTrue(serviceListResponse.getServiceNames().contains("C"));
}
Also used : RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) ServiceListRequest(com.alibaba.nacos.api.naming.remote.request.ServiceListRequest) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse) Test(org.junit.Test)

Aggregations

ServiceListResponse (com.alibaba.nacos.api.naming.remote.response.ServiceListResponse)4 ServiceListRequest (com.alibaba.nacos.api.naming.remote.request.ServiceListRequest)2 Test (org.junit.Test)2 ListView (com.alibaba.nacos.api.naming.pojo.ListView)1 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)1 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)1 Secured (com.alibaba.nacos.auth.annotation.Secured)1 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)1