Search in sources :

Example 1 with TrustyServiceInMemoryContainer

use of org.kie.kogito.tracing.decision.quarkus.devservices.TrustyServiceInMemoryContainer in project kogito-runtimes by kiegroup.

the class KogitoDevServicesProcessor method startTrustyService.

private TrustyServiceInstance startTrustyService(final TrustyServiceDevServiceConfig config, final DevServicesConfig devServicesConfig, final LaunchModeBuildItem launchMode, final boolean useSharedNetwork) {
    if (!config.devServicesEnabled) {
        // explicitly disabled
        LOGGER.info("Not starting DevServices for Kogito, as it has been disabled in the config.");
        return null;
    }
    if (!isDockerWorking.getAsBoolean()) {
        LOGGER.warn("Docker isn't working, unable to start TrustyService image.");
        return null;
    }
    final Optional<ContainerAddress> maybeContainerAddress = LOCATOR.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode());
    // Starting TrustyService
    final Supplier<TrustyServiceInstance> trustyServiceSupplier = () -> {
        try {
            TrustyServiceInMemoryContainer container = new TrustyServiceInMemoryContainer(DockerImageName.parse(config.imageName), config.fixedExposedPort, launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT ? config.serviceName : null, useSharedNetwork);
            LOGGER.debug(String.format("TrustyService DataSource Kind: %s", devServicesConfig.getDataSourceKind()));
            LOGGER.debug(String.format("TrustyService DataSource Username: %s", devServicesConfig.getDataSourceUserName()));
            LOGGER.debug(String.format("TrustyService DataSource Password: %s", devServicesConfig.getDataSourcePassword()));
            LOGGER.debug(String.format("TrustyService DataSource URL: %s", devServicesConfig.getDataSourceUrl()));
            LOGGER.debug(String.format("TrustyService Kafka Bootstrap Server: %s", devServicesConfig.getKafkaBootstrapServer()));
            LOGGER.debug(String.format("TrustyService Hibernate ORM Database Generation: %s", devServicesConfig.getHibernateOrmDatabaseGeneration()));
            // Environment variables used by kogito-images when launching the TrustyService container
            container.addEnv("SCRIPT_DEBUG", "false");
            container.addEnv("EXPLAINABILITY_ENABLED", "false");
            // Environment variables used by TrustyService to integrate with other services
            container.addEnv(QuarkusDataSourceDbKind.getEnvironmentVariableName(), devServicesConfig.getDataSourceKind());
            container.addEnv(QuarkusDataSourceUserName.getEnvironmentVariableName(), devServicesConfig.getDataSourceUserName());
            container.addEnv(QuarkusDataSourcePassword.getEnvironmentVariableName(), devServicesConfig.getDataSourcePassword());
            container.addEnv(QuarkusDataSourceJdbcUrl.getEnvironmentVariableName(), devServicesConfig.getDataSourceUrl());
            container.addEnv(KafkaBootstrapServers.getEnvironmentVariableName(), devServicesConfig.getKafkaBootstrapServer());
            container.addEnv(HibernateOrmDatabaseGeneration.getEnvironmentVariableName(), devServicesConfig.getHibernateOrmDatabaseGeneration());
            container.start();
            return new TrustyServiceInstance(container.getUrl(), container::close);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    };
    return maybeContainerAddress.map(containerAddress -> new TrustyServiceInstance(containerAddress.getUrl(), null)).orElseGet(trustyServiceSupplier);
}
Also used : Arrays(java.util.Arrays) DockerImageName(org.testcontainers.utility.DockerImageName) DevServicesSharedNetworkBuildItem(io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem) LoggerFactory(org.slf4j.LoggerFactory) Container(com.github.dockerjava.api.model.Container) SystemPropertyBuildItem(io.quarkus.deployment.builditem.SystemPropertyBuildItem) LaunchMode(io.quarkus.runtime.LaunchMode) ConsoleInstalledBuildItem(io.quarkus.deployment.console.ConsoleInstalledBuildItem) Supplier(java.util.function.Supplier) IsDevelopment(io.quarkus.deployment.IsDevelopment) IsDockerWorking(io.quarkus.deployment.IsDockerWorking) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) BuildStep(io.quarkus.deployment.annotations.BuildStep) QuarkusDataSourcePassword(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourcePassword) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) HibernateOrmDatabaseGeneration(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.HibernateOrmDatabaseGeneration) QuarkusDataSourceDbKind(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourceDbKind) ContainerNetworkSettings(com.github.dockerjava.api.model.ContainerNetworkSettings) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) KafkaBootstrapServers(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.KafkaBootstrapServers) TrustyServiceInMemoryContainer(org.kie.kogito.tracing.decision.quarkus.devservices.TrustyServiceInMemoryContainer) Logger(org.slf4j.Logger) StartupLogCompressor(io.quarkus.deployment.console.StartupLogCompressor) ContainerAddress(io.quarkus.devservices.common.ContainerAddress) TrustyServiceAvailableBuildItem(org.kie.kogito.quarkus.addons.common.deployment.TrustyServiceAvailableBuildItem) GlobalDevServicesConfig(io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig) ContainerLocator(io.quarkus.devservices.common.ContainerLocator) Collectors(java.util.stream.Collectors) QuarkusDataSourceJdbcUrl(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourceJdbcUrl) QuarkusDataSourceUserName(org.kie.kogito.tracing.decision.quarkus.deployment.DevServicesConfig.Property.QuarkusDataSourceUserName) Objects(java.util.Objects) List(java.util.List) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) Closeable(java.io.Closeable) Optional(java.util.Optional) ContainerPort(com.github.dockerjava.api.model.ContainerPort) DockerClientFactory(org.testcontainers.DockerClientFactory) KOGITO_TRUSTY_SERVICE(org.kie.kogito.tracing.decision.TrustyConstants.KOGITO_TRUSTY_SERVICE) ContainerNetwork(com.github.dockerjava.api.model.ContainerNetwork) TrustyServiceInMemoryContainer(org.kie.kogito.tracing.decision.quarkus.devservices.TrustyServiceInMemoryContainer) ContainerAddress(io.quarkus.devservices.common.ContainerAddress)

Aggregations

Container (com.github.dockerjava.api.model.Container)1 ContainerNetwork (com.github.dockerjava.api.model.ContainerNetwork)1 ContainerNetworkSettings (com.github.dockerjava.api.model.ContainerNetworkSettings)1 ContainerPort (com.github.dockerjava.api.model.ContainerPort)1 IsDevelopment (io.quarkus.deployment.IsDevelopment)1 IsDockerWorking (io.quarkus.deployment.IsDockerWorking)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 CuratedApplicationShutdownBuildItem (io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem)1 DevServicesSharedNetworkBuildItem (io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem)1 LaunchModeBuildItem (io.quarkus.deployment.builditem.LaunchModeBuildItem)1 SystemPropertyBuildItem (io.quarkus.deployment.builditem.SystemPropertyBuildItem)1 ConsoleInstalledBuildItem (io.quarkus.deployment.console.ConsoleInstalledBuildItem)1 StartupLogCompressor (io.quarkus.deployment.console.StartupLogCompressor)1 GlobalDevServicesConfig (io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig)1 LoggingSetupBuildItem (io.quarkus.deployment.logging.LoggingSetupBuildItem)1 ContainerAddress (io.quarkus.devservices.common.ContainerAddress)1 ContainerLocator (io.quarkus.devservices.common.ContainerLocator)1 LaunchMode (io.quarkus.runtime.LaunchMode)1 Closeable (java.io.Closeable)1