|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Airbyte, Inc., all rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +package io.airbyte.integrations.destination.iceberg.container; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.databind.JsonNode; |
| 8 | +import io.airbyte.commons.json.Jsons; |
| 9 | +import io.airbyte.integrations.destination.iceberg.config.format.DataFileFormat; |
| 10 | +import io.airbyte.integrations.destination.iceberg.hive.IcebergHiveCatalogS3ParquetIntegrationTest; |
| 11 | +import org.slf4j.Logger; |
| 12 | +import org.slf4j.LoggerFactory; |
| 13 | +import org.testcontainers.containers.DockerComposeContainer; |
| 14 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 15 | + |
| 16 | +import java.nio.file.Path; |
| 17 | +import java.time.Duration; |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.ICEBERG_CATALOG_CONFIG_KEY; |
| 21 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.ICEBERG_CATALOG_TYPE_CONFIG_KEY; |
| 22 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.ICEBERG_FORMAT_CONFIG_KEY; |
| 23 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.ICEBERG_STORAGE_CONFIG_KEY; |
| 24 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.ICEBERG_STORAGE_TYPE_CONFIG_KEY; |
| 25 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.REST_CATALOG_URI_CONFIG_KEY; |
| 26 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.S3_ACCESS_KEY_ID_CONFIG_KEY; |
| 27 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.S3_BUCKET_REGION_CONFIG_KEY; |
| 28 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.S3_ENDPOINT_CONFIG_KEY; |
| 29 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.S3_SECRET_KEY_CONFIG_KEY; |
| 30 | +import static io.airbyte.integrations.destination.iceberg.IcebergConstants.S3_WAREHOUSE_URI_CONFIG_KEY; |
| 31 | +import static java.util.Map.entry; |
| 32 | +import static java.util.Map.ofEntries; |
| 33 | + |
| 34 | +public class RESTServerWithMinioCompose extends DockerComposeContainer<RESTServerWithMinioCompose> { |
| 35 | + |
| 36 | + private static final Logger LOGGER = LoggerFactory.getLogger(IcebergHiveCatalogS3ParquetIntegrationTest.class); |
| 37 | + private static final String LOCAL_RELATIVE_PATH = "src/test-integration/resources/"; |
| 38 | + private static final String COMPOSE_PATH = LOCAL_RELATIVE_PATH + "rest-catalog-compose.yml"; |
| 39 | + private static final int REST_SERVER_PORT = 8181; |
| 40 | + private static final int MINIO_PORT = 9000; |
| 41 | + private static final String REST_SERVICE_NAME = "rest_1"; |
| 42 | + private static final String MINIO_SERVICE_NAME = "minio_1"; |
| 43 | + |
| 44 | + public RESTServerWithMinioCompose() { |
| 45 | + super(Path.of(COMPOSE_PATH).toFile()); |
| 46 | + super.withExposedService(REST_SERVICE_NAME, |
| 47 | + REST_SERVER_PORT, |
| 48 | + Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(30))) |
| 49 | + .withExposedService(MINIO_SERVICE_NAME, |
| 50 | + MinioContainer.MINIO_PORT, |
| 51 | + Wait.forHttp(MinioContainer.HEALTH_ENDPOINT).withStartupTimeout(Duration.ofSeconds(60))) |
| 52 | + .withLocalCompose(true); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void start() { |
| 57 | + long startTime = System.currentTimeMillis(); |
| 58 | + super.start(); |
| 59 | + LOGGER.info("REST Server port: {}", getServicePort(REST_SERVICE_NAME, REST_SERVER_PORT)); |
| 60 | + LOGGER.info("Minio port: {}", getServicePort(MINIO_SERVICE_NAME, MINIO_PORT)); |
| 61 | + LOGGER.info("REST Server docker-compose startup cost: {} ms", System.currentTimeMillis() - startTime); |
| 62 | + } |
| 63 | + |
| 64 | + public String s3Endpoint() { |
| 65 | + return "http://localhost:" + getServicePort(MINIO_SERVICE_NAME, MINIO_PORT); |
| 66 | + } |
| 67 | + |
| 68 | + public String restServerUri() { |
| 69 | + return "http://localhost:" + getServicePort(REST_SERVICE_NAME, REST_SERVER_PORT); |
| 70 | + } |
| 71 | + |
| 72 | + public JsonNode getComposeConfig(DataFileFormat fileFormat) { |
| 73 | + String s3Endpoint = this.s3Endpoint(); |
| 74 | + LOGGER.info("Configure S3 endpoint to {}", s3Endpoint); |
| 75 | + return Jsons.jsonNode(ofEntries( |
| 76 | + entry(ICEBERG_CATALOG_CONFIG_KEY, |
| 77 | + Jsons.jsonNode(ofEntries( |
| 78 | + entry(ICEBERG_CATALOG_TYPE_CONFIG_KEY, "Rest"), |
| 79 | + entry(REST_CATALOG_URI_CONFIG_KEY, this.restServerUri())))), |
| 80 | + entry(ICEBERG_STORAGE_CONFIG_KEY, |
| 81 | + Jsons.jsonNode(ofEntries( |
| 82 | + entry(ICEBERG_STORAGE_TYPE_CONFIG_KEY, "S3"), |
| 83 | + entry(S3_ACCESS_KEY_ID_CONFIG_KEY, "admin"), |
| 84 | + entry(S3_SECRET_KEY_CONFIG_KEY, "password"), |
| 85 | + entry(S3_WAREHOUSE_URI_CONFIG_KEY, "s3://warehouse/rest"), |
| 86 | + entry(S3_BUCKET_REGION_CONFIG_KEY, "us-east-1"), |
| 87 | + entry(S3_ENDPOINT_CONFIG_KEY, s3Endpoint)))), |
| 88 | + entry(ICEBERG_FORMAT_CONFIG_KEY, |
| 89 | + Jsons.jsonNode(Map.of("format", fileFormat.getConfigValue()))))); |
| 90 | + } |
| 91 | + |
| 92 | + public JsonNode getWrongConfig() { |
| 93 | + return Jsons.jsonNode(ofEntries( |
| 94 | + entry(ICEBERG_CATALOG_CONFIG_KEY, |
| 95 | + Jsons.jsonNode(ofEntries( |
| 96 | + entry(ICEBERG_CATALOG_TYPE_CONFIG_KEY, "Rest"), |
| 97 | + entry(REST_CATALOG_URI_CONFIG_KEY, "wrong-host:1234")))), |
| 98 | + entry(ICEBERG_STORAGE_CONFIG_KEY, |
| 99 | + Jsons.jsonNode(ofEntries(entry(ICEBERG_STORAGE_TYPE_CONFIG_KEY, "S3"), |
| 100 | + entry(S3_ACCESS_KEY_ID_CONFIG_KEY, "wrong_access_key"), |
| 101 | + entry(S3_SECRET_KEY_CONFIG_KEY, "wrong_secret_key"), |
| 102 | + entry(S3_WAREHOUSE_URI_CONFIG_KEY, "s3://warehouse/"), |
| 103 | + entry(S3_BUCKET_REGION_CONFIG_KEY, "us-east-1"), |
| 104 | + entry(S3_ENDPOINT_CONFIG_KEY, this.s3Endpoint())))), |
| 105 | + entry(ICEBERG_FORMAT_CONFIG_KEY, Jsons.jsonNode(Map.of("format", "wrong-format"))))); |
| 106 | + } |
| 107 | +} |
0 commit comments