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