From 040fa595cf79f3346c0a0ae3954d24658e363663 Mon Sep 17 00:00:00 2001 From: praveenkrishna Date: Thu, 25 Nov 2021 17:13:58 +0530 Subject: [PATCH] Extract configuration to HydraIdentityProvider This allows us to reuse to HydraIdentityProvider across various environment. --- .../env/common/HydraIdentityProvider.java | 17 ++++++++++++++ .../env/environment/EnvSinglenodeOauth2.java | 22 +++++-------------- ...empto-configuration-for-docker-oauth2.yaml | 0 3 files changed, 23 insertions(+), 16 deletions(-) rename testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/{conf/tempto => common/hydra-identity-provider}/tempto-configuration-for-docker-oauth2.yaml (100%) diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/common/HydraIdentityProvider.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/common/HydraIdentityProvider.java index 1eb4773fbb38..b3adcd84b59c 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/common/HydraIdentityProvider.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/common/HydraIdentityProvider.java @@ -22,6 +22,10 @@ import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.containers.wait.strategy.WaitAllStrategy; +import static io.trino.tests.product.launcher.env.EnvironmentContainers.TESTS; +import static io.trino.tests.product.launcher.env.EnvironmentContainers.isPrestoContainer; +import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_ETC; +import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_TEMPTO_PROFILE_CONFIG; import static java.util.Objects.requireNonNull; import static org.testcontainers.utility.MountableFile.forHostPath; @@ -88,6 +92,19 @@ public void extendEnvironment(Environment.Builder builder) builder.containerDependsOn(hydra.getLogicalName(), hydraConsent.getLogicalName()); builder.containerDependsOn(hydra.getLogicalName(), migrationContainer.getLogicalName()); builder.containerDependsOn(hydra.getLogicalName(), databaseContainer.getLogicalName()); + + builder.configureContainers(dockerContainer -> { + if (isPrestoContainer(dockerContainer.getLogicalName())) { + dockerContainer + .withCopyFileToContainer( + forHostPath(configDir.getPath("cert")), + CONTAINER_PRESTO_ETC + "/hydra/cert"); + } + }); + + builder.configureContainer(TESTS, dockerContainer -> dockerContainer.withCopyFileToContainer( + forHostPath(configDir.getPath("tempto-configuration-for-docker-oauth2.yaml")), + CONTAINER_TEMPTO_PROFILE_CONFIG)); } public DockerContainer createClient( diff --git a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeOauth2.java b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeOauth2.java index 935638d6fd93..a299dbad3816 100644 --- a/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeOauth2.java +++ b/testing/trino-product-tests-launcher/src/main/java/io/trino/tests/product/launcher/env/environment/EnvSinglenodeOauth2.java @@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableList; import io.trino.tests.product.launcher.docker.DockerFiles; +import io.trino.tests.product.launcher.docker.DockerFiles.ResourceProvider; import io.trino.tests.product.launcher.env.DockerContainer; import io.trino.tests.product.launcher.env.Environment; import io.trino.tests.product.launcher.env.EnvironmentProvider; @@ -30,10 +31,7 @@ import java.util.List; import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR; -import static io.trino.tests.product.launcher.env.EnvironmentContainers.TESTS; import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_CONFIG_PROPERTIES; -import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_ETC; -import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_TEMPTO_PROFILE_CONFIG; import static java.util.Objects.requireNonNull; import static org.testcontainers.utility.MountableFile.forHostPath; @@ -43,7 +41,7 @@ public class EnvSinglenodeOauth2 { private final PortBinder binder; private final HydraIdentityProvider hydraIdentityProvider; - private final DockerFiles dockerFiles; + private final ResourceProvider configDir; @Inject public EnvSinglenodeOauth2(DockerFiles dockerFiles, PortBinder binder, Standard standard, HydraIdentityProvider hydraIdentityProvider, SeleniumChrome seleniumChrome) @@ -52,7 +50,8 @@ public EnvSinglenodeOauth2(DockerFiles dockerFiles, PortBinder binder, Standard this.binder = requireNonNull(binder, "binder is null"); this.hydraIdentityProvider = requireNonNull(hydraIdentityProvider, "hydraIdentityProvider is null"); - this.dockerFiles = requireNonNull(dockerFiles, "dockerFiles is null"); + requireNonNull(dockerFiles, "dockerFiles is null"); + this.configDir = dockerFiles.getDockerFilesHostDirectory("conf/environment/singlenode-oauth2/"); } @Override @@ -61,21 +60,12 @@ public void extendEnvironment(Environment.Builder builder) builder.configureContainer(COORDINATOR, dockerContainer -> { dockerContainer .withCopyFileToContainer( - forHostPath(dockerFiles.getDockerFilesHostPath("conf/environment/singlenode-oauth2/config.properties")), - CONTAINER_PRESTO_CONFIG_PROPERTIES) - .withCopyFileToContainer( - forHostPath(dockerFiles.getDockerFilesHostPath("common/hydra-identity-provider/cert")), - CONTAINER_PRESTO_ETC + "/hydra/cert"); + forHostPath(configDir.getPath("config.properties")), + CONTAINER_PRESTO_CONFIG_PROPERTIES); binder.exposePort(dockerContainer, 7778); }); - builder.configureContainer(TESTS, dockerContainer -> { - dockerContainer.withCopyFileToContainer( - forHostPath(dockerFiles.getDockerFilesHostPath("conf/tempto/tempto-configuration-for-docker-oauth2.yaml")), - CONTAINER_TEMPTO_PROFILE_CONFIG); - }); - DockerContainer hydraClientConfig = hydraIdentityProvider.createClient( builder, "trinodb_client_id", diff --git a/testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/conf/tempto/tempto-configuration-for-docker-oauth2.yaml b/testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/common/hydra-identity-provider/tempto-configuration-for-docker-oauth2.yaml similarity index 100% rename from testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/conf/tempto/tempto-configuration-for-docker-oauth2.yaml rename to testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/common/hydra-identity-provider/tempto-configuration-for-docker-oauth2.yaml