Search in sources :

Example 1 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method initializeMetrics.

/**
 * <p>Initialize metrics and health endpoints.
 *
 * <p>The only reason for manually registering these endpoints is that by default they run as blocking hence
 * running in a different thread than the worker thread started by {@link QuarkusRequestFilter}.
 * See https://github.com/quarkusio/quarkus/issues/12990.
 *
 * <p>By doing this, custom health checks such as {@link org.keycloak.quarkus.runtime.services.health.KeycloakReadyHealthCheck} is
 * executed within an active {@link org.keycloak.models.KeycloakSession}, making possible to use it when calculating the
 * status.
 *
 * @param routes
 */
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void initializeMetrics(KeycloakRecorder recorder, BuildProducer<RouteBuildItem> routes, NonApplicationRootPathBuildItem nonAppRootPath) {
    final Handler<RoutingContext> healthHandler = (isHealthEnabled()) ? new SmallRyeHealthHandler() : new NotFoundHandler();
    Handler<RoutingContext> metricsHandler;
    if (isMetricsEnabled()) {
        String rootPath = nonAppRootPath.getNormalizedHttpRootPath();
        metricsHandler = recorder.createMetricsHandler(rootPath.concat(DEFAULT_METRICS_ENDPOINT).replace("//", "/"));
    } else {
        metricsHandler = new NotFoundHandler();
    }
    routes.produce(RouteBuildItem.builder().route(DEFAULT_HEALTH_ENDPOINT).handler(healthHandler).build());
    routes.produce(RouteBuildItem.builder().route(DEFAULT_HEALTH_ENDPOINT.concat("/live")).handler(healthHandler).build());
    routes.produce(RouteBuildItem.builder().route(DEFAULT_HEALTH_ENDPOINT.concat("/ready")).handler(healthHandler).build());
    routes.produce(RouteBuildItem.builder().route(DEFAULT_METRICS_ENDPOINT).handler(metricsHandler).build());
}
Also used : SmallRyeHealthHandler(io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler) RoutingContext(io.vertx.ext.web.RoutingContext) NotFoundHandler(org.keycloak.quarkus.runtime.integration.web.NotFoundHandler) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method prepareTestEnvironment.

