mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(glue): populate CatalogId on GetDatabase and GetDatabases (#2814)
* fix(glue): populate CatalogId on GetDatabase and GetDatabases The Glue database responses never set CatalogId, so terraform-provider-aws built the aws_glue_catalog_database resource id as ":name" and failed with "unexpected format for ID, expected catalog-id:database-name". Resolve it per request from the caller's account, matching the convention LakeFormationService already uses, rather than persisting it with the database, so existing stores need no migration. Refs #2793 * fix(glue): set CatalogId at write time, backfill legacy rows on read Addresses review feedback: populating CatalogId on the read path mutated the Database instance owned by the store, so a GetDatabase call could persist a request-derived value. Set it when the database is created or updated instead. Reads only fill it in for rows persisted before the field existed, which is stable because the store is namespaced by account -- the same migrate-on-read AccountAwareStorageBackend already does for un-prefixed keys.
This commit is contained in:
1 parent
279f2776b7
commit
342f58b2b7
4 files changed
+109
-3
No files matched your search
+65
@@ -0,0 +1,65 @@
|
||||
package io.github.hectorvent.floci.services.glue;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* terraform-provider-aws builds the aws_glue_catalog_database resource id as
|
||||
* {@code catalog-id:database-name}, so an absent CatalogId yields a malformed id.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class GlueDatabaseCatalogIdIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String ACCOUNT_ID = "000000000000";
|
||||
private static final String DATABASE_NAME = "catalog-id-db-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDatabaseAndGetDatabasesReturnCatalogId() {
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.CreateDatabase")
|
||||
.body("""
|
||||
{
|
||||
"DatabaseInput": {
|
||||
"Name": "%s"
|
||||
}
|
||||
}
|
||||
""".formatted(DATABASE_NAME))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetDatabase")
|
||||
.body("""
|
||||
{
|
||||
"Name": "%s"
|
||||
}
|
||||
""".formatted(DATABASE_NAME))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Database.Name", equalTo(DATABASE_NAME))
|
||||
.body("Database.CatalogId", equalTo(ACCOUNT_ID));
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetDatabases")
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DatabaseList.find { it.Name == '%s' }.CatalogId".formatted(DATABASE_NAME),
|
||||
equalTo(ACCOUNT_ID));
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ class GlueServiceTest {
|
||||
|
||||
private GlueService glueService;
|
||||
private GlueSchemaRegistryService schemaRegistryService;
|
||||
private StorageBackend<String, Database> databaseStore;
|
||||
private StorageBackend<String, Table> tableStore;
|
||||
private StorageBackend<String, Table> tableVersionStore;
|
||||
private StorageBackend<String, Map<String, Object>> columnStatisticsStore;
|
||||
@@ -64,12 +65,13 @@ class GlueServiceTest {
|
||||
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT_ID);
|
||||
StorageFactory storageFactory = new InMemoryStorageFactory();
|
||||
schemaRegistryService = new GlueSchemaRegistryService(storageFactory, regionResolver);
|
||||
databaseStore = new InMemoryStorage<>();
|
||||
tableStore = new InMemoryStorage<>();
|
||||
tableVersionStore = new InMemoryStorage<>();
|
||||
columnStatisticsStore = new InMemoryStorage<>();
|
||||
partitionStore = new InMemoryStorage<>();
|
||||
glueService = new GlueService(
|
||||
new InMemoryStorage<String, Database>(),
|
||||
databaseStore,
|
||||
tableStore,
|
||||
tableVersionStore,
|
||||
columnStatisticsStore,
|
||||
@@ -82,6 +84,24 @@ class GlueServiceTest {
|
||||
glueService.createDatabase(new Database("db1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDatabasePersistsCatalogIdSoReadsDoNotWriteIt() {
|
||||
assertEquals(ACCOUNT_ID, databaseStore.get("db1").orElseThrow().getCatalogId());
|
||||
assertEquals(ACCOUNT_ID, glueService.getDatabase("db1").getCatalogId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void databasePersistedBeforeCatalogIdWasModelledIsBackfilledOnRead() {
|
||||
Database legacy = new Database("legacy-db");
|
||||
legacy.setCatalogId(null);
|
||||
databaseStore.put("legacy-db", legacy);
|
||||
|
||||
assertEquals(ACCOUNT_ID, glueService.getDatabase("legacy-db").getCatalogId());
|
||||
assertEquals(ACCOUNT_ID, glueService.getDatabases().stream()
|
||||
.filter(database -> "legacy-db".equals(database.getName()))
|
||||
.findFirst().orElseThrow().getCatalogId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTableWithoutSchemaReferenceReturnsColumnsUnchanged() {
|
||||
Table table = new Table();
|
||||
|
||||
Reference in new issue
Block a user