Search in sources :

Example 1 with UpdateWatchEventFilter

use of io.kubernetes.client.spring.extended.controller.annotation.UpdateWatchEventFilter in project java by kubernetes-client.

the class KubernetesControllerFactory method getUpdateFilters.

private Map<Class, UpdateFilterAdaptor> getUpdateFilters(KubernetesReconcilerWatches watches, Reconciler reconciler) {
    Map<Class, UpdateFilterAdaptor> filters = new HashMap<>();
    Set<Method> allAnnotatedMethods = new HashSet<>();
    Set<Method> adoptedMethods = new HashSet<>();
    for (KubernetesReconcilerWatch watch : watches.value()) {
        for (Method method : reconciler.getClass().getMethods()) {
            UpdateWatchEventFilter annotation = method.getAnnotation(UpdateWatchEventFilter.class);
            if (annotation == null) {
                continue;
            }
            if (watch.apiTypeClass().equals(annotation.apiTypeClass())) {
                if (filters.containsKey(watch.apiTypeClass())) {
                    log.warn("Duplicated watch UPDATE event filter upon apiType {}", annotation.apiTypeClass());
                }
                filters.put(watch.apiTypeClass(), new UpdateFilterAdaptor(reconciler, method));
                adoptedMethods.add(method);
            }
            allAnnotatedMethods.add(method);
        }
    }
    allAnnotatedMethods.removeAll(adoptedMethods);
    if (allAnnotatedMethods.size() > 0) {
        log.warn("Dangling watch UPDATE event filters {}", StringUtils.join(allAnnotatedMethods, ","));
    }
    return filters;
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) KubernetesReconcilerWatch(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch) HashSet(java.util.HashSet) UpdateWatchEventFilter(io.kubernetes.client.spring.extended.controller.annotation.UpdateWatchEventFilter)

Aggregations

KubernetesReconcilerWatch (io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch)1 UpdateWatchEventFilter (io.kubernetes.client.spring.extended.controller.annotation.UpdateWatchEventFilter)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1