Search in sources :

Example 1 with IstioService

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);
    }
}
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)1 IstioService (com.alibaba.nacos.istio.model.IstioService)1 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)1 HashSet (java.util.HashSet)1