Search in sources :

Example 1 with AssignableResultHandle

use of io.quarkus.gizmo.AssignableResultHandle in project quarkus-operator-sdk by quarkiverse.

the class OperatorSDKProcessor method createDelayedRegistrationObservers.

/**
 * This looks for all resource controllers, to find those that want a delayed registration, and
 * creates one CDI observer for each, that will call operator.register on them when the event is
 * fired.
 */
@BuildStep
void createDelayedRegistrationObservers(CombinedIndexBuildItem combinedIndexBuildItem, ObserverRegistrationPhaseBuildItem observerRegistrationPhase, BuildProducer<ObserverConfiguratorBuildItem> observerConfigurators) {
    final var index = combinedIndexBuildItem.getIndex();
    ClassUtils.getKnownReconcilers(index, log).forEach(info -> {
        final var controllerClassName = info.name().toString();
        final var controllerAnnotation = info.classAnnotation(CONTROLLER_CONFIGURATION);
        final var name = ConfigurationUtils.getReconcilerName(controllerClassName, controllerAnnotation);
        // extract the configuration from annotation and/or external configuration
        final var configExtractor = new BuildTimeHybridControllerConfiguration(buildTimeConfiguration, buildTimeConfiguration.controllers.get(name), controllerAnnotation, info.classAnnotation(DELAY_REGISTRATION));
        if (configExtractor.delayedRegistration()) {
            ObserverConfigurator configurator = observerRegistrationPhase.getContext().configure().observedType(configExtractor.eventType()).beanClass(info.name()).notify(mc -> {
                MethodDescriptor cdiMethod = MethodDescriptor.ofMethod(CDI.class, "current", CDI.class);
                MethodDescriptor selectMethod = MethodDescriptor.ofMethod(CDI.class, "select", Instance.class, Class.class, Annotation[].class);
                MethodDescriptor getMethod = MethodDescriptor.ofMethod(Instance.class, "get", Object.class);
                AssignableResultHandle cdiVar = mc.createVariable(CDI.class);
                mc.assign(cdiVar, mc.invokeStaticMethod(cdiMethod));
                ResultHandle operator = getHandleFromCDI(mc, selectMethod, getMethod, cdiVar, Operator.class, null);
                ResultHandle resource = getHandleFromCDI(mc, selectMethod, getMethod, cdiVar, Reconciler.class, controllerClassName);
                ResultHandle config = getHandleFromCDI(mc, selectMethod, getMethod, cdiVar, QuarkusConfigurationService.class, null);
                mc.invokeStaticMethod(MethodDescriptor.ofMethod(OperatorProducer.class, "applyCRDIfNeededAndRegister", void.class, Operator.class, Reconciler.class, QuarkusConfigurationService.class), operator, resource, config);
                mc.returnValue(null);
            });
            observerConfigurators.produce(new ObserverConfiguratorBuildItem(configurator));
        }
    });
}
Also used : Operator(io.javaoperatorsdk.operator.Operator) Reconciler(io.javaoperatorsdk.operator.api.reconciler.Reconciler) OperatorProducer(io.quarkiverse.operatorsdk.runtime.OperatorProducer) ObserverConfigurator(io.quarkus.arc.processor.ObserverConfigurator) AssignableResultHandle(io.quarkus.gizmo.AssignableResultHandle) ResultHandle(io.quarkus.gizmo.ResultHandle) AssignableResultHandle(io.quarkus.gizmo.AssignableResultHandle) ObserverConfiguratorBuildItem(io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem) MethodDescriptor(io.quarkus.gizmo.MethodDescriptor) Annotation(java.lang.annotation.Annotation) QuarkusConfigurationService(io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

Operator (io.javaoperatorsdk.operator.Operator)1 Reconciler (io.javaoperatorsdk.operator.api.reconciler.Reconciler)1 OperatorProducer (io.quarkiverse.operatorsdk.runtime.OperatorProducer)1 QuarkusConfigurationService (io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService)1 ObserverConfiguratorBuildItem (io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem)1 ObserverConfigurator (io.quarkus.arc.processor.ObserverConfigurator)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 AssignableResultHandle (io.quarkus.gizmo.AssignableResultHandle)1 MethodDescriptor (io.quarkus.gizmo.MethodDescriptor)1 ResultHandle (io.quarkus.gizmo.ResultHandle)1 Annotation (java.lang.annotation.Annotation)1