Search in sources :

Example 16 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testQueryInstancesOfService.

@Test
public void testQueryInstancesOfService() throws Exception {
    QueryServiceResponse res = new QueryServiceResponse();
    ServiceInfo info = new ServiceInfo(GROUP_NAME + "@@" + SERVICE_NAME + "@@" + CLUSTERS);
    res.setServiceInfo(info);
    when(this.rpcClient.request(any())).thenReturn(res);
    ServiceInfo actual = client.queryInstancesOfService(SERVICE_NAME, GROUP_NAME, CLUSTERS, 0, false);
    Assert.assertEquals(info, actual);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) QueryServiceResponse(com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse) Test(org.junit.Test)

Example 17 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testSubscribe.

@Test
public void testSubscribe() throws Exception {
    SubscribeServiceResponse res = new SubscribeServiceResponse();
    ServiceInfo info = new ServiceInfo(GROUP_NAME + "@@" + SERVICE_NAME + "@@" + CLUSTERS);
    res.setServiceInfo(info);
    when(this.rpcClient.request(any())).thenReturn(res);
    ServiceInfo actual = client.subscribe(SERVICE_NAME, GROUP_NAME, CLUSTERS);
    Assert.assertEquals(info, actual);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) SubscribeServiceResponse(com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse) Test(org.junit.Test)

Example 18 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class PushExecutorUdpImpl method replaceServiceInfoName.

/**
 * The reason to replace the name is upd push is used in 1.x client. And 1.x client do not identify the group
 * attribute but only identify name attribute. So for supporting 1.x client, replace it with a new {@link
 * ServiceInfo}.
 *
 * <p>
 * Why not setName directly? Because the input {@link ServiceInfo} may be reused by 2.x push execute. And if set
 * name directly will has some effect for 2.x client.
 * </p>
 *
 * @param originalData original service info
 * @return new service info for 1.x
 */
private ServiceInfo replaceServiceInfoName(PushDataWrapper originalData, Subscriber subscriber) {
    ServiceInfo serviceInfo = ServiceUtil.selectInstancesWithHealthyProtection(originalData.getOriginalData(), originalData.getServiceMetadata(), false, true, subscriber);
    ServiceInfo result = new ServiceInfo();
    result.setName(NamingUtils.getGroupedName(serviceInfo.getName(), serviceInfo.getGroupName()));
    result.setClusters(serviceInfo.getClusters());
    result.setHosts(serviceInfo.getHosts());
    result.setLastRefTime(serviceInfo.getLastRefTime());
    result.setCacheMillis(serviceInfo.getCacheMillis());
    return result;
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo)

Example 19 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class PushExecuteTask method generatePushData.

private PushDataWrapper generatePushData() {
    ServiceInfo serviceInfo = delayTaskEngine.getServiceStorage().getPushData(service);
    ServiceMetadata serviceMetadata = delayTaskEngine.getMetadataManager().getServiceMetadata(service).orElse(null);
    return new PushDataWrapper(serviceMetadata, serviceInfo);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) PushDataWrapper(com.alibaba.nacos.naming.push.v2.PushDataWrapper) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 20 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NacosServiceInfoResourceWatcher method run.

@Override
public void run() {
    boolean changed = false;
    // Query all services to see if any of them have changes.
    Set<String> namespaces = ServiceManager.getInstance().getAllNamespaces();
    Set<String> allServices = new HashSet<>();
    for (String namespace : namespaces) {
        Set<Service> services = ServiceManager.getInstance().getSingletons(namespace);
        if (services.isEmpty()) {
            continue;
        }
        for (Service service : services) {
            String serviceName = IstioCrdUtil.buildServiceNameForServiceEntry(service);
            allServices.add(serviceName);
            IstioService old = serviceInfoMap.get(serviceName);
            // Service not changed
            if (old != null && old.getRevision().equals(service.getRevision())) {
                continue;
            }
            // Update the resource
            changed = true;
            ServiceInfo serviceInfo = serviceStorage.getPushData(service);
            if (!serviceInfo.isValid()) {
                serviceInfoMap.remove(serviceName);
                continue;
            }
            if (old != null) {
                serviceInfoMap.put(serviceName, new IstioService(service, serviceInfo, old));
            } else {
                serviceInfoMap.put(serviceName, new IstioService(service, serviceInfo));
            }
        }
    }
    for (String key : serviceInfoMap.keySet()) {
        if (!allServices.contains(key)) {
            changed = true;
            serviceInfoMap.remove(key);
        }
    }
    if (changed) {
        eventProcessor.notify(Event.SERVICE_UPDATE_EVENT);
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) IstioService(com.alibaba.nacos.istio.model.IstioService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) IstioService(com.alibaba.nacos.istio.model.IstioService) HashSet(java.util.HashSet)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)74 Test (org.junit.Test)44 Instance (com.alibaba.nacos.api.naming.pojo.Instance)29 ArrayList (java.util.ArrayList)17 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)12 Properties (java.util.Properties)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 NacosException (com.alibaba.nacos.api.exception.NacosException)8 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 Before (org.junit.Before)8 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)7 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)5 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)4 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 HashMap (java.util.HashMap)4 QueryServiceResponse (com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse)3 Secured (com.alibaba.nacos.auth.annotation.Secured)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3