Search in sources :

Example 1 with DevServicesConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem in project quarkus-neo4j by quarkiverse.

the class Neo4jDevServicesProcessor method startNeo4jDevService.

@BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class)
public Neo4jDevServiceBuildItem startNeo4jDevService(LaunchModeBuildItem launchMode, Neo4jBuildTimeConfig neo4jBuildTimeConfig, BuildProducer<DevServicesConfigResultBuildItem> devServicePropertiesProducer, Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig globalDevServicesConfig) {
    var configuration = new Neo4jDevServiceConfig(neo4jBuildTimeConfig.devservices);
    if (closeable != null) {
        if (configuration.equals(runningConfiguration)) {
            return null;
        }
        shutdownNeo4j();
        runningConfiguration = null;
    }
    var compressor = new StartupLogCompressor((launchMode.isTest() ? "(test) " : "") + "Neo4j Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem);
    try {
        var neo4jContainer = startNeo4j(configuration, globalDevServicesConfig.timeout);
        if (neo4jContainer != null) {
            devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(NEO4J_URI, neo4jContainer.getBoltUrl()));
            devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(NEO4J_BROWSER_URL, neo4jContainer.getBrowserUrl()));
            devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(NEO4J_USER_PROP, "neo4j"));
            devServicePropertiesProducer.produce(new DevServicesConfigResultBuildItem(NEO4J_PASSWORD_PROP, neo4jContainer.getAdminPassword()));
            log.infof("Dev Services started a Neo4j container reachable at %s", neo4jContainer.getBoltUrl());
            log.infof("Neo4j Browser is reachable at %s", neo4jContainer.getBrowserUrl());
            log.infof("The username for both endpoints is `%s`, authenticated by `%s`", "neo4j", neo4jContainer.getAdminPassword());
            log.infof("Connect via Cypher-Shell: cypher-shell -u %s -p %s -a %s", "neo4j", neo4jContainer.getAdminPassword(), neo4jContainer.getBoltUrl());
            closeable = neo4jContainer::close;
        }
    } catch (Throwable t) {
        compressor.closeAndDumpCaptured();
        throw new RuntimeException(t);
    }
    // Configure the watch dog
    if (first) {
        first = false;
        Runnable closeTask = () -> {
            if (closeable != null) {
                shutdownNeo4j();
                log.info("Dev Services for Neo4j shut down.");
            }
            first = true;
            closeable = null;
            runningConfiguration = null;
        };
        closeBuildItem.addCloseTask(closeTask, true);
    }
    runningConfiguration = configuration;
    return new Neo4jDevServiceBuildItem();
}
Also used : StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) DevServicesConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with DevServicesConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem in project quarkus by quarkusio.

the class DevServicesConfigBuildStep method setup.

@BuildStep
@Produce(ServiceStartBuildItem.class)
DevServicesLauncherConfigResultBuildItem setup(BuildProducer<RunTimeConfigurationDefaultBuildItem> runtimeConfig, List<DevServicesConfigResultBuildItem> devServicesConfigResultBuildItems, List<DevServicesResultBuildItem> devServicesResultBuildItems, CuratedApplicationShutdownBuildItem shutdownBuildItem) {
    Map<String, String> newProperties = new HashMap<>(devServicesConfigResultBuildItems.stream().collect(Collectors.toMap(DevServicesConfigResultBuildItem::getKey, DevServicesConfigResultBuildItem::getValue)));
    for (DevServicesResultBuildItem resultBuildItem : devServicesResultBuildItems) {
        newProperties.putAll(resultBuildItem.getConfig());
    }
    Config config = ConfigProvider.getConfig();
    // we also check the current config, as the dev service may have been disabled by explicit config
    if (oldConfig != null) {
        for (Map.Entry<String, String> entry : oldConfig.entrySet()) {
            if (!newProperties.containsKey(entry.getKey()) && config.getOptionalValue(entry.getKey(), String.class).isEmpty()) {
                newProperties.put(entry.getKey(), entry.getValue());
            }
        }
    } else {
        shutdownBuildItem.addCloseTask(new Runnable() {

            @Override
            public void run() {
                oldConfig = null;
            }
        }, true);
    }
    for (Map.Entry<String, String> entry : newProperties.entrySet()) {
        runtimeConfig.produce(new RunTimeConfigurationDefaultBuildItem(entry.getKey(), entry.getValue()));
    }
    oldConfig = newProperties;
    return new DevServicesLauncherConfigResultBuildItem(Collections.unmodifiableMap(newProperties));
}
Also used : DevServicesLauncherConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem) DevServicesConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem) HashMap(java.util.HashMap) Config(org.eclipse.microprofile.config.Config) DevServicesResultBuildItem(io.quarkus.deployment.builditem.DevServicesResultBuildItem) HashMap(java.util.HashMap) Map(java.util.Map) RunTimeConfigurationDefaultBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with DevServicesConfigResultBuildItem

use of io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem in project kogito-runtimes by kiegroup.

the class DevServicesSetupEnvironmentProcessor method extractDevServicesDefaultDataSourceConfiguration.

@SuppressWarnings("unused")
@BuildStep(onlyIf = IsDevelopment.class)
public void extractDevServicesDefaultDataSourceConfiguration(final BuildProducer<DevServicesConfigResultBuildItem> devServicesConfigResultBuilder, final BuildProducer<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItemBuildProducer) {
    LOGGER.debug("Checking DevService configuration...");
    if (!ConfigUtils.isPropertyPresent(HibernateOrmDatabaseGeneration.getPropertyName())) {
        LOGGER.debug(String.format("Setting %s=%s to initialize DevServices managed database", HibernateOrmDatabaseGeneration.getPropertyName(), HIBERNATE_ORM_DATABASE_GENERATION_STRATEGY));
        devServicesConfigResultBuilder.produce(new DevServicesConfigResultBuildItem(HibernateOrmDatabaseGeneration.getPropertyName(), HIBERNATE_ORM_DATABASE_GENERATION_STRATEGY));
    }
    LOGGER.debug("Enabling use of TestContainers 'Shared Network' for all containers started by Quarkus.");
    devServicesSharedNetworkBuildItemBuildProducer.produce(new DevServicesSharedNetworkBuildItem());
}
Also used : DevServicesConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)3 DevServicesConfigResultBuildItem (io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem)3 Produce (io.quarkus.deployment.annotations.Produce)1 DevServicesLauncherConfigResultBuildItem (io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem)1 DevServicesResultBuildItem (io.quarkus.deployment.builditem.DevServicesResultBuildItem)1 DevServicesSharedNetworkBuildItem (io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem)1 RunTimeConfigurationDefaultBuildItem (io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem)1 StartupLogCompressor (io.quarkus.deployment.console.StartupLogCompressor)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Config (org.eclipse.microprofile.config.Config)1