fix(redshift): scope parameter groups, subnet groups, schedules, copy grants and integrations to their Region (#8565)

Redshift cluster parameter groups, subnet groups, snapshot schedules and snapshot copy grants are now stored under <region>::<name>, and zero-ETL integrations are listed, described and deleted only in the Region their ARN names, with names unique per Region.

The snapshot scheduler reads a cluster's schedule in the cluster's Region. EnableSnapshotCopy and snapshot copies look up the grant in the destination Region. The in-use checks for deleting a grant or schedule are scoped to the Region.

Records stored before this change move at startup. A subnet group goes to its subnets' Region and a copy grant to its KMS key's Region; anything else goes to the default Region. Every other Region where a cluster uses a record gets its own copy.

StorageJson in core.storage builds the mapper used by the persistent, hybrid and WAL storages, and copies a record through that form; AppConfigService.copy uses it too. AvailabilityZoneIds.regionOf gives a zone's Region for EFS, EKS and Redshift.

Part of #8218
This commit is contained in:
mrfelek authored and GitHub committed 2026-11-16 10:55:19 -04:00
1 parent ad6ca74685
commit 4a7953bb0b
17 files changed
+948 -194

No files matched your search

@@ -46,6 +46,18 @@ public final class AvailabilityZoneIds {
return forIndex(region, 1);
}
/**
* The Region of zone {@code zoneName}, the name without its zone letter: {@code us-east-1} for
* {@code us-east-1a}. Null for a name that doesn't end in a letter.
*/
public static String regionOf(String zoneName) {
if (zoneName == null || zoneName.length() < 2
|| !Character.isLetter(zoneName.charAt(zoneName.length() - 1))) {
return null;
}
return zoneName.substring(0, zoneName.length() - 1);
}
/** The id of the {@code index}-th zone of {@code region}, counting from 1. */
public static String forIndex(String region, int index) {
return prefix(region) + SEPARATOR + index;
@@ -3,7 +3,6 @@ package io.floci.aws.core.storage;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.jboss.logging.Logger;
import java.io.IOException;
@@ -39,10 +38,7 @@ public class HybridStorage<K, V> implements StorageBackend<K, V> {
public HybridStorage(Path filePath, TypeReference<Map<K, V>> typeReference, long flushIntervalMs) {
this.filePath = filePath;
this.typeReference = typeReference;
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new JavaTimeModule());
this.objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
this.objectMapper = StorageJson.mapper().enable(SerializationFeature.INDENT_OUTPUT);
this.scheduler = StorageFiles.scheduleEvery("hybrid-storage-flush", flushIntervalMs, this::flushIfDirty);
}
@@ -3,7 +3,6 @@ package io.floci.aws.core.storage;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.jboss.logging.Logger;
import java.io.IOException;
@@ -37,10 +36,7 @@ public class PersistentStorage<K, V> implements StorageBackend<K, V> {
public PersistentStorage(Path filePath, TypeReference<Map<K, V>> typeReference) {
this.filePath = filePath;
this.typeReference = typeReference;
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new JavaTimeModule());
this.objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
this.objectMapper = StorageJson.mapper().enable(SerializationFeature.INDENT_OUTPUT);
}
@Override
@@ -0,0 +1,41 @@
package io.floci.aws.core.storage;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
/**
* The JSON form the file storages keep records in: Java time types, written as ISO-8601 text rather than numbers.
* Their mappers are built here, and so are copies of a record through that form.
*/
public final class StorageJson {
private static final ObjectMapper COPIES = mapper();
private StorageJson() {
}
/** A mapper that reads and writes records as the file storages do. */
public static ObjectMapper mapper() {
return configure(new ObjectMapper());
}
/** As above, over {@code factory}, as the write-ahead log's CBOR mapper is. */
static ObjectMapper mapper(JsonFactory factory) {
return configure(new ObjectMapper(factory));
}
/**
* A copy of {@code record} through its stored form: a record of its own, as storage would read it back, so
* changing one doesn't change the other.
*/
@SuppressWarnings("unchecked")
public static <V> V copy(V record) {
return (V) COPIES.convertValue(record, record.getClass());
}
private static ObjectMapper configure(ObjectMapper mapper) {
return mapper.registerModule(new JavaTimeModule()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
}
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.jboss.logging.Logger;
import java.io.BufferedInputStream;
@@ -90,14 +89,9 @@ public class WalStorage<K, V> implements StorageBackend<K, V> {
this.walPath = walPath;
this.typeReference = typeReference;
this.snapshotMapper = new ObjectMapper();
this.snapshotMapper.registerModule(new JavaTimeModule());
this.snapshotMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
this.snapshotMapper.enable(SerializationFeature.INDENT_OUTPUT);
this.snapshotMapper = StorageJson.mapper().enable(SerializationFeature.INDENT_OUTPUT);
this.walMapper = new ObjectMapper(new CBORFactory());
this.walMapper.registerModule(new JavaTimeModule());
this.walMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
this.walMapper = StorageJson.mapper(new CBORFactory());
this.scheduler = StorageFiles.scheduleEvery("wal-storage-compaction", compactionIntervalMs, this::compact);
}
@@ -1,7 +1,6 @@
package io.floci.aws.services.appconfig;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
@@ -10,6 +9,7 @@ import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.RegionScopedStorage;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.core.storage.StorageJson;
import io.floci.aws.core.storage.StorageOperations;
import io.floci.aws.services.appconfig.model.Application;
import io.floci.aws.services.appconfig.model.ConfigurationProfile;
@@ -56,7 +56,6 @@ public class AppConfigService {
private static final int MAX_DEPLOYMENT_PAGE_TOKENS = 1000;
private static final int MAX_MONITORS = 5;
private static final int MAX_ARN_LENGTH = 2048;
private static final ObjectMapper COPIER = new ObjectMapper();
private static final Pattern ROLE_ARN = Pattern.compile("arn:" + AwsArnUtils.PARTITION_REGEX + ":iam::\\d{12}:role/.*");
@Inject
@@ -892,9 +891,8 @@ public class AppConfigService {
* such as one a GetApplication is still serializing, under that caller. The models are plain
* Jackson beans, as storage persists them, so a round trip copies every field.
*/
@SuppressWarnings("unchecked")
private static <T> T copy(T entity) {
return (T) COPIER.convertValue(entity, entity.getClass());
return StorageJson.copy(entity);
}
private static String shortId(int length) {
@@ -30,12 +30,8 @@ public class MountTarget {
* mount target persisted before zone ids took AWS's shape carries the old id.
*/
public String getAvailabilityZoneId() {
if (availabilityZoneName == null || availabilityZoneName.length() < 2
|| !Character.isLetter(availabilityZoneName.charAt(availabilityZoneName.length() - 1))) {
return availabilityZoneId;
}
String region = availabilityZoneName.substring(0, availabilityZoneName.length() - 1);
return AvailabilityZoneIds.forZoneName(region, availabilityZoneName);
String region = AvailabilityZoneIds.regionOf(availabilityZoneName);
return region == null ? availabilityZoneId : AvailabilityZoneIds.forZoneName(region, availabilityZoneName);
}
public void setAvailabilityZoneId(String availabilityZoneId) {
@@ -2,6 +2,7 @@ package io.floci.aws.services.eks;
import com.fasterxml.jackson.core.type.TypeReference;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.AvailabilityZoneIds;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
@@ -1039,11 +1040,8 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
private void validateInstanceRegion(Cluster cluster, Instance instance) {
String clusterReg = resolveClusterRegion(cluster);
String instReg = instance.getRegion();
if (instReg == null && instance.getPlacement() != null && instance.getPlacement().getAvailabilityZone() != null) {
String az = instance.getPlacement().getAvailabilityZone();
if (az.length() > 1 && Character.isLetter(az.charAt(az.length() - 1))) {
instReg = az.substring(0, az.length() - 1);
}
if (instReg == null && instance.getPlacement() != null) {
instReg = AvailabilityZoneIds.regionOf(instance.getPlacement().getAvailabilityZone());
}
if (instReg != null && !instReg.equals(clusterReg)) {
throw new AwsException("InvalidParameterException", "Cannot join instance " + instance.getInstanceId()
@@ -3,6 +3,7 @@ package io.floci.aws.services.redshift;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.AvailabilityZoneIds;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.AwsRegions;
@@ -14,6 +15,7 @@ import io.floci.aws.core.common.docker.ContainerRejectedException;
import io.floci.aws.core.common.docker.DockerHostResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.core.storage.StorageJson;
import io.floci.aws.services.dynamodb.backend.DynamoDbStreamReader;
import io.floci.aws.services.dynamodb.model.TableDefinition;
import io.floci.aws.services.ec2.Ec2Service;
@@ -44,6 +46,7 @@ import io.floci.aws.services.secretsmanager.RandomPasswordGenerator;
import io.floci.aws.services.secretsmanager.SecretsManagerService;
import io.floci.aws.services.secretsmanager.model.Secret;
import io.quarkus.runtime.StartupEvent;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
@@ -77,6 +80,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Pattern;
@@ -88,6 +92,8 @@ public class RedshiftService implements ManagedSecretRotator {
// The group every cluster starts on until one is named.
static final String DEFAULT_PARAMETER_GROUP_NAME = "default.redshift-1.0";
private static final int MAX_RESET_PARAMETERS = 20;
// The alias of the AWS-managed key a snapshot copy grant gets when it names none.
private static final String DEFAULT_SNAPSHOT_COPY_GRANT_KEY = "alias/aws/redshift";
private final AccountAwareStorageBackend<Cluster> clusters;
private final AccountAwareStorageBackend<Snapshot> snapshots;
@@ -352,6 +358,27 @@ public class RedshiftService implements ManagedSecretRotator {
credentialBroker, null, new ObjectMapper(), null);
}
/**
* Moves the Regional records stored before they were Regional onto their Regional keys when the bean is made, as
* {@code AmazonMqService} moves its brokers: before {@link #onStart} and before any sweep runs, such as the
* snapshot-copy sweep that starts at startup on its own thread and reads a copy grant by its Regional key.
*/
@PostConstruct
void migrateRegionalRecords() {
// The clusters are read once, and only when a store has records to move.
migrateLegacyRegionalRecords(new Supplier<>() {
private List<AccountAwareStorageBackend.AccountEntry<Cluster>> read;
@Override
public List<AccountAwareStorageBackend.AccountEntry<Cluster>> get() {
if (read == null) {
read = clusters.scanAllAccountEntries(k -> true);
}
return read;
}
});
}
// Recreate Docker containers for persisted clusters on app restart (across every account, not just default)
void onStart(@Observes StartupEvent event) {
List<AccountAwareStorageBackend.AccountEntry<Cluster>> persistedClusters =
@@ -729,6 +756,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
boolean nameTaken = integrations.scan(k -> true).stream()
.filter(existing -> region.equals(integrationRegion(existing)))
.anyMatch(existing -> integrationName.equals(existing.getIntegrationName()));
if (nameTaken) {
throw new AwsException("IntegrationAlreadyExistsFault",
@@ -840,6 +868,7 @@ public class RedshiftService implements ManagedSecretRotator {
public IntegrationPage describeIntegrations(String integrationArn, Integer maxRecords, String marker,
List<IntegrationFilter> filters) {
List<Integration> all = integrations.scan(k -> true).stream()
.filter(this::isInRequestRegion)
.sorted(Comparator.comparing(Integration::getIntegrationArn))
.toList();
@@ -1078,6 +1107,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
if (autoCopyConsumer != null) {
integrations.keys().stream().map(integrations::get).flatMap(Optional::stream)
.filter(this::isInRequestRegion)
.filter(integration -> integrationArn.equals(integration.getIntegrationArn())
&& S3_EVENT_SOURCE_TYPE.equals(integration.getSourceType()))
.findFirst().ifPresent(autoCopyConsumer::disable);
@@ -1093,7 +1123,8 @@ public class RedshiftService implements ManagedSecretRotator {
}
for (String key : integrations.keys()) {
Optional<Integration> stored = integrations.get(key);
if (stored.isPresent() && integrationArn.equals(stored.get().getIntegrationArn())) {
if (stored.isPresent() && integrationArn.equals(stored.get().getIntegrationArn())
&& isInRequestRegion(stored.get())) {
integrations.delete(key);
LOG.infov("Deleted Redshift zero-ETL integration: {0}", integrationArn);
if (stored.get().getSourceType() == null) {
@@ -2029,7 +2060,7 @@ public class RedshiftService implements ManagedSecretRotator {
validateSnapshotIdentifier(snapshotIdentifier);
String clusterIdentifier = cluster.getClusterIdentifier();
boolean shadowedByCopy = scheduledTime == null
&& snapshotCopies.get(copyKey(regionResolver.getRegion(), snapshotIdentifier)).isPresent();
&& snapshotCopies.get(regionalKey(snapshotIdentifier)).isPresent();
if (shadowedByCopy || (scheduledTime == null ? snapshots.get(snapshotIdentifier)
: snapshots.getForAccount(accountId, snapshotIdentifier)).isPresent()) {
throw new AwsException("ClusterSnapshotAlreadyExists", "Snapshot " + snapshotIdentifier + " already exists", 400);
@@ -2138,17 +2169,138 @@ public class RedshiftService implements ManagedSecretRotator {
return visible;
}
private static String copyKey(String region, String snapshotIdentifier) {
return region + "::" + snapshotIdentifier;
/**
* The storage key of the Regional record {@code name} in {@code region}: a snapshot copy, cluster parameter
* group, subnet group, snapshot copy grant or snapshot schedule. Each is Regional, so the same name can be
* used in each Region of an account.
*/
static String regionalKey(String region, String name) {
return region + KEY_SEPARATOR + name;
}
/** Separates the Region from the name in a {@link #regionalKey}. */
private static final String KEY_SEPARATOR = "::";
/**
* Moves the cluster parameter groups, subnet groups, snapshot schedules and snapshot copy grants stored before
* they became Regional from their bare name onto {@link #regionalKey} keys. They recorded no Region, and every
* Region saw them. Each moves to the Region it shows it was made in, when it shows one: a subnet group to its
* subnets' Region, a copy grant to its KMS key's. Any other moves to the default Region. Every other Region where
* one of its account's clusters uses it gets a copy of its own, so those clusters keep finding it.
*/
private void migrateLegacyRegionalRecords(
Supplier<List<AccountAwareStorageBackend.AccountEntry<Cluster>>> persistedClusters) {
migrateLegacyRegionalRecords(parameterGroups, ClusterParameterGroup::getParameterGroupName, group -> null,
persistedClusters, Cluster::getClusterParameterGroupName, this::clusterRegion, (copy, region) -> { });
migrateLegacyRegionalRecords(subnetGroups, ClusterSubnetGroup::getClusterSubnetGroupName,
RedshiftService::regionOfSubnets, persistedClusters, Cluster::getClusterSubnetGroupName,
this::clusterRegion, (copy, region) -> { });
migrateLegacyRegionalRecords(snapshotSchedules, SnapshotSchedule::getScheduleIdentifier, schedule -> null,
persistedClusters, Cluster::getSnapshotScheduleIdentifier, this::clusterRegion, (copy, region) -> { });
migrateLegacyRegionalRecords(snapshotCopyGrants, SnapshotCopyGrant::getSnapshotCopyGrantName,
RedshiftService::regionOfKey, persistedClusters, Cluster::getSnapshotCopyGrantName,
Cluster::getSnapshotCopyDestinationRegion, this::useTheDefaultKeyOfItsRegion);
}
/** The Region of the zones EC2 placed a subnet group's subnets in, when they are all in one. */
private static String regionOfSubnets(ClusterSubnetGroup group) {
Map<String, String> zones = group.getSubnetZones();
if (zones == null || zones.isEmpty()) {
return null;
}
Set<String> regions = new LinkedHashSet<>();
for (String zone : zones.values()) {
String region = AvailabilityZoneIds.regionOf(zone);
regions.add(region != null && Ec2Service.isModelledAvailabilityZone(region, zone) ? region : null);
}
return regions.size() == 1 ? regions.iterator().next() : null;
}
/** The Region of a copy grant's KMS key, when its key is a KMS ARN: a key is of one Region, the grant's. */
private static String regionOfKey(SnapshotCopyGrant grant) {
String key = grant.getKmsKeyId();
if (!AwsArnUtils.isArnFor(key, "kms")) {
return null;
}
String region = AwsArnUtils.parse(key).region();
return region.isEmpty() ? null : region;
}
/**
* A grant copied to {@code region} that holds another Region's AWS-managed Redshift key, the one a grant created
* without {@code KmsKeyId} gets, holds {@code region}'s instead, as a grant created there would. A stored grant
* records no difference between that key given and defaulted, so both are changed; any other key is kept.
*/
private void useTheDefaultKeyOfItsRegion(SnapshotCopyGrant grant, String region) {
String key = grant.getKmsKeyId();
if (key == null || !AwsArnUtils.isArn(key)) {
return;
}
AwsArnUtils.Arn arn = AwsArnUtils.parse(key);
if ("kms".equals(arn.service()) && DEFAULT_SNAPSHOT_COPY_GRANT_KEY.equals(arn.resource())
&& !region.equals(arn.region())) {
grant.setKmsKeyId(regionResolver.buildArn("kms", region, arn.accountId(), DEFAULT_SNAPSHOT_COPY_GRANT_KEY));
}
}
/**
* Moves {@code store}'s records without a Region in their key to the Region {@code regionMadeIn} gives, or to the
* default Region. The clusters that use one name it through {@code nameUsed}, in the Region {@code regionOfUse}
* gives, and each of those Regions gets a copy, which {@code forRegion} fits to it.
*/
private <V> void migrateLegacyRegionalRecords(AccountAwareStorageBackend<V> store, Function<V, String> name,
Function<V, String> regionMadeIn,
Supplier<List<AccountAwareStorageBackend.AccountEntry<Cluster>>> persistedClusters,
Function<Cluster, String> nameUsed,
Function<Cluster, String> regionOfUse,
BiConsumer<V, String> forRegion) {
Predicate<String> legacy = key -> !key.contains(KEY_SEPARATOR);
List<AccountAwareStorageBackend.AccountEntry<V>> entries = store.scanAllAccountEntries(legacy);
if (entries.isEmpty()) {
return;
}
String defaultRegion = regionResolver.getDefaultRegion();
Function<V, String> home = value -> Optional.ofNullable(regionMadeIn.apply(value)).orElse(defaultRegion);
for (AccountAwareStorageBackend.AccountEntry<V> entry : entries) {
String recordName = name.apply(entry.value());
String recordHome = home.apply(entry.value());
for (AccountAwareStorageBackend.AccountEntry<Cluster> cluster : persistedClusters.get()) {
String region = regionOfUse.apply(cluster.value());
if (recordName == null || region == null || region.equals(recordHome)
|| !cluster.accountId().equals(entry.accountId())
|| !recordName.equals(nameUsed.apply(cluster.value()))) {
continue;
}
if (store.getForAccount(entry.accountId(), regionalKey(region, recordName)).isEmpty()) {
V copy = StorageJson.copy(entry.value());
forRegion.accept(copy, region);
store.putForAccount(entry.accountId(), regionalKey(region, recordName), copy);
}
}
}
store.migrateLegacyEntriesInAllAccounts(legacy,
value -> name.apply(value) == null ? null : regionalKey(home.apply(value), name.apply(value)));
store.flush();
}
/** {@link #regionalKey(String, String)} in the request's Region. */
private String regionalKey(String name) {
return regionalKey(regionResolver.getRegion(), name);
}
/** Whether a key is of the request's Region, its prefix built once for a whole scan. */
private Predicate<String> inRequestRegion() {
String prefix = regionResolver.getRegion() + KEY_SEPARATOR;
return key -> key.startsWith(prefix);
}
private List<Snapshot> copiesInRegion(String region) {
return snapshotCopies.scan(key -> key.startsWith(region + "::"));
return snapshotCopies.scan(key -> key.startsWith(region + KEY_SEPARATOR));
}
/** The copy in this request's Region if there is one, otherwise the snapshot itself. */
private Optional<Snapshot> findSnapshot(String snapshotIdentifier) {
return snapshotCopies.get(copyKey(regionResolver.getRegion(), snapshotIdentifier))
return snapshotCopies.get(regionalKey(snapshotIdentifier))
.or(() -> snapshots.get(snapshotIdentifier));
}
@@ -2208,6 +2360,15 @@ public class RedshiftService implements ManagedSecretRotator {
return clusterRegion(cluster).equals(regionResolver.getRegion());
}
private boolean isInRequestRegion(Integration integration) {
return integrationRegion(integration).equals(regionResolver.getRegion());
}
/** The Region an integration was created in, which its ARN names. */
private String integrationRegion(Integration integration) {
return AwsArnUtils.regionOrDefault(integration.getIntegrationArn(), regionResolver.getDefaultRegion());
}
/**
* The snapshot an ARN names in its account, as a restore finds it, a cluster the ARN leaves open ({@code *})
* matching any: in the caller's account the copy kept in the ARN's Region before the snapshot itself, and in
@@ -2231,7 +2392,7 @@ public class RedshiftService implements ManagedSecretRotator {
.filter(snapshot -> snapshot.getSnapshotArn() == null
|| AwsArnUtils.parse(snapshot.getSnapshotArn()).region().equals(arn.region()));
}
return snapshotCopies.getForAccount(arn.accountId(), copyKey(arn.region(), identifier)).filter(ofCluster)
return snapshotCopies.getForAccount(arn.accountId(), regionalKey(arn.region(), identifier)).filter(ofCluster)
.or(() -> snapshots.getForAccount(arn.accountId(), identifier).filter(ofCluster));
}
@@ -2289,7 +2450,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
private Snapshot shareableSnapshot(String snapshotIdentifier, String snapshotClusterIdentifier) {
String copyKey = copyKey(regionResolver.getRegion(), snapshotIdentifier);
String copyKey = regionalKey(snapshotIdentifier);
if (snapshotCopies.get(copyKey).isPresent()) {
throw new AwsException("InvalidClusterSnapshotState",
"Snapshot " + snapshotIdentifier + " is not an available manual snapshot, which is the only kind"
@@ -2365,7 +2526,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
snapshot.setManualSnapshotRetentionPeriod(manualSnapshotRetentionPeriod);
String copyKey = copyKey(region, snapshotIdentifier);
String copyKey = regionalKey(region, snapshotIdentifier);
if (snapshotCopies.get(copyKey).isPresent()) {
snapshotCopies.putAllAtomically(Map.of(copyKey, snapshot));
snapshotCopies.flush();
@@ -2388,7 +2549,7 @@ public class RedshiftService implements ManagedSecretRotator {
String region = regionResolver.getRegion();
return withResourceLock("snapshot", targetSnapshotIdentifier, () -> {
boolean shadowedByCopy = snapshotCopies.get(copyKey(region, targetSnapshotIdentifier)).isPresent();
boolean shadowedByCopy = snapshotCopies.get(regionalKey(region, targetSnapshotIdentifier)).isPresent();
if (shadowedByCopy || snapshots.get(targetSnapshotIdentifier).isPresent()) {
throw new AwsException("ClusterSnapshotAlreadyExists",
"Snapshot " + targetSnapshotIdentifier + " already exists", 400);
@@ -2472,7 +2633,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
private Snapshot removeSnapshot(String snapshotIdentifier, String snapshotClusterIdentifier) {
String copyKey = copyKey(regionResolver.getRegion(), snapshotIdentifier);
String copyKey = regionalKey(snapshotIdentifier);
Optional<Snapshot> copyOpt = snapshotCopies.get(copyKey);
Optional<Snapshot> snapshotOpt = copyOpt.or(() -> snapshots.get(snapshotIdentifier))
.filter(found -> takenFrom(found, snapshotClusterIdentifier));
@@ -2733,7 +2894,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (DEFAULT_PARAMETER_GROUP_NAME.equals(parameterGroupName)) {
throw new AwsException("InvalidParameterValue", "The default parameter group name is reserved.", 400);
}
if (parameterGroups.get(parameterGroupName).isPresent()) {
if (parameterGroups.get(regionalKey(parameterGroupName)).isPresent()) {
throw new AwsException("ClusterParameterGroupAlreadyExists", "Cluster parameter group " + parameterGroupName + " already exists", 400);
}
@@ -2741,7 +2902,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (tags != null) {
group.setTags(new LinkedHashMap<>(tags));
}
parameterGroups.put(parameterGroupName, group);
parameterGroups.put(regionalKey(parameterGroupName), group);
parameterGroups.flush();
emitEvent(RedshiftEventCatalog.PARAMETER_GROUP_CREATED, parameterGroupName,
"Cluster parameter group '" + parameterGroupName + "' was created.");
@@ -2750,7 +2911,7 @@ public class RedshiftService implements ManagedSecretRotator {
public List<ClusterParameterGroup> describeClusterParameterGroups(String parameterGroupName) {
if (parameterGroupName != null && !parameterGroupName.isBlank()) {
Optional<ClusterParameterGroup> group = parameterGroups.get(parameterGroupName);
Optional<ClusterParameterGroup> group = parameterGroups.get(regionalKey(parameterGroupName));
if (group.isEmpty() && DEFAULT_PARAMETER_GROUP_NAME.equals(parameterGroupName)) {
return List.of(defaultParameterGroup());
}
@@ -2759,7 +2920,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
return List.of(group.get());
}
List<ClusterParameterGroup> all = new ArrayList<>(parameterGroups.scan(k -> true));
List<ClusterParameterGroup> all = new ArrayList<>(parameterGroups.scan(inRequestRegion()));
if (all.stream().noneMatch(g -> DEFAULT_PARAMETER_GROUP_NAME.equals(g.getParameterGroupName()))) {
all.add(0, defaultParameterGroup());
}
@@ -2773,11 +2934,11 @@ public class RedshiftService implements ManagedSecretRotator {
}
public Optional<ClusterParameterGroup> getClusterParameterGroup(String parameterGroupName) {
return parameterGroups.get(parameterGroupName);
return parameterGroups.get(regionalKey(parameterGroupName));
}
public List<Parameter> describeClusterParameters(String parameterGroupName) {
ClusterParameterGroup group = parameterGroups.get(parameterGroupName)
ClusterParameterGroup group = parameterGroups.get(regionalKey(parameterGroupName))
.or(() -> DEFAULT_PARAMETER_GROUP_NAME.equals(parameterGroupName)
? Optional.of(defaultParameterGroup()) : Optional.empty())
.orElseThrow(() -> new AwsException("ClusterParameterGroupNotFound",
@@ -2788,7 +2949,7 @@ public class RedshiftService implements ManagedSecretRotator {
public synchronized ClusterParameterGroup modifyClusterParameterGroup(
String parameterGroupName, List<Parameter> updates) {
requireMutableParameterGroup(parameterGroupName);
ClusterParameterGroup group = parameterGroups.get(parameterGroupName)
ClusterParameterGroup group = parameterGroups.get(regionalKey(parameterGroupName))
.orElseThrow(() -> new AwsException("ClusterParameterGroupNotFound",
"Cluster parameter group " + parameterGroupName + " not found", 404));
@@ -2819,7 +2980,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
}
group.setParameters(current);
parameterGroups.put(parameterGroupName, group);
parameterGroups.put(regionalKey(parameterGroupName), group);
parameterGroups.flush();
refreshClustersForActivityParameter(parameterGroupName, group);
emitParameterGroupUpdated(parameterGroupName);
@@ -2832,7 +2993,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
private boolean userActivityLoggingEnabled(String parameterGroupName) {
ClusterParameterGroup group = parameterGroups.get(parameterGroupName)
ClusterParameterGroup group = parameterGroups.get(regionalKey(parameterGroupName))
.or(() -> DEFAULT_PARAMETER_GROUP_NAME.equals(parameterGroupName)
? Optional.of(defaultParameterGroup()) : Optional.empty())
.orElse(null);
@@ -2860,7 +3021,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (parameterNames.size() > MAX_RESET_PARAMETERS) {
throw new AwsException("InvalidParameterValue", "A maximum of 20 parameters can be reset.", 400);
}
ClusterParameterGroup group = parameterGroups.get(parameterGroupName)
ClusterParameterGroup group = parameterGroups.get(regionalKey(parameterGroupName))
.orElseThrow(() -> new AwsException("ClusterParameterGroupNotFound",
"Cluster parameter group " + parameterGroupName + " not found", 404));
Set<String> names = new LinkedHashSet<>();
@@ -2885,7 +3046,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
}
group.setParameters(reset);
parameterGroups.put(parameterGroupName, group);
parameterGroups.put(regionalKey(parameterGroupName), group);
parameterGroups.flush();
refreshClustersForActivityParameter(parameterGroupName, group);
emitParameterGroupUpdated(parameterGroupName);
@@ -2894,7 +3055,7 @@ public class RedshiftService implements ManagedSecretRotator {
private void refreshClustersForActivityParameter(String parameterGroupName, ClusterParameterGroup group) {
boolean enabled = userActivityLoggingEnabled(group);
String accountId = clusters.accountId();
List<Cluster> affected = clusters.scan(key -> true).stream()
List<Cluster> affected = regionalClusters().stream()
.filter(cluster -> parameterGroupName.equals(cluster.getClusterParameterGroupName())).toList();
for (Cluster cluster : affected) {
cluster.setUserActivityLoggingEnabled(enabled);
@@ -2915,7 +3076,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (name == null || name.isBlank()) {
throw new AwsException("InvalidParameterValue", "ParameterGroupName is required", 400);
}
if (DEFAULT_PARAMETER_GROUP_NAME.equals(name) && parameterGroups.get(name).isEmpty()) {
if (DEFAULT_PARAMETER_GROUP_NAME.equals(name) && parameterGroups.get(regionalKey(name)).isEmpty()) {
throw new AwsException("InvalidParameterValue", "The default parameter group cannot be modified.", 400);
}
}
@@ -2936,12 +3097,12 @@ public class RedshiftService implements ManagedSecretRotator {
}
public ClusterParameterGroup deleteClusterParameterGroup(String parameterGroupName) {
Optional<ClusterParameterGroup> groupOpt = parameterGroups.get(parameterGroupName);
Optional<ClusterParameterGroup> groupOpt = parameterGroups.get(regionalKey(parameterGroupName));
if (groupOpt.isEmpty()) {
throw new AwsException("ClusterParameterGroupNotFound", "Cluster parameter group " + parameterGroupName + " not found", 404);
}
ClusterParameterGroup group = groupOpt.get();
parameterGroups.delete(parameterGroupName);
parameterGroups.delete(regionalKey(parameterGroupName));
parameterGroups.flush();
emitEvent(RedshiftEventCatalog.PARAMETER_GROUP_DELETED, parameterGroupName,
"Cluster parameter group '" + parameterGroupName + "' was deleted at " + eventTime() + ".");
@@ -2968,7 +3129,7 @@ public class RedshiftService implements ManagedSecretRotator {
return switch (sourceType) {
case RedshiftEventCatalog.CLUSTER -> regionalCluster(sourceIdentifier).isPresent();
case RedshiftEventCatalog.PARAMETER_GROUP -> DEFAULT_PARAMETER_GROUP_NAME.equals(sourceIdentifier)
|| parameterGroups.get(sourceIdentifier).isPresent();
|| parameterGroups.get(regionalKey(sourceIdentifier)).isPresent();
case RedshiftEventCatalog.SNAPSHOT -> findSnapshot(sourceIdentifier).isPresent();
default -> false;
};
@@ -3032,7 +3193,7 @@ public class RedshiftService implements ManagedSecretRotator {
public ClusterSubnetGroup createClusterSubnetGroup(String name, String description, String vpcId,
List<String> subnetIds, Map<String, String> tags) {
if (subnetGroups.get(name).isPresent()) {
if (subnetGroups.get(regionalKey(name)).isPresent()) {
throw new AwsException("ClusterSubnetGroupAlreadyExists", "Cluster subnet group " + name + " already exists", 400);
}
ClusterSubnetGroup group = new ClusterSubnetGroup(name, description, vpcId, subnetIds);
@@ -3040,7 +3201,7 @@ public class RedshiftService implements ManagedSecretRotator {
group.setTags(new LinkedHashMap<>(tags));
}
resolveSubnets(group);
subnetGroups.put(name, group);
subnetGroups.put(regionalKey(name), group);
subnetGroups.flush();
return group;
}
@@ -3066,15 +3227,15 @@ public class RedshiftService implements ManagedSecretRotator {
public List<ClusterSubnetGroup> describeClusterSubnetGroups(String name) {
if (name != null && !name.isBlank()) {
// The Terraform AWS provider matches this exact "...Fault" code to detect a missing group.
ClusterSubnetGroup group = subnetGroups.get(name)
ClusterSubnetGroup group = subnetGroups.get(regionalKey(name))
.orElseThrow(() -> new AwsException("ClusterSubnetGroupNotFoundFault", "Cluster subnet group " + name + " not found", 400));
return List.of(group);
}
return subnetGroups.scan(k -> true);
return subnetGroups.scan(inRequestRegion());
}
public synchronized ClusterSubnetGroup modifyClusterSubnetGroup(String name, String description, List<String> subnetIds) {
ClusterSubnetGroup group = subnetGroups.get(name)
ClusterSubnetGroup group = subnetGroups.get(regionalKey(name))
.orElseThrow(() -> new AwsException("ClusterSubnetGroupNotFoundFault", "Cluster subnet group " + name + " not found", 400));
if (description != null) {
group.setDescription(description);
@@ -3084,15 +3245,15 @@ public class RedshiftService implements ManagedSecretRotator {
group.setVpcId(null);
resolveSubnets(group);
}
subnetGroups.put(name, group);
subnetGroups.put(regionalKey(name), group);
subnetGroups.flush();
return group;
}
public ClusterSubnetGroup deleteClusterSubnetGroup(String name) {
ClusterSubnetGroup group = subnetGroups.get(name)
ClusterSubnetGroup group = subnetGroups.get(regionalKey(name))
.orElseThrow(() -> new AwsException("ClusterSubnetGroupNotFoundFault", "Cluster subnet group " + name + " not found", 400));
subnetGroups.delete(name);
subnetGroups.delete(regionalKey(name));
subnetGroups.flush();
return group;
}
@@ -3105,7 +3266,7 @@ public class RedshiftService implements ManagedSecretRotator {
* has to round-trip through Describe, which is what Terraform reads back.
*/
private String defaultSnapshotCopyGrantKey() {
return regionResolver.buildArn("kms", regionResolver.getRegion(), "alias/aws/redshift");
return regionResolver.buildArn("kms", regionResolver.getRegion(), DEFAULT_SNAPSHOT_COPY_GRANT_KEY);
}
/**
@@ -3127,7 +3288,7 @@ public class RedshiftService implements ManagedSecretRotator {
// or two concurrent creates of the same name both succeed and the second overwrites the first.
public synchronized SnapshotCopyGrant createSnapshotCopyGrant(String name, String kmsKeyId, Map<String, String> tags) {
validateSnapshotCopyGrantName(name);
if (snapshotCopyGrants.get(name).isPresent()) {
if (snapshotCopyGrants.get(regionalKey(name)).isPresent()) {
throw new AwsException("SnapshotCopyGrantAlreadyExistsFault",
"Snapshot copy grant " + name + " already exists", 400);
}
@@ -3136,7 +3297,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (tags != null && !tags.isEmpty()) {
grant.setTags(new LinkedHashMap<>(tags));
}
snapshotCopyGrants.put(name, grant);
snapshotCopyGrants.put(regionalKey(name), grant);
snapshotCopyGrants.flush();
return grant;
}
@@ -3164,12 +3325,12 @@ public class RedshiftService implements ManagedSecretRotator {
List<SnapshotCopyGrant> matching;
if (name != null && !name.isBlank()) {
SnapshotCopyGrant grant = snapshotCopyGrants.get(name)
SnapshotCopyGrant grant = snapshotCopyGrants.get(regionalKey(name))
.orElseThrow(() -> new AwsException("SnapshotCopyGrantNotFoundFault",
"Snapshot copy grant " + name + " not found", 400));
matching = List.of(grant);
} else {
matching = snapshotCopyGrants.scan(k -> true);
matching = snapshotCopyGrants.scan(inRequestRegion());
}
return Pagination.paginate(matching, SnapshotCopyGrant::getSnapshotCopyGrantName,
@@ -3178,16 +3339,17 @@ public class RedshiftService implements ManagedSecretRotator {
}
public synchronized SnapshotCopyGrant deleteSnapshotCopyGrant(String name) {
SnapshotCopyGrant grant = snapshotCopyGrants.get(name)
SnapshotCopyGrant grant = snapshotCopyGrants.get(regionalKey(name))
.orElseThrow(() -> new AwsException("SnapshotCopyGrantNotFoundFault",
"Snapshot copy grant " + name + " not found", 400));
boolean inUse = clusters.scan(k -> true).stream()
.anyMatch(c -> name.equals(c.getSnapshotCopyGrantName()));
.anyMatch(c -> name.equals(c.getSnapshotCopyGrantName())
&& regionResolver.getRegion().equals(c.getSnapshotCopyDestinationRegion()));
if (inUse) {
throw new AwsException("InvalidSnapshotCopyGrantStateFault",
"Snapshot copy grant " + name + " is used by one or more clusters", 400);
}
snapshotCopyGrants.delete(name);
snapshotCopyGrants.delete(regionalKey(name));
snapshotCopyGrants.flush();
return grant;
}
@@ -3245,7 +3407,7 @@ public class RedshiftService implements ManagedSecretRotator {
validateAutomatedRetention(retention);
validateManualRetention(manualRetention);
boolean hasGrant = snapshotCopyGrantName != null && !snapshotCopyGrantName.isBlank();
if (hasGrant && snapshotCopyGrants.get(snapshotCopyGrantName).isEmpty()) {
if (hasGrant && snapshotCopyGrants.get(regionalKey(destinationRegion, snapshotCopyGrantName)).isEmpty()) {
throw new AwsException("SnapshotCopyGrantNotFoundFault",
"Snapshot copy grant " + snapshotCopyGrantName + " not found", 400);
}
@@ -3419,7 +3581,8 @@ public class RedshiftService implements ManagedSecretRotator {
return;
}
SnapshotSchedule schedule = cluster.getSnapshotScheduleIdentifier() == null ? null
: snapshotSchedules.getForAccount(accountId, cluster.getSnapshotScheduleIdentifier()).orElseThrow(
: snapshotSchedules.getForAccount(accountId,
regionalKey(clusterRegion(cluster), cluster.getSnapshotScheduleIdentifier())).orElseThrow(
() -> new AwsException("SnapshotScheduleNotFound", "The cluster's snapshot schedule is missing", 400));
List<String> definitions = schedule == null ? List.of("rate(8 hours)")
: List.copyOf(schedule.getScheduleDefinitions());
@@ -3579,7 +3742,7 @@ public class RedshiftService implements ManagedSecretRotator {
|| source.getSnapshotCreateTime().isBefore(current.getSnapshotCopyEnabledAt())) {
return null;
}
String key = copyKey(destination, snapshotId);
String key = regionalKey(destination, snapshotId);
Snapshot existing = snapshotCopies.getForAccount(accountId, key).orElse(null);
if (existing != null) {
if (Objects.equals(source.getSnapshotCreateTime(), existing.getSourceSnapshotCreateTime())) {
@@ -3649,7 +3812,8 @@ public class RedshiftService implements ManagedSecretRotator {
copy.setTags(new LinkedHashMap<>());
copy.setAccountsWithRestoreAccess(new LinkedHashSet<>());
copy.setKmsKeyId(Optional.ofNullable(cluster.getSnapshotCopyGrantName())
.flatMap(name -> snapshotCopyGrants.getForAccount(accountId, name))
.flatMap(name -> snapshotCopyGrants.getForAccount(accountId,
regionalKey(cluster.getSnapshotCopyDestinationRegion(), name)))
.map(SnapshotCopyGrant::getKmsKeyId).orElse(null));
if ("automated".equals(source.getSnapshotType())) {
copy.setAutomatedSnapshotRetentionPeriod(cluster.getSnapshotCopyRetentionPeriod());
@@ -3700,7 +3864,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
int retention;
if ("automated".equals(copy.getSnapshotType())) {
String region = key.substring(0, key.indexOf("::"));
String region = key.substring(0, key.indexOf(KEY_SEPARATOR));
// A cluster recreated under the same name has a new generation and no say over the old copies.
Integer current = clusters.getForAccount(accountId, copy.getClusterIdentifier())
.filter(cluster -> region.equals(cluster.getSnapshotCopyDestinationRegion()))
@@ -3761,7 +3925,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
private SnapshotSchedule requireSnapshotSchedule(String scheduleIdentifier) {
return snapshotSchedules.get(scheduleIdentifier)
return snapshotSchedules.get(regionalKey(scheduleIdentifier))
.orElseThrow(() -> new AwsException("SnapshotScheduleNotFound",
"Snapshot schedule " + scheduleIdentifier + " not found", 400));
}
@@ -3775,7 +3939,7 @@ public class RedshiftService implements ManagedSecretRotator {
throw new AwsException("InvalidParameterValue",
"ScheduleIdentifier may contain only letters, digits and hyphens: " + id, 400);
}
if (snapshotSchedules.get(id).isPresent()) {
if (snapshotSchedules.get(regionalKey(id)).isPresent()) {
throw new AwsException("SnapshotScheduleAlreadyExists", "Snapshot schedule " + id + " already exists", 400);
}
validateScheduleDefinitions(definitions);
@@ -3784,7 +3948,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (tags != null && !tags.isEmpty()) {
schedule.setTags(new LinkedHashMap<>(tags));
}
snapshotSchedules.put(id, schedule);
snapshotSchedules.put(regionalKey(id), schedule);
snapshotSchedules.flush();
return schedule;
}
@@ -3805,7 +3969,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
}
String byCluster = clusterSchedule;
List<SnapshotSchedule> matching = snapshotSchedules.scan(k -> true).stream()
List<SnapshotSchedule> matching = snapshotSchedules.scan(inRequestRegion()).stream()
.filter(s -> scheduleIdentifier == null || scheduleIdentifier.isBlank()
|| scheduleIdentifier.equals(s.getScheduleIdentifier()))
.filter(s -> byCluster == null || byCluster.equals(s.getScheduleIdentifier()))
@@ -3820,7 +3984,7 @@ public class RedshiftService implements ManagedSecretRotator {
/** Identifiers of the clusters currently using the schedule, sorted for a stable response. */
public List<String> clustersUsingSnapshotSchedule(String scheduleIdentifier) {
return clusters.scan(k -> true).stream()
return regionalClusters().stream()
.filter(c -> scheduleIdentifier.equals(c.getSnapshotScheduleIdentifier()))
.map(Cluster::getClusterIdentifier)
.sorted()
@@ -3833,7 +3997,7 @@ public class RedshiftService implements ManagedSecretRotator {
SnapshotSchedule schedule = new SnapshotSchedule(scheduleIdentifier, current.getScheduleDescription(), definitions);
schedule.setTags(new LinkedHashMap<>(current.getTags()));
schedule.setUpdatedAt(Instant.now());
snapshotSchedules.put(scheduleIdentifier, schedule);
snapshotSchedules.put(regionalKey(scheduleIdentifier), schedule);
snapshotSchedules.flush();
return schedule;
}
@@ -3844,7 +4008,7 @@ public class RedshiftService implements ManagedSecretRotator {
throw new AwsException("InvalidClusterSnapshotScheduleState",
"Snapshot schedule " + scheduleIdentifier + " is associated with one or more clusters.", 400);
}
snapshotSchedules.delete(scheduleIdentifier);
snapshotSchedules.delete(regionalKey(scheduleIdentifier));
snapshotSchedules.flush();
}
@@ -3923,7 +4087,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
if (resourceType == null || "snapshot".equalsIgnoreCase(resourceType)) {
for (Snapshot s : snapshots.scan(k -> true)) {
if (snapshotCopies.get(copyKey(regionResolver.getRegion(), s.getSnapshotIdentifier())).isPresent()) {
if (snapshotCopies.get(regionalKey(s.getSnapshotIdentifier())).isPresent()) {
continue;
}
addTaggedResources(result, snapshotArn(s.getClusterIdentifier(), s.getSnapshotIdentifier()),
@@ -3934,25 +4098,25 @@ public class RedshiftService implements ManagedSecretRotator {
}
}
if (resourceType == null || "parametergroup".equalsIgnoreCase(resourceType)) {
for (ClusterParameterGroup g : parameterGroups.scan(k -> true)) {
for (ClusterParameterGroup g : parameterGroups.scan(inRequestRegion())) {
addTaggedResources(result, parameterGroupArn(g.getParameterGroupName()),
"parametergroup", g.getTags(), tagKeysFilter);
}
}
if (resourceType == null || "subnetgroup".equalsIgnoreCase(resourceType)) {
for (ClusterSubnetGroup g : subnetGroups.scan(k -> true)) {
for (ClusterSubnetGroup g : subnetGroups.scan(inRequestRegion())) {
addTaggedResources(result, subnetGroupArn(g.getClusterSubnetGroupName()),
"subnetgroup", g.getTags(), tagKeysFilter);
}
}
if (resourceType == null || "snapshotcopygrant".equalsIgnoreCase(resourceType)) {
for (SnapshotCopyGrant g : snapshotCopyGrants.scan(k -> true)) {
for (SnapshotCopyGrant g : snapshotCopyGrants.scan(inRequestRegion())) {
addTaggedResources(result, snapshotCopyGrantArn(g.getSnapshotCopyGrantName()),
"snapshotcopygrant", g.getTags(), tagKeysFilter);
}
}
if (resourceType == null || "snapshotschedule".equalsIgnoreCase(resourceType)) {
for (SnapshotSchedule s : snapshotSchedules.scan(k -> true)) {
for (SnapshotSchedule s : snapshotSchedules.scan(inRequestRegion())) {
addTaggedResources(result, snapshotScheduleArn(s.getScheduleIdentifier()),
"snapshotschedule", s.getTags(), tagKeysFilter);
}
@@ -4083,7 +4247,7 @@ public class RedshiftService implements ManagedSecretRotator {
}
case "snapshot" -> {
String snapshotId = id.contains("/") ? id.substring(id.lastIndexOf('/') + 1) : id;
String copyKey = copyKey(arn.region(), snapshotId);
String copyKey = regionalKey(arn.region(), snapshotId);
Snapshot copy = snapshotCopies.get(copyKey).orElse(null);
if (copy != null) {
yield new TagHandle(copy.getTags(), updated -> {
@@ -4101,20 +4265,20 @@ public class RedshiftService implements ManagedSecretRotator {
});
}
case "parametergroup" -> {
ClusterParameterGroup group = parameterGroups.get(id)
ClusterParameterGroup group = parameterGroups.get(regionalKey(id))
.orElseThrow(() -> new AwsException("ClusterParameterGroupNotFound", "Cluster parameter group " + id + " not found", 404));
yield new TagHandle(group.getTags(), updated -> {
group.setTags(updated);
parameterGroups.put(id, group);
parameterGroups.put(regionalKey(id), group);
parameterGroups.flush();
});
}
case "subnetgroup" -> {
ClusterSubnetGroup group = subnetGroups.get(id)
ClusterSubnetGroup group = subnetGroups.get(regionalKey(id))
.orElseThrow(() -> new AwsException("ClusterSubnetGroupNotFoundFault", "Cluster subnet group " + id + " not found", 400));
yield new TagHandle(group.getTags(), updated -> {
group.setTags(updated);
subnetGroups.put(id, group);
subnetGroups.put(regionalKey(id), group);
subnetGroups.flush();
});
}
@@ -4127,21 +4291,21 @@ public class RedshiftService implements ManagedSecretRotator {
// ClusterParameterGroupNotFound are each modelled at 404. The grant fault is
// modelled at 400, so emitting it here would pair a code with a status the
// model never gives it.
SnapshotCopyGrant grant = snapshotCopyGrants.get(id)
SnapshotCopyGrant grant = snapshotCopyGrants.get(regionalKey(id))
.orElseThrow(() -> new AwsException("ResourceNotFoundFault", "Snapshot copy grant " + id + " not found", 404));
yield new TagHandle(grant.getTags(), updated -> {
grant.setTags(updated);
snapshotCopyGrants.put(id, grant);
snapshotCopyGrants.put(regionalKey(id), grant);
snapshotCopyGrants.flush();
});
}
case "snapshotschedule" -> {
// ResourceNotFoundFault for the same reason as snapshotcopygrant above.
SnapshotSchedule schedule = snapshotSchedules.get(id)
SnapshotSchedule schedule = snapshotSchedules.get(regionalKey(id))
.orElseThrow(() -> new AwsException("ResourceNotFoundFault", "Snapshot schedule " + id + " not found", 404));
yield new TagHandle(schedule.getTags(), updated -> {
schedule.setTags(updated);
snapshotSchedules.put(id, schedule);
snapshotSchedules.put(regionalKey(id), schedule);
snapshotSchedules.flush();
});
}