use of com.alibaba.nacos.istio.model.IstioService 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