|
|
|
@@ -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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|