mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix: keep EMR security configurations, ElastiCache parameter groups and Glue Schema Registry resources in their Region (#8611)
EMR security configurations, ElastiCache cache parameter groups and Glue Schema Registry registries and schemas are now stored under their Region, so each is listed and reached only in the Region it was created in, and its name is free in other Regions. Another Region's resource answers the error each service already gives for one that does not exist, and each Region gets its own default Glue registry. Records stored before move at startup, in every account: to the Region their ARN names, or to the default Region, with a copy in each other Region whose clusters or replication groups name one, through the new AccountAwareStorageBackend.migrateLegacyEntriesToRegions. A Glue schema stored in another Region than its registry gets a copy of that registry there. Part of #8218.
This commit is contained in:
1 parent
b7a95fc920
commit
e44f9137be
17 files changed
+863
-187
No files matched your search
@@ -472,6 +472,40 @@ class AccountAwareStorageBackendTest {
|
||||
Set.copyOf(raw.keys()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A legacy entry is copied to each other Region its account's resources name it in, keeping a record already
|
||||
* there, and then moves to the default Region; one no resource names moves only. The default Region named too
|
||||
* gets the moved entry, not a copy.
|
||||
*/
|
||||
@Test
|
||||
void migrateLegacyEntriesToRegionsCopiesEachToTheRegionsUsingItThenMovesItToTheDefaultRegion() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
raw.put("123456789012/used", "used");
|
||||
raw.put("123456789012/unused", "unused");
|
||||
raw.put("123456789012/eu-west-1::used", "already there");
|
||||
raw.put("gen0", "default-account");
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(raw, null, "000000000000");
|
||||
List<String> asked = new ArrayList<>();
|
||||
|
||||
storage.migrateLegacyEntriesToRegions(key -> !key.contains("::"), "us-east-1",
|
||||
(account, value) -> {
|
||||
asked.add(account + " " + value);
|
||||
return value.equals("used") ? Set.of("us-east-1", "eu-central-1", "eu-west-1") : Set.of();
|
||||
},
|
||||
(region, value) -> region + "::" + value, value -> value + " (copy)");
|
||||
|
||||
assertEquals(List.of("000000000000 default-account", "123456789012 unused", "123456789012 used"),
|
||||
asked.stream().sorted().toList());
|
||||
assertEquals(Map.of(
|
||||
"123456789012/us-east-1::used", "used",
|
||||
"123456789012/eu-central-1::used", "used (copy)",
|
||||
"123456789012/eu-west-1::used", "already there",
|
||||
"123456789012/us-east-1::unused", "unused",
|
||||
"000000000000/us-east-1::default-account", "default-account"),
|
||||
raw.keys().stream().collect(Collectors.toMap(key -> key, key -> raw.get(key).orElseThrow())));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code get} and {@code getForAccountMigratingLegacy} both migrate a pre-multi-account entry, and
|
||||
* both delete the legacy key once they have copied it. Unless they hold the same monitor, two readers
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package io.floci.aws.services.elasticache;
|
||||
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.services.elasticache.model.CacheParameterGroup;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroup;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Cache parameter groups stored before they were keyed by Region, under their bare name, move at startup to the
|
||||
* default Region, and every other Region where one of the account's replication groups names one gets a copy of it,
|
||||
* so that group still finds it there.
|
||||
*/
|
||||
class ElastiCacheParameterGroupLegacyKeysTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void aLegacyGroupMovesToTheDefaultRegionAndIsCopiedToTheRegionOfAReplicationGroupNamingIt() {
|
||||
ElastiCacheServiceFixture fixture = new ElastiCacheServiceFixture();
|
||||
AccountAwareStorageBackend<CacheParameterGroup> parameterGroups = (AccountAwareStorageBackend<CacheParameterGroup>)
|
||||
fixture.backendsByFile.get("elasticache-parameter-groups.json");
|
||||
AccountAwareStorageBackend<ReplicationGroup> groups = (AccountAwareStorageBackend<ReplicationGroup>)
|
||||
fixture.backendsByFile.get("elasticache-groups.json");
|
||||
CacheParameterGroup used = new CacheParameterGroup("used", "redis7", "named by a group");
|
||||
used.setParameters(new LinkedHashMap<>(Map.of("maxmemory-policy", "allkeys-lru")));
|
||||
parameterGroups.put("used", used);
|
||||
parameterGroups.put("unused", new CacheParameterGroup("unused", "redis7", "named by none"));
|
||||
ReplicationGroup group = new ReplicationGroup();
|
||||
group.setReplicationGroupId("in-frankfurt");
|
||||
group.setArn("arn:aws:elasticache:eu-central-1:" + ACCOUNT + ":replicationgroup:in-frankfurt");
|
||||
group.setCacheParameterGroupName("used");
|
||||
groups.put("in-frankfurt", group);
|
||||
|
||||
fixture.service.migrateLegacyParameterGroups();
|
||||
|
||||
assertEquals(Set.of("us-east-1::used", "us-east-1::unused", "eu-central-1::used"),
|
||||
parameterGroups.keysForAccount(ACCOUNT));
|
||||
assertEquals(Map.of("maxmemory-policy", "allkeys-lru"),
|
||||
parameterGroups.get("eu-central-1::used").orElseThrow().getParameters());
|
||||
// Outside a request, the service answers for the default Region, us-east-1.
|
||||
assertEquals(Set.of("used", "unused"), fixture.service.describeCacheParameterGroups(null).stream()
|
||||
.map(CacheParameterGroup::getName)
|
||||
.filter(name -> !name.startsWith("default."))
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
+30
-4
@@ -11,10 +11,10 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* Replication groups, cache clusters, users and user groups are Regional on AWS: one created in a Region of an
|
||||
* account is listed, and found by its id, only from that Region of that account. Each case creates the resource
|
||||
* in {@link #HOME} of {@link #ACCOUNT} and checks the unfiltered listing and the id filter from there, from
|
||||
* {@link #OTHER_REGION} of the same account, and from {@link #HOME} of {@link #OTHER_ACCOUNT}.
|
||||
* Replication groups, cache clusters, users, user groups and cache parameter groups are Regional on AWS: one
|
||||
* created in a Region of an account is listed, and found by its id, only from that Region of that account. Each case
|
||||
* creates the resource in {@link #HOME} of {@link #ACCOUNT} and checks the unfiltered listing and the id filter from
|
||||
* there, from {@link #OTHER_REGION} of the same account, and from {@link #HOME} of {@link #OTHER_ACCOUNT}.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ElastiCacheRegionScopingIntegrationTest {
|
||||
@@ -106,6 +106,32 @@ class ElastiCacheRegionScopingIntegrationTest {
|
||||
assertCacheClusterIsRegional("region-scoped-memcached", "memcached");
|
||||
}
|
||||
|
||||
@Test
|
||||
void cacheParameterGroupIsOnlyVisibleInItsRegionAndAccountAndItsNameIsFreeElsewhere() {
|
||||
String name = "region-scoped-params";
|
||||
String[] create = {"CacheParameterGroupName", name, "CacheParameterGroupFamily", "redis7",
|
||||
"Description", "scoped"};
|
||||
send(ACCOUNT, HOME, "CreateCacheParameterGroup", create).then().statusCode(200);
|
||||
try {
|
||||
assertRegional("DescribeCacheParameterGroups", "CacheParameterGroupName", name,
|
||||
"<CacheParameterGroupName>" + name + "</CacheParameterGroupName>");
|
||||
send(ACCOUNT, OTHER_REGION, "ModifyCacheParameterGroup", "CacheParameterGroupName", name,
|
||||
"ParameterNameValues.ParameterNameValue.1.ParameterName", "maxmemory-policy",
|
||||
"ParameterNameValues.ParameterNameValue.1.ParameterValue", "allkeys-lru")
|
||||
.then().statusCode(404);
|
||||
send(ACCOUNT, OTHER_REGION, "DeleteCacheParameterGroup", "CacheParameterGroupName", name)
|
||||
.then().statusCode(404);
|
||||
|
||||
send(ACCOUNT, OTHER_REGION, "CreateCacheParameterGroup", create).then().statusCode(200);
|
||||
send(ACCOUNT, OTHER_REGION, "DeleteCacheParameterGroup", "CacheParameterGroupName", name)
|
||||
.then().statusCode(200);
|
||||
send(ACCOUNT, HOME, "DescribeCacheParameterGroups", "CacheParameterGroupName", name)
|
||||
.then().statusCode(200);
|
||||
} finally {
|
||||
send(ACCOUNT, HOME, "DeleteCacheParameterGroup", "CacheParameterGroupName", name).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertCacheClusterIsRegional(String cluster, String engine) {
|
||||
send(ACCOUNT, HOME, "CreateCacheCluster", "CacheClusterId", cluster, "Engine", engine,
|
||||
"NumCacheNodes", "1", "CacheNodeType", "cache.t3.micro").then().statusCode(200);
|
||||
|
||||
@@ -234,7 +234,8 @@ class ElastiCacheServiceTest {
|
||||
|
||||
Field locksField = ElastiCacheService.class.getDeclaredField("parameterGroupLocks");
|
||||
locksField.setAccessible(true);
|
||||
Object monitor = ((ConcurrentHashMap<?, ?>) locksField.get(service)).get(name);
|
||||
// Each group's monitor is keyed by its Region and name, as the group is.
|
||||
Object monitor = ((ConcurrentHashMap<?, ?>) locksField.get(service)).get("us-east-1::" + name);
|
||||
ExecutorService pool = Executors.newSingleThreadExecutor();
|
||||
AtomicReference<Thread> writer = new AtomicReference<>();
|
||||
try {
|
||||
|
||||
@@ -5,6 +5,8 @@ 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.floci.aws.testing.EmrRequests.emr;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
@@ -61,6 +63,39 @@ class EmrClusterRegionIntegrationTest {
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSecurityConfigurationIsListedDescribedAndNamedOnlyInItsRegion() {
|
||||
String name = "sec-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String create = "{\"Name\":\"" + name + "\",\"SecurityConfiguration\":\"{\\\"EncryptionConfiguration\\\":{}}\"}";
|
||||
String byName = "{\"Name\":\"" + name + "\"}";
|
||||
emr(HOME, "CreateSecurityConfiguration", create).then().statusCode(200);
|
||||
try {
|
||||
emr(OTHER, "ListSecurityConfigurations", "{}").then().statusCode(200)
|
||||
.body("SecurityConfigurations.Name", not(hasItem(name)));
|
||||
emr(OTHER, "DescribeSecurityConfiguration", byName).then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"))
|
||||
.body("message", equalTo("Security configuration does not exist: " + name));
|
||||
emr(OTHER, "DeleteSecurityConfiguration", byName).then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
emr(OTHER, "RunJobFlow", "{\"Name\":\"secured\",\"ReleaseLabel\":\"emr-7.5.0\",\"SecurityConfiguration\":\""
|
||||
+ name + "\",\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
|
||||
+ "\"InstanceGroups\":[{\"Name\":\"master\",\"InstanceRole\":\"MASTER\","
|
||||
+ "\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
emr(OTHER, "CreateSecurityConfiguration", create).then().statusCode(200);
|
||||
emr(OTHER, "DeleteSecurityConfiguration", byName).then().statusCode(200);
|
||||
|
||||
emr(HOME, "ListSecurityConfigurations", "{}").then().statusCode(200)
|
||||
.body("SecurityConfigurations.Name", hasItem(name));
|
||||
emr(HOME, "DescribeSecurityConfiguration", byName).then().statusCode(200)
|
||||
.body("Name", equalTo(name));
|
||||
} finally {
|
||||
emr(HOME, "DeleteSecurityConfiguration", byName);
|
||||
}
|
||||
}
|
||||
|
||||
// Catches: an instance's or the master's private DNS name in the wrong region's domain.
|
||||
@Test
|
||||
void listedInstancesUseTheClustersRegionalPrivateDnsDomain() {
|
||||
|
||||
@@ -291,7 +291,7 @@ class EmrIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.body("SecurityConfiguration", equalTo("{\"EncryptionConfiguration\":{}}"));
|
||||
|
||||
emrService.describeSecurityConfiguration("floci-emr-sec")
|
||||
emrService.describeSecurityConfiguration("floci-emr-sec", "us-east-1")
|
||||
.setCreationDateTime(Instant.ofEpochMilli(1_761_000_000_123L));
|
||||
try {
|
||||
JsonNode describedTime = objectMapper.readTree(emr("DescribeSecurityConfiguration",
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.SecurityConfiguration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.floci.aws.services.emr.EmrServiceFixture.ACCOUNT;
|
||||
import static io.floci.aws.services.emr.EmrServiceFixture.REGION;
|
||||
import static io.floci.aws.services.emr.EmrServiceFixture.cluster;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Security configurations stored before they were keyed by Region, under their bare name, move at startup to the
|
||||
* default Region, and every other Region where one of the account's clusters names one gets a copy of it, so the
|
||||
* cluster's configuration is still described there.
|
||||
*/
|
||||
class EmrSecurityConfigurationLegacyKeysTest {
|
||||
|
||||
private static final String CLUSTER_REGION = "eu-central-1";
|
||||
|
||||
@Test
|
||||
void aLegacyConfigurationMovesToTheDefaultRegionAndIsCopiedToTheRegionsOfTheClustersNamingIt() {
|
||||
EmrServiceFixture fixture = new EmrServiceFixture();
|
||||
AccountAwareStorageBackend<SecurityConfiguration> configurations = fixture.storage.create("emr",
|
||||
"emr-security-configs.json", new TypeReference<Map<String, SecurityConfiguration>>() {});
|
||||
configurations.put("used", configuration("used"));
|
||||
configurations.put("unused", configuration("unused"));
|
||||
// A name may hold the separator itself: it is still a key stored before.
|
||||
configurations.put("team::prod", configuration("team::prod"));
|
||||
// A key already of a Region, any Region a partition publishes, stays where it is.
|
||||
configurations.put("eusc-de-east-1::sovereign", configuration("sovereign"));
|
||||
String clusterId = fixture.service.runJobFlow(cluster("secured", true), CLUSTER_REGION).getId();
|
||||
AccountAwareStorageBackend<EmrCluster> clusters = fixture.storage.create("emr", "emr-clusters.json",
|
||||
new TypeReference<Map<String, EmrCluster>>() {});
|
||||
EmrCluster stored = clusters.get(clusterId).orElseThrow();
|
||||
stored.setSecurityConfiguration("used");
|
||||
clusters.put(clusterId, stored);
|
||||
|
||||
EmrService restarted = fixture.restartImmediate().service;
|
||||
|
||||
assertEquals(Set.of(REGION + "::used", REGION + "::unused", REGION + "::team::prod", CLUSTER_REGION + "::used",
|
||||
"eusc-de-east-1::sovereign"), configurations.keysForAccount(ACCOUNT));
|
||||
assertEquals(Set.of("sovereign"), names(restarted.listSecurityConfigurations("eusc-de-east-1")));
|
||||
assertEquals(Set.of("used", "unused", "team::prod"), names(restarted.listSecurityConfigurations(REGION)));
|
||||
assertEquals(Set.of("used"), names(restarted.listSecurityConfigurations(CLUSTER_REGION)));
|
||||
assertEquals(Set.of(), names(restarted.listSecurityConfigurations("eu-west-1")));
|
||||
assertEquals("{\"EncryptionConfiguration\":{}}",
|
||||
restarted.describeSecurityConfiguration("used", CLUSTER_REGION).getSecurityConfiguration());
|
||||
}
|
||||
|
||||
private static SecurityConfiguration configuration(String name) {
|
||||
SecurityConfiguration configuration = new SecurityConfiguration();
|
||||
configuration.setName(name);
|
||||
configuration.setSecurityConfiguration("{\"EncryptionConfiguration\":{}}");
|
||||
configuration.setCreationDateTime(Instant.parse("2026-11-01T00:00:00Z"));
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private static Set<String> names(List<SecurityConfiguration> configurations) {
|
||||
return Set.copyOf(configurations.stream().map(SecurityConfiguration::getName).toList());
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package io.floci.aws.services.glue.schemaregistry;
|
||||
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.services.glue.schemaregistry.model.Registry;
|
||||
import io.floci.aws.services.glue.schemaregistry.model.RegistryId;
|
||||
import io.floci.aws.services.glue.schemaregistry.model.Schema;
|
||||
import io.floci.aws.services.glue.schemaregistry.model.SchemaId;
|
||||
import io.floci.aws.services.glue.schemaregistry.model.SchemaVersion;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Registries and schemas stored before they were keyed by Region, under their bare name and {@code registry:schema},
|
||||
* move at startup onto the key of the Region their ARN names, or the default Region's when they have no ARN. Each is
|
||||
* then listed and reached there, its versions with it, and a schema of another Region than its registry keeps a copy
|
||||
* of that registry in its own Region. The stores are account stores, as the storage factory gives the service.
|
||||
*/
|
||||
class GlueSchemaRegistryLegacyKeysTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String DEFAULT = "us-east-1";
|
||||
private static final String FRANKFURT = "eu-central-1";
|
||||
private static final String DEFINITION =
|
||||
"{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"x\",\"fields\":[{\"name\":\"id\",\"type\":\"long\"}]}";
|
||||
|
||||
@Test
|
||||
void storedRegistriesAndSchemasMoveToTheRegionTheirArnNames() {
|
||||
AccountAwareStorageBackend<Registry> registries = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
AccountAwareStorageBackend<Schema> schemas = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
AccountAwareStorageBackend<SchemaVersion> versions = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
Registry frankfurt = new Registry("reg");
|
||||
frankfurt.setRegistryArn("arn:aws:glue:" + FRANKFURT + ":" + ACCOUNT + ":registry/reg");
|
||||
registries.put("reg", frankfurt);
|
||||
registries.put("bare", new Registry("bare"));
|
||||
Schema schema = new Schema();
|
||||
schema.setRegistryName("reg");
|
||||
schema.setRegistryArn(frankfurt.getRegistryArn());
|
||||
schema.setSchemaName("users");
|
||||
schema.setSchemaArn("arn:aws:glue:" + FRANKFURT + ":" + ACCOUNT + ":schema/reg/users");
|
||||
schema.setDataFormat("AVRO");
|
||||
schema.setCompatibility("BACKWARD");
|
||||
schema.setLatestSchemaVersion(1L);
|
||||
schema.setNextSchemaVersion(2L);
|
||||
schemas.put("reg:users", schema);
|
||||
SchemaVersion version = new SchemaVersion();
|
||||
version.setSchemaVersionId("version-1");
|
||||
version.setSchemaArn(schema.getSchemaArn());
|
||||
version.setVersionNumber(1L);
|
||||
version.setStatus("AVAILABLE");
|
||||
version.setSchemaDefinition(DEFINITION);
|
||||
version.setDataFormat("AVRO");
|
||||
version.setCreatedTime(Instant.parse("2026-11-01T00:00:00Z"));
|
||||
versions.put("version-1", version);
|
||||
|
||||
GlueSchemaRegistryService service = new GlueSchemaRegistryService(registries, schemas, versions,
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT), new RegionResolver(DEFAULT, ACCOUNT));
|
||||
service.afterCdiInit();
|
||||
|
||||
assertEquals(Set.of(FRANKFURT + "::reg", DEFAULT + "::bare"), registries.keysForAccount(ACCOUNT));
|
||||
assertEquals(Set.of(FRANKFURT + "::reg:users"), schemas.keysForAccount(ACCOUNT));
|
||||
assertEquals(List.of("reg"), service.listRegistries(FRANKFURT).stream().map(Registry::getRegistryName).toList());
|
||||
assertEquals(List.of("bare"), service.listRegistries(DEFAULT).stream().map(Registry::getRegistryName).toList());
|
||||
assertEquals(List.of("users"), service.listSchemas(new RegistryId("reg", null), FRANKFURT).stream()
|
||||
.map(Schema::getSchemaName).toList());
|
||||
assertEquals("version-1", service.getSchemaByDefinition(new SchemaId("reg", "users", null), DEFINITION,
|
||||
FRANKFURT).getSchemaVersionId());
|
||||
assertEquals("version-1", service.getSchemaVersion(null, "version-1", null, false, FRANKFURT)
|
||||
.getSchemaVersionId());
|
||||
}
|
||||
|
||||
/** The copy's ARN names its Region whether the registry was stored with an ARN or, the default Region's, without. */
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void aSchemaOfAnotherRegionThanItsRegistryKeepsACopyOfItsRegistryThere(boolean storedWithAnArn) {
|
||||
AccountAwareStorageBackend<Registry> registries = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
AccountAwareStorageBackend<Schema> schemas = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
Registry home = new Registry("orders");
|
||||
home.setRegistryArn(storedWithAnArn ? "arn:aws:glue:" + DEFAULT + ":" + ACCOUNT + ":registry/orders" : null);
|
||||
home.setDescription("orders");
|
||||
registries.put("orders", home);
|
||||
// Every Region saw every registry, so a schema of it could be created in another Region.
|
||||
Schema schema = new Schema();
|
||||
schema.setRegistryName("orders");
|
||||
schema.setRegistryArn(home.getRegistryArn());
|
||||
schema.setSchemaName("o1");
|
||||
schema.setSchemaArn("arn:aws:glue:" + FRANKFURT + ":" + ACCOUNT + ":schema/orders/o1");
|
||||
schema.setDataFormat("AVRO");
|
||||
schemas.put("orders:o1", schema);
|
||||
|
||||
GlueSchemaRegistryService service = new GlueSchemaRegistryService(registries, schemas, AccountAwareStorageBackend.inMemory(ACCOUNT),
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT), new RegionResolver(DEFAULT, ACCOUNT));
|
||||
service.afterCdiInit();
|
||||
|
||||
assertEquals(Set.of(DEFAULT + "::orders", FRANKFURT + "::orders"), registries.keysForAccount(ACCOUNT));
|
||||
Registry copy = service.getRegistry(new RegistryId("orders", null), FRANKFURT);
|
||||
assertEquals("arn:aws:glue:" + FRANKFURT + ":" + ACCOUNT + ":registry/orders", copy.getRegistryArn());
|
||||
assertEquals("orders", copy.getDescription());
|
||||
Schema moved = service.getSchema(new SchemaId("orders", "o1", null), FRANKFURT);
|
||||
assertEquals(copy.getRegistryArn(), moved.getRegistryArn());
|
||||
assertEquals(List.of(), service.listSchemas(new RegistryId("orders", null), DEFAULT));
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package io.floci.aws.services.glue.schemaregistry;
|
||||
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
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;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* Glue Schema Registry registries and their schemas are Regional: each is listed and reached only in the Region it
|
||||
* was created in, by its name, its ARN or a schema version's id, and its name can be used again in another Region.
|
||||
* Another Region's answers {@code EntityNotFoundException}, as one that doesn't exist does.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class GlueSchemaRegistryRegionScopingIntegrationTest {
|
||||
|
||||
private static final String HOME = "eu-west-1";
|
||||
private static final String OTHER = "eu-central-1";
|
||||
private static final String AVRO = "{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"User\\\",\\\"namespace\\\":\\\"x\\\","
|
||||
+ "\\\"fields\\\":[{\\\"name\\\":\\\"id\\\",\\\"type\\\":\\\"long\\\"}]}";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRegistryAndItsSchemaAreListedAndReachedOnlyInTheirRegion() {
|
||||
String registry = "reg-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String byName = "{\"RegistryId\":{\"RegistryName\":\"" + registry + "\"}}";
|
||||
String registryArn = call(HOME, "CreateRegistry", "{\"RegistryName\":\"" + registry + "\"}").statusCode(200)
|
||||
.extract().path("RegistryArn");
|
||||
try {
|
||||
ValidatableResponse schema = call(HOME, "CreateSchema", "{\"RegistryId\":{\"RegistryName\":\"" + registry
|
||||
+ "\"},\"SchemaName\":\"users\",\"DataFormat\":\"AVRO\",\"SchemaDefinition\":\"" + AVRO + "\"}")
|
||||
.statusCode(200);
|
||||
String schemaArn = schema.extract().path("SchemaArn");
|
||||
String versionId = schema.extract().path("SchemaVersionId");
|
||||
|
||||
call(OTHER, "ListRegistries", "{}").statusCode(200).body("Registries.RegistryName", not(hasItem(registry)));
|
||||
notFound(call(OTHER, "GetRegistry", byName));
|
||||
notFound(call(OTHER, "GetRegistry", "{\"RegistryId\":{\"RegistryArn\":\"" + registryArn + "\"}}"));
|
||||
notFound(call(OTHER, "ListSchemas", byName));
|
||||
notFound(call(OTHER, "GetSchema", "{\"SchemaId\":{\"SchemaArn\":\"" + schemaArn + "\"}}"));
|
||||
notFound(call(OTHER, "GetSchemaVersion", "{\"SchemaVersionId\":\"" + versionId + "\"}"));
|
||||
notFound(call(OTHER, "PutSchemaVersionMetadata", "{\"SchemaVersionId\":\"" + versionId + "\","
|
||||
+ "\"MetadataKeyValue\":{\"MetadataKey\":\"owner\",\"MetadataValue\":\"alice\"}}"));
|
||||
notFound(call(OTHER, "GetTags", "{\"ResourceArn\":\"" + registryArn + "\"}"));
|
||||
notFound(call(OTHER, "DeleteRegistry", byName));
|
||||
|
||||
call(OTHER, "CreateRegistry", "{\"RegistryName\":\"" + registry + "\"}").statusCode(200)
|
||||
.body("RegistryArn", startsWith("arn:aws:glue:" + OTHER + ":"));
|
||||
call(OTHER, "DeleteRegistry", byName).statusCode(200);
|
||||
|
||||
call(HOME, "ListRegistries", "{}").statusCode(200).body("Registries.RegistryName", hasItem(registry));
|
||||
call(HOME, "GetSchema", "{\"SchemaId\":{\"SchemaArn\":\"" + schemaArn + "\"}}").statusCode(200)
|
||||
.body("SchemaName", equalTo("users"));
|
||||
call(HOME, "GetSchemaVersion", "{\"SchemaVersionId\":\"" + versionId + "\"}").statusCode(200)
|
||||
.body("SchemaArn", equalTo(schemaArn));
|
||||
} finally {
|
||||
call(HOME, "DeleteRegistry", byName);
|
||||
}
|
||||
}
|
||||
|
||||
private static ValidatableResponse call(String region, String action, String body) {
|
||||
return given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "AWSGlue." + action)
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKID/20260101/" + region + "/glue/aws4_request")
|
||||
.body(body)
|
||||
.when().post("/").then();
|
||||
}
|
||||
|
||||
private static void notFound(ValidatableResponse response) {
|
||||
response.statusCode(400).body("__type", equalTo("EntityNotFoundException"));
|
||||
}
|
||||
}
|
||||
+38
-38
@@ -141,7 +141,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
|
||||
assertEquals("default-registry", registry.getRegistryName());
|
||||
assertEquals("AVAILABLE", registry.getStatus());
|
||||
assertEquals(1, service.listRegistries().size());
|
||||
assertEquals(1, service.listRegistries(REGION).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,7 +163,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
service.createRegistry("a", null, null, REGION);
|
||||
service.createRegistry("b", null, null, REGION);
|
||||
|
||||
List<Registry> registries = service.listRegistries();
|
||||
List<Registry> registries = service.listRegistries(REGION);
|
||||
|
||||
assertEquals(2, registries.size());
|
||||
}
|
||||
@@ -174,8 +174,8 @@ class GlueSchemaRegistryServiceTest {
|
||||
service.createRegistry("b", null, null, REGION);
|
||||
service.createRegistry("c", null, null, REGION);
|
||||
|
||||
GlueSchemaRegistryService.Page<Registry> first = service.listRegistries(2, null);
|
||||
GlueSchemaRegistryService.Page<Registry> second = service.listRegistries(2, first.nextToken());
|
||||
GlueSchemaRegistryService.Page<Registry> first = service.listRegistries(REGION, 2, null);
|
||||
GlueSchemaRegistryService.Page<Registry> second = service.listRegistries(REGION, 2, first.nextToken());
|
||||
|
||||
assertEquals(2, first.items().size());
|
||||
assertEquals("2", first.nextToken());
|
||||
@@ -186,7 +186,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
|
||||
@Test
|
||||
void listRegistriesEmptyByDefault() {
|
||||
assertTrue(service.listRegistries().isEmpty());
|
||||
assertTrue(service.listRegistries(REGION).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -218,7 +218,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
service.createRegistry("r1", null, null, REGION);
|
||||
SchemaVersion first = service.createSchema(new RegistryId("r1", null),
|
||||
"users", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION).firstVersion();
|
||||
service.putSchemaVersionMetadata(first.getSchemaVersionId(), "team", "platform");
|
||||
service.putSchemaVersionMetadata(first.getSchemaVersionId(), "team", "platform", REGION);
|
||||
|
||||
service.deleteRegistry(new RegistryId("r1", null), REGION);
|
||||
service.createRegistry("r1", null, null, REGION);
|
||||
@@ -228,7 +228,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
service.getSchemaVersion(null, first.getSchemaVersionId(), null, false, REGION));
|
||||
assertEquals("EntityNotFoundException", versionEx.getErrorCode());
|
||||
AwsException metadataEx = assertThrows(AwsException.class, () ->
|
||||
service.querySchemaVersionMetadata(first.getSchemaVersionId(), null));
|
||||
service.querySchemaVersionMetadata(first.getSchemaVersionId(), null, REGION));
|
||||
assertEquals("EntityNotFoundException", metadataEx.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
public Optional<Schema> get(String key) {
|
||||
Optional<Schema> schema = super.get(key);
|
||||
if (Thread.currentThread() == lookupThread.get()
|
||||
&& key.equals("reg:users") && paused.compareAndSet(false, true)) {
|
||||
&& key.equals(REGION + "::reg:users") && paused.compareAndSet(false, true)) {
|
||||
firstSchemaRead.countDown();
|
||||
awaitRelease(finishLookup);
|
||||
}
|
||||
@@ -1097,32 +1097,32 @@ class GlueSchemaRegistryServiceTest {
|
||||
void putSchemaVersionMetadataStoresKeyValue() {
|
||||
String svId = firstVersionId();
|
||||
|
||||
GlueSchemaRegistryService.MetadataPutResult r = service.putSchemaVersionMetadata(svId, "team", "platform");
|
||||
GlueSchemaRegistryService.MetadataPutResult r = service.putSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
|
||||
assertEquals("team", r.metadataKey());
|
||||
assertEquals("platform", r.metadataValue());
|
||||
Map<String, MetadataInfo> map = service.querySchemaVersionMetadata(svId, null);
|
||||
Map<String, MetadataInfo> map = service.querySchemaVersionMetadata(svId, null, REGION);
|
||||
assertEquals("platform", map.get("team").getMetadataValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putSchemaVersionMetadataDuplicateKeyValueRejected() {
|
||||
String svId = firstVersionId();
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform");
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform"));
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform", REGION));
|
||||
assertEquals("AlreadyExistsException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putSchemaVersionMetadataSameKeyNewValueDemotesOld() {
|
||||
String svId = firstVersionId();
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform");
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
|
||||
service.putSchemaVersionMetadata(svId, "team", "data");
|
||||
service.putSchemaVersionMetadata(svId, "team", "data", REGION);
|
||||
|
||||
Map<String, MetadataInfo> map = service.querySchemaVersionMetadata(svId, null);
|
||||
Map<String, MetadataInfo> map = service.querySchemaVersionMetadata(svId, null, REGION);
|
||||
assertEquals("data", map.get("team").getMetadataValue());
|
||||
assertEquals(1, map.get("team").getOtherMetadataValueList().size());
|
||||
assertEquals("platform", map.get("team").getOtherMetadataValueList().get(0).getMetadataValue());
|
||||
@@ -1131,19 +1131,19 @@ class GlueSchemaRegistryServiceTest {
|
||||
@Test
|
||||
void putSchemaVersionMetadataForUnknownVersionThrows() {
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.putSchemaVersionMetadata("does-not-exist", "team", "platform"));
|
||||
service.putSchemaVersionMetadata("does-not-exist", "team", "platform", REGION));
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeSchemaVersionMetadataCurrentPromotesNext() {
|
||||
String svId = firstVersionId();
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform");
|
||||
service.putSchemaVersionMetadata(svId, "team", "data");
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
service.putSchemaVersionMetadata(svId, "team", "data", REGION);
|
||||
|
||||
service.removeSchemaVersionMetadata(svId, "team", "data");
|
||||
service.removeSchemaVersionMetadata(svId, "team", "data", REGION);
|
||||
|
||||
Map<String, MetadataInfo> map = service.querySchemaVersionMetadata(svId, null);
|
||||
Map<String, MetadataInfo> map = service.querySchemaVersionMetadata(svId, null, REGION);
|
||||
assertEquals("platform", map.get("team").getMetadataValue());
|
||||
assertNull(map.get("team").getOtherMetadataValueList());
|
||||
}
|
||||
@@ -1151,29 +1151,29 @@ class GlueSchemaRegistryServiceTest {
|
||||
@Test
|
||||
void removeSchemaVersionMetadataLastValueDeletesKey() {
|
||||
String svId = firstVersionId();
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform");
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
|
||||
service.removeSchemaVersionMetadata(svId, "team", "platform");
|
||||
service.removeSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
|
||||
assertTrue(service.querySchemaVersionMetadata(svId, null).isEmpty());
|
||||
assertTrue(service.querySchemaVersionMetadata(svId, null, REGION).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeSchemaVersionMetadataNotFoundThrows() {
|
||||
String svId = firstVersionId();
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.removeSchemaVersionMetadata(svId, "missing", "x"));
|
||||
service.removeSchemaVersionMetadata(svId, "missing", "x", REGION));
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void querySchemaVersionMetadataWithFilterReturnsSubset() {
|
||||
String svId = firstVersionId();
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform");
|
||||
service.putSchemaVersionMetadata(svId, "owner", "alice");
|
||||
service.putSchemaVersionMetadata(svId, "team", "platform", REGION);
|
||||
service.putSchemaVersionMetadata(svId, "owner", "alice", REGION);
|
||||
|
||||
Map<String, MetadataInfo> filtered = service.querySchemaVersionMetadata(svId,
|
||||
List.of(new GlueSchemaRegistryService.MetadataKeyValueFilter("team", null)));
|
||||
List.of(new GlueSchemaRegistryService.MetadataKeyValueFilter("team", null)), REGION);
|
||||
|
||||
assertEquals(1, filtered.size());
|
||||
assertTrue(filtered.containsKey("team"));
|
||||
@@ -1186,12 +1186,12 @@ class GlueSchemaRegistryServiceTest {
|
||||
"a", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION).firstVersion();
|
||||
service.registerSchemaVersion(new SchemaId("reg", "a", null), AVRO_V2_BACKWARD_OK, REGION);
|
||||
service.updateSchema(new SchemaId("reg", "a", null), null, null, 2L, REGION);
|
||||
service.putSchemaVersionMetadata(first.getSchemaVersionId(), "team", "platform");
|
||||
service.putSchemaVersionMetadata(first.getSchemaVersionId(), "team", "platform", REGION);
|
||||
|
||||
service.deleteSchemaVersions(new SchemaId("reg", "a", null), "1", REGION);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.querySchemaVersionMetadata(first.getSchemaVersionId(), null));
|
||||
service.querySchemaVersionMetadata(first.getSchemaVersionId(), null, REGION));
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -1199,9 +1199,9 @@ class GlueSchemaRegistryServiceTest {
|
||||
void tagAndGetTagsForRegistry() {
|
||||
Registry r = service.createRegistry("reg", null, null, REGION);
|
||||
|
||||
service.tagResource(r.getRegistryArn(), Map.of("env", "prod", "team", "platform"));
|
||||
service.tagResource(r.getRegistryArn(), Map.of("env", "prod", "team", "platform"), REGION);
|
||||
|
||||
Map<String, String> tags = service.getTags(r.getRegistryArn());
|
||||
Map<String, String> tags = service.getTags(r.getRegistryArn(), REGION);
|
||||
assertEquals(2, tags.size());
|
||||
assertEquals("prod", tags.get("env"));
|
||||
}
|
||||
@@ -1212,20 +1212,20 @@ class GlueSchemaRegistryServiceTest {
|
||||
Schema schema = service.createSchema(new RegistryId("reg", null),
|
||||
"a", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION).schema();
|
||||
|
||||
service.tagResource(schema.getSchemaArn(), Map.of("owner", "alice"));
|
||||
service.tagResource(schema.getSchemaArn(), Map.of("owner", "alice"), REGION);
|
||||
|
||||
Map<String, String> tags = service.getTags(schema.getSchemaArn());
|
||||
Map<String, String> tags = service.getTags(schema.getSchemaArn(), REGION);
|
||||
assertEquals("alice", tags.get("owner"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void untagResourceRemovesKeys() {
|
||||
Registry r = service.createRegistry("reg", null, null, REGION);
|
||||
service.tagResource(r.getRegistryArn(), Map.of("env", "prod", "team", "platform"));
|
||||
service.tagResource(r.getRegistryArn(), Map.of("env", "prod", "team", "platform"), REGION);
|
||||
|
||||
service.untagResource(r.getRegistryArn(), List.of("env"));
|
||||
service.untagResource(r.getRegistryArn(), List.of("env"), REGION);
|
||||
|
||||
Map<String, String> tags = service.getTags(r.getRegistryArn());
|
||||
Map<String, String> tags = service.getTags(r.getRegistryArn(), REGION);
|
||||
assertEquals(1, tags.size());
|
||||
assertTrue(tags.containsKey("team"));
|
||||
}
|
||||
@@ -1233,7 +1233,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
@Test
|
||||
void tagResourceWithMalformedArnThrows() {
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.tagResource("not-an-arn", Map.of("a", "b")));
|
||||
service.tagResource("not-an-arn", Map.of("a", "b"), REGION));
|
||||
assertEquals("InvalidInputException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -1242,7 +1242,7 @@ class GlueSchemaRegistryServiceTest {
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.tagResource(
|
||||
"arn:aws:glue:us-east-1:" + ACCOUNT_ID + ":registry/missing",
|
||||
Map.of("a", "b")));
|
||||
Map.of("a", "b"), REGION));
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user