use of io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch in project java by kubernetes-client.
the class KubernetesControllerFactory method getDeleteFilters.
private Map<Class, DeleteFilterAdaptor> getDeleteFilters(KubernetesReconcilerWatches watches, Reconciler reconciler) {
Map<Class, DeleteFilterAdaptor> filters = new HashMap<>();
Set<Method> allAnnotatedMethods = new HashSet<>();
Set<Method> adoptedMethods = new HashSet<>();
for (KubernetesReconcilerWatch watch : watches.value()) {
for (Method method : reconciler.getClass().getMethods()) {
DeleteWatchEventFilter annotation = method.getAnnotation(DeleteWatchEventFilter.class);
if (annotation == null) {
continue;
}
if (watch.apiTypeClass().equals(annotation.apiTypeClass())) {
if (filters.containsKey(watch.apiTypeClass())) {
log.warn("Duplicated watch DELETE event filter upon apiType {}", annotation.apiTypeClass());
}
filters.put(watch.apiTypeClass(), new DeleteFilterAdaptor(reconciler, method));
adoptedMethods.add(method);
}
allAnnotatedMethods.add(method);
}
}
allAnnotatedMethods.removeAll(adoptedMethods);
if (allAnnotatedMethods.size() > 0) {
log.warn("Dangling watch DELETE event filters {}", StringUtils.join(allAnnotatedMethods, ","));
}
return filters;
}
use of io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch in project java by kubernetes-client.
the class KubernetesControllerFactory method buildController.
private Controller buildController(SharedInformerFactory sharedInformerFactory, Reconciler r) throws BeansException {
KubernetesReconciler kubernetesReconciler = r.getClass().getAnnotation(KubernetesReconciler.class);
String reconcilerName = kubernetesReconciler.value();
KubernetesReconcilerWatches watches = kubernetesReconciler.watches();
DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory);
RateLimitingQueue<Request> workQueue = new DefaultRateLimitingQueue<>();
builder = builder.withWorkQueue(workQueue);
Map<Class, AddFilterAdaptor> addFilters = getAddFilters(watches, r);
Map<Class, UpdateFilterAdaptor> updateFilters = getUpdateFilters(watches, r);
Map<Class, DeleteFilterAdaptor> deleteFilters = getDeleteFilters(watches, r);
List<ReadyFuncAdaptor> readyFuncs = getReadyFuncs(r);
for (KubernetesReconcilerWatch watch : watches.value()) {
try {
Function<? extends KubernetesObject, Request> workQueueKeyFunc;
try {
workQueueKeyFunc = watch.workQueueKeyFunc().getConstructor(WorkQueue.class).newInstance(workQueue);
} catch (NoSuchMethodException e) {
workQueueKeyFunc = watch.workQueueKeyFunc().newInstance();
} catch (InvocationTargetException e) {
throw new BeanCreationException("Failed instantiating controller watch: " + e.getMessage());
}
final Function<? extends KubernetesObject, Request> finalWorkQueueKeyFunc = workQueueKeyFunc;
builder = builder.watch((q) -> {
return ControllerBuilder.controllerWatchBuilder(watch.apiTypeClass(), q).withOnAddFilter(addFilters.get(watch.apiTypeClass())).withOnUpdateFilter(updateFilters.get(watch.apiTypeClass())).withOnDeleteFilter(deleteFilters.get(watch.apiTypeClass())).withWorkQueueKeyFunc(finalWorkQueueKeyFunc).withResyncPeriod(Duration.ofMillis(watch.resyncPeriodMillis())).build();
});
for (Supplier<Boolean> readyFunc : readyFuncs) {
builder = builder.withReadyFunc(readyFunc);
}
} catch (IllegalAccessException | InstantiationException e) {
throw new BeanCreationException("Failed instantiating controller: " + e.getMessage());
}
}
builder = builder.withWorkerCount(kubernetesReconciler.workerCount());
return builder.withReconciler(r).withName(reconcilerName).build();
}
use of io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch in project java by kubernetes-client.
the class KubernetesControllerFactory method getAddFilters.
private Map<Class, AddFilterAdaptor> getAddFilters(KubernetesReconcilerWatches watches, Reconciler reconciler) {
Map<Class, AddFilterAdaptor> filters = new HashMap<>();
Set<Method> allAnnotatedMethods = new HashSet<>();
Set<Method> adoptedMethods = new HashSet<>();
for (KubernetesReconcilerWatch watch : watches.value()) {
for (Method method : reconciler.getClass().getMethods()) {
AddWatchEventFilter annotation = method.getAnnotation(AddWatchEventFilter.class);
if (annotation == null) {
continue;
}
if (watch.apiTypeClass().equals(annotation.apiTypeClass())) {
if (filters.containsKey(watch.apiTypeClass())) {
log.warn("Duplicated watch ADD event filter upon apiType {}", annotation.apiTypeClass());
}
filters.put(watch.apiTypeClass(), new AddFilterAdaptor(reconciler, method));
adoptedMethods.add(method);
}
allAnnotatedMethods.add(method);
}
}
allAnnotatedMethods.removeAll(adoptedMethods);
if (allAnnotatedMethods.size() > 0) {
log.warn("Dangling watch ADD event filters {}", StringUtils.join(allAnnotatedMethods, ","));
}
return filters;
}
use of io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch 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;
}
Aggregations