mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(redshiftserverless): add snapshot and restore operations (#5184)
* feat(redshiftserverless): add snapshot and restore operations Adds CreateSnapshot, GetSnapshot (by name or ARN), ListSnapshots (filterable by namespace), DeleteSnapshot and RestoreFromSnapshot on top of the existing workgroup support. A snapshot is AVAILABLE as soon as it is created, so a snapshot created in a standby region stands in for a cross-region copy. RestoreFromSnapshot restores into an existing namespace and workgroup and never creates either. * docs(redshiftserverless): document snapshot and restore actions * docs(redshiftserverless): update service matrix operation count * fix(redshiftserverless): validate snapshot restore and ARN lookup Reject a RestoreFromSnapshot workgroup that belongs to another namespace, resolve snapshotArn only for this account and Region, and register the snapshot model for reflection so persisted snapshots survive a native restart. * fix(redshiftserverless): harden snapshot restore and add lifecycle tests Validate namespaceName and snapshot names, accept snapshotArn on RestoreFromSnapshot, read the snapshot once during restore, and cover the handler with an integration lifecycle test and a Java SDK compatibility test. * feat(redshiftserverless): dump and restore snapshot data and model retention, tags and filters CreateSnapshot dumps a running workgroup with pg_dump and RestoreFromSnapshot empties the public schema and replays the dump, reusing the provisioned Redshift container manager. Snapshots now report adminUsername, kmsKeyId and retention, accept tags (taggable by ARN), ListSnapshots filters by namespaceArn, ownerAccount and a time window, and RestoreFromSnapshot rejects snapshotName and snapshotArn together. * fix(redshiftserverless): make snapshot restore atomic and strict Dump the current contents before a restore and put them back when the replay fails, drop every user schema rather than only public, run psql with ON_ERROR_STOP so a failing statement fails the restore, and fail a restore whose recorded dump file is missing. * fix(redshiftserverless): keep the catalog bootstrap schema out of snapshot restore The reset dropped floci_internal and with it the pg_catalog svv_external_* views, so the strict replay failed. Leave that schema out of the reset and out of the dump. * fix(redshiftserverless): drop large objects when resetting before a restore * refactor(redshift): share container lookup and defaults in the container manager * docs(redshiftserverless): document the bootstrap schema left out of snapshots * style(redshiftserverless): order imports in the runtime test --------- Co-authored-by: yarammanasa2001-max <271440416+yarammanasa2001-max@users.noreply.github.com>
This commit is contained in:
1 parent
43c616d757
commit
9934b39a42
12 files changed
+1076
-30
No files matched your search
+86
-18
@@ -181,16 +181,44 @@ public class RedshiftContainerManager {
|
||||
return ContainerStorageHelper.dockerName(config, "redshift-" + accountId + "-" + clusterIdentifier);
|
||||
}
|
||||
|
||||
public void takeSnapshot(String accountId, String clusterIdentifier, String username, String dbname, Path outputFile) {
|
||||
private RedshiftContainerHandle requireHandle(String accountId, String clusterIdentifier) {
|
||||
RedshiftContainerHandle handle = containers.get(containerKey(accountId, clusterIdentifier));
|
||||
if (handle == null) {
|
||||
throw new AwsException("ClusterNotFound", "Cluster container for " + clusterIdentifier + " not found", 404);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
String effectiveUser = (username != null && !username.isBlank()) ? username : "postgres";
|
||||
String effectiveDb = (dbname != null && !dbname.isBlank()) ? dbname : "dev";
|
||||
private static String userOrDefault(String username) {
|
||||
return (username != null && !username.isBlank()) ? username : "postgres";
|
||||
}
|
||||
|
||||
String[] cmd = new String[]{"pg_dump", "-U", effectiveUser, effectiveDb, "-f", "/tmp/dump.sql"};
|
||||
private static String databaseOrDefault(String dbname) {
|
||||
return (dbname != null && !dbname.isBlank()) ? dbname : DEFAULT_DATABASE;
|
||||
}
|
||||
|
||||
/** Schema {@code bootstrap-catalog.sql} owns; the catalog views read it, so snapshots leave it alone. */
|
||||
public static final String BOOTSTRAP_SCHEMA = "floci_internal";
|
||||
|
||||
public void takeSnapshot(String accountId, String clusterIdentifier, String username, String dbname, Path outputFile) {
|
||||
takeSnapshot(accountId, clusterIdentifier, username, dbname, outputFile, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the database with pg_dump. With {@code skipBootstrapSchema} the {@link #BOOTSTRAP_SCHEMA}
|
||||
* is left out, which a dump meant to be replayed into a live, already bootstrapped container needs.
|
||||
*/
|
||||
public void takeSnapshot(String accountId, String clusterIdentifier, String username, String dbname,
|
||||
Path outputFile, boolean skipBootstrapSchema) {
|
||||
RedshiftContainerHandle handle = requireHandle(accountId, clusterIdentifier);
|
||||
|
||||
String effectiveUser = userOrDefault(username);
|
||||
String effectiveDb = databaseOrDefault(dbname);
|
||||
|
||||
String[] cmd = skipBootstrapSchema
|
||||
? new String[]{"pg_dump", "-U", effectiveUser, "--exclude-schema=" + BOOTSTRAP_SCHEMA, effectiveDb,
|
||||
"-f", "/tmp/dump.sql"}
|
||||
: new String[]{"pg_dump", "-U", effectiveUser, effectiveDb, "-f", "/tmp/dump.sql"};
|
||||
try {
|
||||
ContainerExec.Result result = execInContainer(handle.getContainerId(), cmd, 30);
|
||||
if (result.exitCode() != 0) {
|
||||
@@ -222,11 +250,8 @@ public class RedshiftContainerManager {
|
||||
/** As the four-argument form, connecting to {@code databaseName} instead of {@code dev}. */
|
||||
public void alterUserPassword(String accountId, String clusterIdentifier, String username, String newPassword,
|
||||
String databaseName) {
|
||||
RedshiftContainerHandle handle = containers.get(containerKey(accountId, clusterIdentifier));
|
||||
if (handle == null) {
|
||||
throw new AwsException("ClusterNotFound", "Cluster container for " + clusterIdentifier + " not found", 404);
|
||||
}
|
||||
String effectiveUser = (username != null && !username.isBlank()) ? username : "postgres";
|
||||
RedshiftContainerHandle handle = requireHandle(accountId, clusterIdentifier);
|
||||
String effectiveUser = userOrDefault(username);
|
||||
// Validate effectiveUser against safe SQL identifier pattern to prevent SQL injection.
|
||||
// psql -c sends the query string to Postgres, which allows multiple ;-separated statements,
|
||||
// so even argv-escaping doesn't protect against a username like "postgres; DROP TABLE ..."
|
||||
@@ -281,18 +306,24 @@ public class RedshiftContainerManager {
|
||||
}
|
||||
|
||||
public void restoreSnapshot(String accountId, String clusterIdentifier, String username, String dbname, Path sqlDumpFile) {
|
||||
RedshiftContainerHandle handle = containers.get(containerKey(accountId, clusterIdentifier));
|
||||
if (handle == null) {
|
||||
throw new AwsException("ClusterNotFound", "Cluster container for " + clusterIdentifier + " not found", 404);
|
||||
}
|
||||
restoreSnapshot(accountId, clusterIdentifier, username, dbname, sqlDumpFile, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replays the dump with psql. With {@code stopOnError} the first failing statement aborts the
|
||||
* replay and fails the call, instead of psql skipping it and exiting successfully.
|
||||
*/
|
||||
public void restoreSnapshot(String accountId, String clusterIdentifier, String username, String dbname,
|
||||
Path sqlDumpFile, boolean stopOnError) {
|
||||
RedshiftContainerHandle handle = requireHandle(accountId, clusterIdentifier);
|
||||
|
||||
if (sqlDumpFile == null || !Files.exists(sqlDumpFile)) {
|
||||
LOG.infov("Empty snapshot dump for cluster {0}, skipping restore", clusterIdentifier);
|
||||
return;
|
||||
}
|
||||
|
||||
String effectiveUser = (username != null && !username.isBlank()) ? username : "postgres";
|
||||
String effectiveDb = (dbname != null && !dbname.isBlank()) ? dbname : "dev";
|
||||
String effectiveUser = userOrDefault(username);
|
||||
String effectiveDb = databaseOrDefault(dbname);
|
||||
String fileName = sqlDumpFile.getFileName().toString();
|
||||
|
||||
try {
|
||||
@@ -301,7 +332,10 @@ public class RedshiftContainerManager {
|
||||
.withRemotePath("/tmp")
|
||||
.exec();
|
||||
|
||||
String[] cmd = new String[]{"psql", "-U", effectiveUser, "-d", effectiveDb, "-f", "/tmp/" + fileName};
|
||||
String[] cmd = stopOnError
|
||||
? new String[]{"psql", "-U", effectiveUser, "-d", effectiveDb, "-v", "ON_ERROR_STOP=1",
|
||||
"-f", "/tmp/" + fileName}
|
||||
: new String[]{"psql", "-U", effectiveUser, "-d", effectiveDb, "-f", "/tmp/" + fileName};
|
||||
ContainerExec.Result result = execInContainer(handle.getContainerId(), cmd, 60);
|
||||
if (result.exitCode() != 0) {
|
||||
LOG.warnv("psql restore failed for cluster {0} (exit {1}): {2}", clusterIdentifier, result.exitCode(), result.stderr());
|
||||
@@ -315,6 +349,40 @@ public class RedshiftContainerManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static final String DROP_USER_SCHEMAS_SQL = "DO $$ DECLARE s text; BEGIN "
|
||||
+ "PERFORM lo_unlink(oid) FROM pg_largeobject_metadata; "
|
||||
+ "FOR s IN SELECT nspname FROM pg_namespace WHERE nspname NOT IN ('pg_catalog', 'information_schema') "
|
||||
+ "AND nspname <> '" + BOOTSTRAP_SCHEMA + "' AND nspname NOT LIKE 'pg\\_%' LOOP EXECUTE format('DROP SCHEMA %I CASCADE', s); END LOOP; "
|
||||
+ "CREATE SCHEMA public; END $$;";
|
||||
|
||||
/**
|
||||
* Drops every large object and every user schema except the bootstrap one, and recreates an
|
||||
* empty {@code public} one, so a following {@link #restoreSnapshot} replays into a clean
|
||||
* database rather than appending to what is already there.
|
||||
*/
|
||||
public void resetUserSchemas(String accountId, String clusterIdentifier, String username, String dbname) {
|
||||
RedshiftContainerHandle handle = requireHandle(accountId, clusterIdentifier);
|
||||
String effectiveUser = userOrDefault(username);
|
||||
String effectiveDb = databaseOrDefault(dbname);
|
||||
String[] cmd = new String[]{"psql", "-U", effectiveUser, "-d", effectiveDb, "-c",
|
||||
DROP_USER_SCHEMAS_SQL};
|
||||
try {
|
||||
ContainerExec.Result result = execInContainer(handle.getContainerId(), cmd, 30);
|
||||
if (result.exitCode() != 0) {
|
||||
LOG.warnv("Schema reset failed for cluster {0} (exit {1}): {2}", clusterIdentifier,
|
||||
result.exitCode(), result.stderr());
|
||||
throw new AwsException("InternalFailure", "Failed to reset the database of " + clusterIdentifier
|
||||
+ ": " + result.stderr(), 500);
|
||||
}
|
||||
} catch (AwsException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
LOG.errorv(e, "Error resetting the database of cluster {0}", clusterIdentifier);
|
||||
throw new AwsException("InternalFailure", "Failed to reset the database of " + clusterIdentifier
|
||||
+ ": " + e.getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreSnapshot(String accountId, String clusterIdentifier, String username, Path sqlDumpFile) {
|
||||
restoreSnapshot(accountId, clusterIdentifier, username, "dev", sqlDumpFile);
|
||||
}
|
||||
@@ -344,7 +412,7 @@ public class RedshiftContainerManager {
|
||||
return bos.toByteArray();
|
||||
}
|
||||
private void waitForReady(String containerName, String containerId, String username, String dbName) {
|
||||
String effectiveUser = (username != null && !username.isBlank()) ? username : "postgres";
|
||||
String effectiveUser = userOrDefault(username);
|
||||
String[] cmd = {
|
||||
"psql",
|
||||
"-h", "127.0.0.1",
|
||||
@@ -384,7 +452,7 @@ public class RedshiftContainerManager {
|
||||
* and migration tooling can inspect metadata without relation-does-not-exist errors.
|
||||
*/
|
||||
void bootstrapCatalog(String containerId, String username, String dbName) {
|
||||
String effectiveUser = (username != null && !username.isBlank()) ? username : "postgres";
|
||||
String effectiveUser = userOrDefault(username);
|
||||
String effectiveDb = (dbName != null && !dbName.isBlank()) ? dbName : "dev";
|
||||
try (InputStream in = getClass().getResourceAsStream("/redshift/bootstrap-catalog.sql")) {
|
||||
if (in == null) {
|
||||
|
||||
+102
@@ -13,12 +13,15 @@ import io.github.hectorvent.floci.services.redshift.TempCredential;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.ConfigParameter;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.Namespace;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.PricePerformanceTarget;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.RedshiftServerlessSnapshot;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.Workgroup;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -76,6 +79,11 @@ public class RedshiftServerlessJsonHandler {
|
||||
case "ListWorkgroups" -> handleListWorkgroups(request, region);
|
||||
case "UpdateWorkgroup" -> handleUpdateWorkgroup(request, region);
|
||||
case "DeleteWorkgroup" -> handleDeleteWorkgroup(request, region);
|
||||
case "CreateSnapshot" -> handleCreateSnapshot(request, region);
|
||||
case "GetSnapshot" -> handleGetSnapshot(request, region);
|
||||
case "ListSnapshots" -> handleListSnapshots(request, region);
|
||||
case "DeleteSnapshot" -> handleDeleteSnapshot(request, region);
|
||||
case "RestoreFromSnapshot" -> handleRestoreFromSnapshot(request, region);
|
||||
case "GetCredentials" -> handleGetCredentials(request, region, authorizationHeader);
|
||||
case "ListTagsForResource" -> handleListTagsForResource(request, region);
|
||||
case "TagResource" -> handleTagResource(request, region);
|
||||
@@ -199,6 +207,59 @@ public class RedshiftServerlessJsonHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleCreateSnapshot(JsonNode request, String region) {
|
||||
return snapshotResponse(service.createSnapshot(
|
||||
text(request, "snapshotName"), text(request, "namespaceName"),
|
||||
parseInteger(request, "retentionPeriod"), parseTagList(request.path("tags"), "tags"), region));
|
||||
}
|
||||
|
||||
/**
|
||||
* GetSnapshot also accepts {@code snapshotArn}, which must name a snapshot of this account
|
||||
* and Region.
|
||||
*/
|
||||
private Response handleGetSnapshot(JsonNode request, String region) {
|
||||
return snapshotResponse(service.getSnapshot(snapshotNameOf(request, region), region));
|
||||
}
|
||||
|
||||
private Response handleListSnapshots(JsonNode request, String region) {
|
||||
PaginatedResult<RedshiftServerlessSnapshot> page = service.listSnapshots(
|
||||
text(request, "namespaceName"), text(request, "namespaceArn"), text(request, "ownerAccount"),
|
||||
parseEpochSeconds(request, "startTime"), parseEpochSeconds(request, "endTime"), region,
|
||||
parseMaxResults(request), text(request, "nextToken"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode items = response.putArray("snapshots");
|
||||
page.items().forEach(snapshot -> items.add(snapshotNode(snapshot)));
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteSnapshot(JsonNode request, String region) {
|
||||
return snapshotResponse(service.deleteSnapshot(text(request, "snapshotName"), region));
|
||||
}
|
||||
|
||||
private Response handleRestoreFromSnapshot(JsonNode request, String region) {
|
||||
RedshiftServerlessService.RestoreResult result = service.restoreFromSnapshot(
|
||||
text(request, "namespaceName"), text(request, "workgroupName"),
|
||||
snapshotNameOf(request, region), text(request, "ownerAccount"), region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("namespace", namespaceNode(result.namespace()));
|
||||
response.put("ownerAccount", result.snapshot().getOwnerAccount());
|
||||
response.put("snapshotName", result.snapshot().getSnapshotName());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/** The snapshot name from {@code snapshotName}, or recovered from {@code snapshotArn} when absent. */
|
||||
private String snapshotNameOf(JsonNode request, String region) {
|
||||
String snapshotName = text(request, "snapshotName");
|
||||
String snapshotArn = text(request, "snapshotArn");
|
||||
if (snapshotName != null && snapshotArn != null) {
|
||||
throw validation("snapshotName and snapshotArn cannot both be specified.");
|
||||
}
|
||||
return snapshotArn == null ? snapshotName : service.snapshotNameFromArn(snapshotArn, region);
|
||||
}
|
||||
|
||||
private Response handleListTagsForResource(JsonNode request, String region) {
|
||||
Map<String, String> tags = service.listTagsForResource(text(request, "resourceArn"), region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
@@ -260,6 +321,35 @@ public class RedshiftServerlessJsonHandler {
|
||||
return node;
|
||||
}
|
||||
|
||||
private Response snapshotResponse(RedshiftServerlessSnapshot snapshot) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("snapshot", snapshotNode(snapshot));
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private ObjectNode snapshotNode(RedshiftServerlessSnapshot snapshot) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("snapshotName", snapshot.getSnapshotName());
|
||||
node.put("snapshotArn", snapshot.getSnapshotArn());
|
||||
node.put("namespaceName", snapshot.getNamespaceName());
|
||||
node.put("namespaceArn", snapshot.getNamespaceArn());
|
||||
node.put("ownerAccount", snapshot.getOwnerAccount());
|
||||
node.put("status", snapshot.getStatus());
|
||||
node.put("adminUsername", snapshot.getAdminUsername());
|
||||
if (snapshot.getKmsKeyId() != null) {
|
||||
node.put("kmsKeyId", snapshot.getKmsKeyId());
|
||||
}
|
||||
if (snapshot.getRetentionPeriod() != null) {
|
||||
node.put("snapshotRetentionPeriod", snapshot.getRetentionPeriod());
|
||||
long elapsedDays = Duration.between(snapshot.getSnapshotCreateTime(), Instant.now()).toDays();
|
||||
node.put("snapshotRemainingDays", Math.max(0, snapshot.getRetentionPeriod() - elapsedDays));
|
||||
}
|
||||
if (snapshot.getSnapshotCreateTime() != null) {
|
||||
node.put("snapshotCreateTime", CREATION_DATE_FORMAT.format(snapshot.getSnapshotCreateTime()));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
private Response workgroupResponse(Workgroup workgroup) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("workgroup", workgroupNode(workgroup));
|
||||
@@ -387,6 +477,18 @@ public class RedshiftServerlessJsonHandler {
|
||||
return new PricePerformanceTarget(text(node, "status"), parseInteger(node, "level"));
|
||||
}
|
||||
|
||||
/** A timestamp request member, which awsJson1.1 sends as epoch seconds unless the model says otherwise. */
|
||||
private Instant parseEpochSeconds(JsonNode request, String field) {
|
||||
JsonNode node = request.path(field);
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
return null;
|
||||
}
|
||||
if (!node.isNumber()) {
|
||||
throw validation(field + " must be a timestamp.");
|
||||
}
|
||||
return Instant.ofEpochMilli(Math.round(node.asDouble() * 1000));
|
||||
}
|
||||
|
||||
private Integer parseMaxResults(JsonNode request) {
|
||||
JsonNode node = request.path("maxResults");
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
|
||||
+56
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.PasswordValidator;
|
||||
import io.github.hectorvent.floci.services.redshift.RedshiftCredentialBroker;
|
||||
import io.github.hectorvent.floci.services.redshift.TempCredential;
|
||||
@@ -11,6 +12,9 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -81,6 +85,58 @@ public class RedshiftServerlessRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
/** Dumps the workgroup's database to {@code outputFile} with pg_dump. */
|
||||
public void takeSnapshot(String accountId, String region, String workgroupName, String masterUsername,
|
||||
String dbName, Path outputFile) {
|
||||
containerManager.takeSnapshot(accountId, backendId(region, workgroupName), masterUsername, dbName, outputFile,
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the workgroup's database contents with the dump in {@code dumpFile}. The current
|
||||
* contents are dumped first, and when the replay fails they are put back, so a bad dump never
|
||||
* leaves the workgroup empty or half restored.
|
||||
*/
|
||||
public void restoreSnapshot(String accountId, String region, String workgroupName, String masterUsername,
|
||||
String dbName, Path dumpFile) {
|
||||
String backendId = backendId(region, workgroupName);
|
||||
Path safety;
|
||||
try {
|
||||
safety = Files.createTempFile("redshift-serverless-restore-" + workgroupName + "-", ".sql");
|
||||
} catch (IOException e) {
|
||||
throw new AwsException("InternalServerException",
|
||||
"Failed to prepare the restore of workgroup " + workgroupName + ": " + e.getMessage(), 500);
|
||||
}
|
||||
try {
|
||||
containerManager.takeSnapshot(accountId, backendId, masterUsername, dbName, safety, true);
|
||||
try {
|
||||
containerManager.resetUserSchemas(accountId, backendId, masterUsername, dbName);
|
||||
containerManager.restoreSnapshot(accountId, backendId, masterUsername, dbName, dumpFile, true);
|
||||
} catch (RuntimeException e) {
|
||||
rollBackRestore(accountId, backendId, masterUsername, dbName, safety, e);
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
Files.deleteIfExists(safety);
|
||||
} catch (IOException e) {
|
||||
LOG.warnv(e, "Could not delete the pre-restore dump {0}", safety);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void rollBackRestore(String accountId, String backendId, String masterUsername, String dbName,
|
||||
Path safety, RuntimeException failure) {
|
||||
try {
|
||||
containerManager.resetUserSchemas(accountId, backendId, masterUsername, dbName);
|
||||
containerManager.restoreSnapshot(accountId, backendId, masterUsername, dbName, safety, true);
|
||||
} catch (RuntimeException rollbackFailure) {
|
||||
LOG.errorv(rollbackFailure, "Could not put back the previous contents of {0} after a failed restore",
|
||||
backendId);
|
||||
failure.addSuppressed(rollbackFailure);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the proxy first and lets a failure propagate: if the listener cannot be closed the
|
||||
* port must stay reserved and the workgroup must stay on record, so the caller can retry.
|
||||
|
||||
+253
-7
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
@@ -12,6 +13,7 @@ import io.github.hectorvent.floci.services.redshift.TempCredential;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.ConfigParameter;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.Namespace;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.PricePerformanceTarget;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.RedshiftServerlessSnapshot;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.Workgroup;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import jakarta.annotation.Priority;
|
||||
@@ -21,6 +23,10 @@ import jakarta.inject.Inject;
|
||||
import jakarta.interceptor.Interceptor;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -87,6 +93,8 @@ public class RedshiftServerlessService implements Resettable {
|
||||
public static final int MIN_CREDENTIAL_DURATION_SECONDS = 900;
|
||||
public static final int MAX_CREDENTIAL_DURATION_SECONDS = 3600;
|
||||
|
||||
private static final int MAX_RETENTION_DAYS = 3653;
|
||||
private static final Pattern SNAPSHOT_NAME = Pattern.compile("[a-z0-9-]+");
|
||||
private static final Pattern WORKGROUP_NAME = Pattern.compile("[a-z0-9-]+");
|
||||
private static final Pattern TRACK_NAME = Pattern.compile("[a-zA-Z0-9_]+");
|
||||
private static final Set<String> IP_ADDRESS_TYPES = Set.of("ipv4", "dualstack");
|
||||
@@ -94,20 +102,26 @@ public class RedshiftServerlessService implements Resettable {
|
||||
|
||||
private final AccountAwareStorageBackend<Namespace> namespaces;
|
||||
private final AccountAwareStorageBackend<Workgroup> workgroups;
|
||||
private final AccountAwareStorageBackend<RedshiftServerlessSnapshot> snapshots;
|
||||
private final RegionResolver regionResolver;
|
||||
private final RedshiftServerlessEndpoints endpoints;
|
||||
private final RedshiftServerlessRuntime runtime;
|
||||
private final EmulatorConfig config;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessService(StorageFactory storageFactory, RegionResolver regionResolver,
|
||||
RedshiftServerlessEndpoints endpoints, RedshiftServerlessRuntime runtime) {
|
||||
RedshiftServerlessEndpoints endpoints, RedshiftServerlessRuntime runtime,
|
||||
EmulatorConfig config) {
|
||||
this.namespaces = storageFactory.create("redshiftserverless", "redshiftserverless-namespaces.json",
|
||||
new TypeReference<Map<String, Namespace>>() {});
|
||||
this.workgroups = storageFactory.create("redshiftserverless", "redshiftserverless-workgroups.json",
|
||||
new TypeReference<Map<String, Workgroup>>() {});
|
||||
this.snapshots = storageFactory.create("redshiftserverless", "redshiftserverless-snapshots.json",
|
||||
new TypeReference<Map<String, RedshiftServerlessSnapshot>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
this.endpoints = endpoints;
|
||||
this.runtime = runtime;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,13 +347,209 @@ public class RedshiftServerlessService implements Resettable {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a snapshot directly in {@code region}. Real {@code CreateSnapshot} always creates
|
||||
* in the source namespace's own region; a snapshot that should appear as a cross-region copy
|
||||
* is created by calling this in the standby region, where it is immediately AVAILABLE. When
|
||||
* the namespace's workgroup has a live database its contents are dumped with pg_dump, the way
|
||||
* provisioned Redshift snapshots work; with no live database the snapshot is metadata only.
|
||||
*/
|
||||
public synchronized RedshiftServerlessSnapshot createSnapshot(String snapshotName, String namespaceName,
|
||||
Integer retentionPeriod,
|
||||
Map<String, String> tags, String region) {
|
||||
validateSnapshotName(snapshotName);
|
||||
Integer retentionDays = validateRetentionPeriod(retentionPeriod);
|
||||
Namespace namespace = getNamespace(namespaceName, region);
|
||||
String key = storageKey(region, snapshotName);
|
||||
if (snapshots.get(key).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"The snapshot " + snapshotName + " already exists.", 409);
|
||||
}
|
||||
RedshiftServerlessSnapshot snapshot = new RedshiftServerlessSnapshot();
|
||||
snapshot.setSnapshotName(snapshotName);
|
||||
snapshot.setNamespaceName(namespaceName);
|
||||
snapshot.setNamespaceArn(namespace.getNamespaceArn());
|
||||
snapshot.setRegion(region);
|
||||
snapshot.setAccountId(regionResolver.getAccountId());
|
||||
snapshot.setOwnerAccount(regionResolver.getAccountId());
|
||||
snapshot.setSnapshotArn(regionResolver.buildArn("redshift-serverless", region, "snapshot/" + snapshotName));
|
||||
snapshot.setStatus("AVAILABLE");
|
||||
snapshot.setSnapshotCreateTime(Instant.now());
|
||||
snapshot.setAdminUsername(adminUserOf(namespace));
|
||||
snapshot.setKmsKeyId(namespace.getKmsKeyId());
|
||||
snapshot.setRetentionPeriod(retentionDays);
|
||||
snapshot.setTags(tags);
|
||||
dumpDatabase(snapshot, namespace, region);
|
||||
snapshots.put(key, snapshot);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
private static Integer validateRetentionPeriod(Integer retentionPeriod) {
|
||||
if (retentionPeriod == null || retentionPeriod == -1) {
|
||||
return null;
|
||||
}
|
||||
if (retentionPeriod < 1 || retentionPeriod > MAX_RETENTION_DAYS) {
|
||||
throw validation("retentionPeriod must be -1 (indefinite) or between 1 and " + MAX_RETENTION_DAYS + ".");
|
||||
}
|
||||
return retentionPeriod;
|
||||
}
|
||||
|
||||
private void dumpDatabase(RedshiftServerlessSnapshot snapshot, Namespace namespace, String region) {
|
||||
Optional<Workgroup> attached = workgroupOf(namespace.getNamespaceName(), region);
|
||||
if (attached.isEmpty() || !hasLiveRuntime(attached.get())) {
|
||||
return;
|
||||
}
|
||||
Path dumpFile = dumpFileOf(snapshot.getSnapshotName(), region);
|
||||
try {
|
||||
Files.createDirectories(dumpFile.getParent());
|
||||
runtime.takeSnapshot(workgroups.accountId(), region, attached.get().getWorkgroupName(),
|
||||
attached.get().getMasterUsername(), namespace.getDbName(), dumpFile);
|
||||
snapshot.setSqlDump(dumpFile.toString());
|
||||
} catch (IOException e) {
|
||||
throw new AwsException("InternalServerException",
|
||||
"Failed to take snapshot " + snapshot.getSnapshotName() + ": " + e.getMessage(), 500);
|
||||
} catch (RuntimeException e) {
|
||||
deleteDumpQuietly(dumpFile);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasLiveRuntime(Workgroup workgroup) {
|
||||
return workgroup.getRuntimeHost() != null && workgroup.getRuntimePort() > 0;
|
||||
}
|
||||
|
||||
/** Absolute, normalised {@code <persistentPath>/redshift-serverless-dumps/<accountId>/<region>} directory. */
|
||||
private Path dumpDir(String region) {
|
||||
return Paths.get(config.storage().persistentPath())
|
||||
.resolve("redshift-serverless-dumps")
|
||||
.resolve(workgroups.accountId())
|
||||
.resolve(region)
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
}
|
||||
|
||||
private Path dumpFileOf(String snapshotName, String region) {
|
||||
Path dir = dumpDir(region);
|
||||
Path file = dir.resolve(snapshotName + ".sql").normalize();
|
||||
if (!file.startsWith(dir)) {
|
||||
throw validation("Invalid snapshotName.");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/** A stored dump path is trusted only while it still resolves inside this account's dump directory. */
|
||||
private Optional<Path> trustedDump(RedshiftServerlessSnapshot snapshot, String region) {
|
||||
String stored = snapshot.getSqlDump();
|
||||
if (stored == null || stored.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Path file = Paths.get(stored).toAbsolutePath().normalize();
|
||||
return file.startsWith(dumpDir(region)) ? Optional.of(file) : Optional.empty();
|
||||
}
|
||||
|
||||
private static void deleteDumpQuietly(Path dumpFile) {
|
||||
try {
|
||||
Files.deleteIfExists(dumpFile);
|
||||
} catch (IOException e) {
|
||||
LOG.warnv(e, "Could not delete the snapshot dump {0}", dumpFile);
|
||||
}
|
||||
}
|
||||
|
||||
public RedshiftServerlessSnapshot getSnapshot(String snapshotName, String region) {
|
||||
requireSnapshotName(snapshotName);
|
||||
return snapshots.get(storageKey(region, snapshotName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"The snapshot " + snapshotName + " was not found.", 404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recovers the snapshot name from a snapshot ARN, rejecting one that names another account,
|
||||
* Region or resource type rather than resolving it to a local snapshot of the same name.
|
||||
*/
|
||||
public String snapshotNameFromArn(String snapshotArn, String region) {
|
||||
String prefix = regionResolver.buildArn("redshift-serverless", region, "snapshot/");
|
||||
if (snapshotArn == null || !snapshotArn.startsWith(prefix) || snapshotArn.length() == prefix.length()) {
|
||||
throw validation("snapshotArn does not identify a snapshot in this account and Region.");
|
||||
}
|
||||
return snapshotArn.substring(prefix.length());
|
||||
}
|
||||
|
||||
public synchronized RedshiftServerlessSnapshot deleteSnapshot(String snapshotName, String region) {
|
||||
RedshiftServerlessSnapshot deleted = getSnapshot(snapshotName, region);
|
||||
snapshots.delete(storageKey(region, snapshotName));
|
||||
trustedDump(deleted, region).ifPresent(RedshiftServerlessService::deleteDumpQuietly);
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the Region's snapshots, narrowed by every filter that is supplied: the namespace by
|
||||
* name or ARN, the owning account, and a creation-time window that includes both ends.
|
||||
*/
|
||||
public PaginatedResult<RedshiftServerlessSnapshot> listSnapshots(String namespaceName, String namespaceArn,
|
||||
String ownerAccount, Instant startTime,
|
||||
Instant endTime, String region,
|
||||
Integer maxResults, String nextToken) {
|
||||
List<RedshiftServerlessSnapshot> all = snapshots.scan(key -> key.startsWith(region + "::")).stream()
|
||||
.filter(snapshot -> namespaceName == null || namespaceName.isBlank()
|
||||
|| namespaceName.equals(snapshot.getNamespaceName()))
|
||||
.filter(snapshot -> namespaceArn == null || namespaceArn.isBlank()
|
||||
|| namespaceArn.equals(snapshot.getNamespaceArn()))
|
||||
.filter(snapshot -> ownerAccount == null || ownerAccount.isBlank()
|
||||
|| ownerAccount.equals(snapshot.getOwnerAccount()))
|
||||
.filter(snapshot -> startTime == null || !snapshot.getSnapshotCreateTime().isBefore(startTime))
|
||||
.filter(snapshot -> endTime == null || !snapshot.getSnapshotCreateTime().isAfter(endTime))
|
||||
.toList();
|
||||
return Pagination.paginate(all, RedshiftServerlessSnapshot::getSnapshotName, maxResults, nextToken,
|
||||
100, 100, "ValidationException");
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores into the already-existing namespace and workgroup in {@code region} and never
|
||||
* creates either, mirroring real {@code RestoreFromSnapshot}. A snapshot that carries a dump
|
||||
* replaces the workgroup's database contents with it; a metadata-only snapshot leaves the
|
||||
* database untouched and only reports the namespace {@code AVAILABLE}.
|
||||
*/
|
||||
public synchronized RestoreResult restoreFromSnapshot(String namespaceName, String workgroupName,
|
||||
String snapshotName, String ownerAccount,
|
||||
String region) {
|
||||
validateNamespaceName(namespaceName);
|
||||
RedshiftServerlessSnapshot snapshot = getSnapshot(snapshotName, region);
|
||||
if (ownerAccount != null && !ownerAccount.isBlank() && !ownerAccount.equals(snapshot.getOwnerAccount())) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"The snapshot " + snapshotName + " was not found.", 404);
|
||||
}
|
||||
Workgroup workgroup = getWorkgroup(workgroupName, region);
|
||||
if (!namespaceName.equals(workgroup.getNamespaceName())) {
|
||||
throw validation("The workgroup " + workgroupName + " does not belong to the namespace "
|
||||
+ namespaceName + ".");
|
||||
}
|
||||
Namespace namespace = getNamespace(namespaceName, region);
|
||||
if (snapshot.getSqlDump() != null && hasLiveRuntime(workgroup)) {
|
||||
Path dump = trustedDump(snapshot, region).filter(Files::exists).orElseThrow(() -> new AwsException(
|
||||
"InternalServerException", "The data of snapshot " + snapshotName + " is no longer available.",
|
||||
500));
|
||||
runtime.restoreSnapshot(workgroups.accountId(), region, workgroupName, workgroup.getMasterUsername(),
|
||||
namespace.getDbName(), dump);
|
||||
}
|
||||
Namespace restored = new Namespace(namespace);
|
||||
restored.setStatus("AVAILABLE");
|
||||
namespaces.put(storageKey(region, namespaceName), restored);
|
||||
return new RestoreResult(restored, snapshot);
|
||||
}
|
||||
|
||||
public record RestoreResult(Namespace namespace, RedshiftServerlessSnapshot snapshot) {}
|
||||
|
||||
public Map<String, String> listTagsForResource(String resourceArn, String region) {
|
||||
requireResourceArn(resourceArn);
|
||||
Optional<Namespace> namespace = namespaceByArn(resourceArn, region);
|
||||
if (namespace.isPresent()) {
|
||||
return new LinkedHashMap<>(namespace.get().getTags());
|
||||
}
|
||||
return new LinkedHashMap<>(workgroupByArn(resourceArn, region).orElseThrow(
|
||||
Optional<Workgroup> workgroup = workgroupByArn(resourceArn, region);
|
||||
if (workgroup.isPresent()) {
|
||||
return new LinkedHashMap<>(workgroup.get().getTags());
|
||||
}
|
||||
return new LinkedHashMap<>(snapshotByArn(resourceArn, region).orElseThrow(
|
||||
() -> resourceNotFound(resourceArn)).getTags());
|
||||
}
|
||||
|
||||
@@ -353,7 +563,8 @@ public class RedshiftServerlessService implements Resettable {
|
||||
|
||||
public synchronized Map<String, String> untagResource(String resourceArn, List<String> tagKeys, String region) {
|
||||
requireResourceArn(resourceArn);
|
||||
if (namespaceByArn(resourceArn, region).isEmpty() && workgroupByArn(resourceArn, region).isEmpty()) {
|
||||
if (namespaceByArn(resourceArn, region).isEmpty() && workgroupByArn(resourceArn, region).isEmpty()
|
||||
&& snapshotByArn(resourceArn, region).isEmpty()) {
|
||||
throw resourceNotFound(resourceArn);
|
||||
}
|
||||
if (tagKeys == null) {
|
||||
@@ -364,7 +575,7 @@ public class RedshiftServerlessService implements Resettable {
|
||||
|
||||
/**
|
||||
* Redshift Serverless tags whatever the ARN names, so the lookup is by ARN rather than by name.
|
||||
* Namespaces and workgroups are the taggable resources in Floci, so any other Redshift Serverless
|
||||
* Namespaces, workgroups and snapshots are the taggable resources in Floci, so any other Redshift Serverless
|
||||
* ARN resolves to nothing and is reported as absent rather than as an unsupported resource type.
|
||||
* The change is applied to a copy and stored, never to the instance readers may hold.
|
||||
*/
|
||||
@@ -377,13 +588,27 @@ public class RedshiftServerlessService implements Resettable {
|
||||
namespaces.put(storageKey(region, updated.getNamespaceName()), updated);
|
||||
return new LinkedHashMap<>(updated.getTags());
|
||||
}
|
||||
Workgroup workgroup = workgroupByArn(resourceArn, region).orElseThrow(() -> resourceNotFound(resourceArn));
|
||||
Workgroup updated = new Workgroup(workgroup);
|
||||
Optional<Workgroup> workgroup = workgroupByArn(resourceArn, region);
|
||||
if (workgroup.isPresent()) {
|
||||
Workgroup updated = new Workgroup(workgroup.get());
|
||||
change.accept(updated.getTags());
|
||||
workgroups.put(storageKey(region, updated.getWorkgroupName()), updated);
|
||||
return new LinkedHashMap<>(updated.getTags());
|
||||
}
|
||||
RedshiftServerlessSnapshot snapshot = snapshotByArn(resourceArn, region)
|
||||
.orElseThrow(() -> resourceNotFound(resourceArn));
|
||||
RedshiftServerlessSnapshot updated = new RedshiftServerlessSnapshot(snapshot);
|
||||
change.accept(updated.getTags());
|
||||
workgroups.put(storageKey(region, updated.getWorkgroupName()), updated);
|
||||
snapshots.put(storageKey(region, updated.getSnapshotName()), updated);
|
||||
return new LinkedHashMap<>(updated.getTags());
|
||||
}
|
||||
|
||||
private Optional<RedshiftServerlessSnapshot> snapshotByArn(String resourceArn, String region) {
|
||||
return snapshots.scan(key -> key.startsWith(region + "::")).stream()
|
||||
.filter(snapshot -> resourceArn.equals(snapshot.getSnapshotArn()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private Optional<Namespace> namespaceByArn(String resourceArn, String region) {
|
||||
return namespaces.scan(key -> key.startsWith(region + "::")).stream()
|
||||
.filter(namespace -> resourceArn.equals(namespace.getNamespaceArn()))
|
||||
@@ -673,6 +898,27 @@ public class RedshiftServerlessService implements Resettable {
|
||||
}
|
||||
namespaces.clear();
|
||||
workgroups.clear();
|
||||
for (AccountAwareStorageBackend.AccountEntry<RedshiftServerlessSnapshot> entry
|
||||
: snapshots.scanAllAccountEntries(key -> true)) {
|
||||
String dump = entry.value().getSqlDump();
|
||||
if (dump != null && !dump.isBlank()) {
|
||||
deleteDumpQuietly(Paths.get(dump));
|
||||
}
|
||||
}
|
||||
snapshots.clear();
|
||||
}
|
||||
|
||||
private static void requireSnapshotName(String snapshotName) {
|
||||
if (snapshotName == null || snapshotName.isBlank()) {
|
||||
throw validation("snapshotName is required.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateSnapshotName(String snapshotName) {
|
||||
requireSnapshotName(snapshotName);
|
||||
if (snapshotName.length() < 3 || snapshotName.length() > 255 || !SNAPSHOT_NAME.matcher(snapshotName).matches()) {
|
||||
throw validation("snapshotName must be 3-255 characters of lowercase letters, numbers, and hyphens.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateNamespaceName(String namespaceName) {
|
||||
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A Redshift Serverless snapshot. Floci stores snapshot metadata only and does not model async
|
||||
* cross-region copy: a snapshot created via {@code CreateSnapshot} in the standby region is
|
||||
* immediately {@code AVAILABLE} there, standing in for what a real
|
||||
* {@code SnapshotCopyConfiguration} would eventually produce.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RedshiftServerlessSnapshot {
|
||||
|
||||
private String snapshotName;
|
||||
private String snapshotArn;
|
||||
private String namespaceName;
|
||||
private String namespaceArn;
|
||||
private String region;
|
||||
private String accountId;
|
||||
private String ownerAccount;
|
||||
private String status = "AVAILABLE";
|
||||
private Instant snapshotCreateTime;
|
||||
private String adminUsername;
|
||||
private String kmsKeyId;
|
||||
private Integer retentionPeriod;
|
||||
private String sqlDump;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public RedshiftServerlessSnapshot() {
|
||||
}
|
||||
|
||||
public RedshiftServerlessSnapshot(RedshiftServerlessSnapshot other) {
|
||||
this.snapshotName = other.snapshotName;
|
||||
this.snapshotArn = other.snapshotArn;
|
||||
this.namespaceName = other.namespaceName;
|
||||
this.namespaceArn = other.namespaceArn;
|
||||
this.region = other.region;
|
||||
this.accountId = other.accountId;
|
||||
this.ownerAccount = other.ownerAccount;
|
||||
this.status = other.status;
|
||||
this.snapshotCreateTime = other.snapshotCreateTime;
|
||||
this.adminUsername = other.adminUsername;
|
||||
this.kmsKeyId = other.kmsKeyId;
|
||||
this.retentionPeriod = other.retentionPeriod;
|
||||
this.sqlDump = other.sqlDump;
|
||||
this.tags = new LinkedHashMap<>(other.tags);
|
||||
}
|
||||
|
||||
public String getSnapshotName() {
|
||||
return snapshotName;
|
||||
}
|
||||
|
||||
public void setSnapshotName(String snapshotName) {
|
||||
this.snapshotName = snapshotName;
|
||||
}
|
||||
|
||||
public String getSnapshotArn() {
|
||||
return snapshotArn;
|
||||
}
|
||||
|
||||
public void setSnapshotArn(String snapshotArn) {
|
||||
this.snapshotArn = snapshotArn;
|
||||
}
|
||||
|
||||
public String getNamespaceName() {
|
||||
return namespaceName;
|
||||
}
|
||||
|
||||
public void setNamespaceName(String namespaceName) {
|
||||
this.namespaceName = namespaceName;
|
||||
}
|
||||
|
||||
public String getNamespaceArn() {
|
||||
return namespaceArn;
|
||||
}
|
||||
|
||||
public void setNamespaceArn(String namespaceArn) {
|
||||
this.namespaceArn = namespaceArn;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(String accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public String getOwnerAccount() {
|
||||
return ownerAccount;
|
||||
}
|
||||
|
||||
public void setOwnerAccount(String ownerAccount) {
|
||||
this.ownerAccount = ownerAccount;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Instant getSnapshotCreateTime() {
|
||||
return snapshotCreateTime;
|
||||
}
|
||||
|
||||
public void setSnapshotCreateTime(Instant snapshotCreateTime) {
|
||||
this.snapshotCreateTime = snapshotCreateTime;
|
||||
}
|
||||
|
||||
public String getAdminUsername() {
|
||||
return adminUsername;
|
||||
}
|
||||
|
||||
public void setAdminUsername(String adminUsername) {
|
||||
this.adminUsername = adminUsername;
|
||||
}
|
||||
|
||||
public String getKmsKeyId() {
|
||||
return kmsKeyId;
|
||||
}
|
||||
|
||||
public void setKmsKeyId(String kmsKeyId) {
|
||||
this.kmsKeyId = kmsKeyId;
|
||||
}
|
||||
|
||||
/** Days the snapshot is kept, or {@code null} for indefinitely. */
|
||||
public Integer getRetentionPeriod() {
|
||||
return retentionPeriod;
|
||||
}
|
||||
|
||||
public void setRetentionPeriod(Integer retentionPeriod) {
|
||||
this.retentionPeriod = retentionPeriod;
|
||||
}
|
||||
|
||||
/** Path of the pg_dump file, or {@code null} for a metadata-only snapshot. */
|
||||
public String getSqlDump() {
|
||||
return sqlDump;
|
||||
}
|
||||
|
||||
public void setSqlDump(String sqlDump) {
|
||||
this.sqlDump = sqlDump;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags == null ? new LinkedHashMap<>() : new LinkedHashMap<>(tags);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user