@BuildStep(onlyIf = IsIntegrationTest.class)
void prepareTestEnvironment(BuildProducer<StaticInitConfigSourceProviderBuildItem> configSources, DevServicesDatasourceResultBuildItem dbConfig) {
    configSources.produce(new StaticInitConfigSourceProviderBuildItem("org.keycloak.quarkus.runtime.configuration.test.TestKeycloakConfigSourceProvider"));
    // this might be too sensitive and break if Quarkus changes the behavior
    if (dbConfig != null && dbConfig.getDefaultDatasource() != null) {
        Map<String, String> configProperties = dbConfig.getDefaultDatasource().getConfigProperties();
        for (Entry<String, String> dbConfigProperty : configProperties.entrySet()) {
            PropertyMapper mapper = PropertyMappers.getMapper(dbConfigProperty.getKey());
            if (mapper == null) {
                continue;
            }
            String kcProperty = mapper.getFrom();
            if (kcProperty.endsWith("db")) {
                // db kind set when running tests
                continue;
            }
            System.setProperty(kcProperty, dbConfigProperty.getValue());
        }
    }
}
Also used : StaticInitConfigSourceProviderBuildItem(io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method initializeFilter.

@BuildStep
void initializeFilter(BuildProducer<FilterBuildItem> filters, LaunchModeBuildItem launchModeBuildItem) {
    QuarkusRequestFilter filter = new QuarkusRequestFilter();
    LaunchMode launchMode = launchModeBuildItem.getLaunchMode();
    if (launchMode.isDevOrTest()) {
        filter = new QuarkusDevRequestFilter();
    }
    filters.produce(new FilterBuildItem(filter, FilterBuildItem.AUTHORIZATION - 10));
}
Also used : LaunchMode(io.quarkus.runtime.LaunchMode) QuarkusRequestFilter(org.keycloak.quarkus.runtime.integration.web.QuarkusRequestFilter) QuarkusDevRequestFilter(org.keycloak.quarkus.runtime.dev.QuarkusDevRequestFilter) FilterBuildItem(io.quarkus.vertx.http.deployment.FilterBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method index.

/**
 * This will cause quarkus tu include specified modules in the jandex index. For example keycloak-services is needed as it includes
 * most of the JAX-RS resources, which are required to register Resteasy builtin providers. See {@link ResteasyDeployment#isRegisterBuiltin()}.
 * Similar reason is liquibase
 *
 * @param indexDependencyBuildItemBuildProducer
 */
@BuildStep
void index(BuildProducer<IndexDependencyBuildItem> indexDependencyBuildItemBuildProducer) {
    indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.liquibase", "liquibase-core"));
    indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-services"));
}
Also used : IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 5 with BuildStep

use of io.quarkus.deployment.annotations.BuildStep in project keycloak by keycloak.

the class KeycloakProcessor method persistBuildTimeProperties.

/**
 * <p>Make the build time configuration available at runtime so that the server can run without having to specify some of
 * the properties again.
 */
@BuildStep(onlyIf = IsReAugmentation.class)
void persistBuildTimeProperties(BuildProducer<GeneratedResourceBuildItem> resources) {
    Properties properties = new Properties();
    for (String name : getPropertyNames()) {
        PropertyMapper mapper = PropertyMappers.getMapper(name);
        ConfigValue value = null;
        if (mapper == null) {
            if (name.startsWith(NS_QUARKUS)) {
                value = Configuration.getConfigValue(name);
                if (!QuarkusPropertiesConfigSource.isSameSource(value)) {
                    continue;
                }
            }
        } else if (mapper.isBuildTime()) {
            name = mapper.getFrom();
            value = Configuration.getConfigValue(name);
        }
        if (value != null && value.getValue() != null) {
            properties.put(name, value.getValue());
        }
    }
    for (File jar : getProviderFiles().values()) {
        properties.put(String.format("kc.provider.file.%s.last-modified", jar.getName()), String.valueOf(jar.lastModified()));
    }
    String profile = Environment.getProfile();
    if (profile != null) {
        properties.put(Environment.PROFILE, profile);
        properties.put(ProfileManager.QUARKUS_PROFILE_PROP, profile);
    }
    properties.put(QUARKUS_PROPERTY_ENABLED, String.valueOf(QuarkusPropertiesConfigSource.getConfigurationFile() != null));
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        properties.store(outputStream, " Auto-generated, DO NOT change this file");
        resources.produce(new GeneratedResourceBuildItem(PersistedConfigSource.PERSISTED_PROPERTIES, outputStream.toByteArray()));
    } catch (Exception cause) {
        throw new RuntimeException("Failed to persist configuration", cause);
    }
}
Also used : ConfigValue(io.smallrye.config.ConfigValue) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) PropertyMapper(org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper) File(java.io.File) JarFile(java.util.jar.JarFile) IOException(java.io.IOException) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)11 Record (io.quarkus.deployment.annotations.Record)4 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)2 Consume (io.quarkus.deployment.annotations.Consume)2 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)2 HotDeploymentWatchedFileBuildItem (io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem)2 IndexDependencyBuildItem (io.quarkus.deployment.builditem.IndexDependencyBuildItem)2 StaticInitConfigSourceProviderBuildItem (io.quarkus.deployment.builditem.StaticInitConfigSourceProviderBuildItem)2 ResteasyDeploymentCustomizerBuildItem (io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem)2 LaunchMode (io.quarkus.runtime.LaunchMode)2 SmallRyeHealthHandler (io.quarkus.smallrye.health.runtime.SmallRyeHealthHandler)2 FilterBuildItem (io.quarkus.vertx.http.deployment.FilterBuildItem)2 ConfigValue (io.smallrye.config.ConfigValue)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)2