mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
refactor(redshift): align Redshift code with AGENTS.md style rules (#3992)
* refactor(redshift): align main sources with AGENTS.md style rules Import Matcher instead of qualifying it inline, replace a var with its explicit type, and order the RedshiftService imports (java.* last). Remove em-dashes from comments and a log message. Two swallowed IOExceptions now log with context (snapshot dump deletion and exec output capture), and the remaining intentionally ignored one says why it is safe. * refactor(redshift): replace var and inline qualified names in tests Use explicit types instead of var and import the classes that were written fully qualified inline, as AGENTS.md requires. * refactor(redshift): drop the test prefix from test method names AGENTS.md prefers camelCase sentences over testX names, which are common in older tests but not the pattern to copy. Rename the 99 remaining testX methods in the Redshift tests. No assertions changed. * refactor(redshift): remove remaining em-dashes from test comments * refactor(redshift): log warning when temp dump cleanup fails on aborted reboot
This commit is contained in:
1 parent
fc81cdedd9
commit
5f1f80b496
14 files changed
+177
-165
No files matched your search
+2
-1
@@ -26,6 +26,7 @@ import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
@@ -1090,7 +1091,7 @@ public class RedshiftQueryHandler {
|
||||
private static List<RedshiftService.IntegrationFilter> integrationFilters(MultivaluedMap<String, String> params) {
|
||||
Map<String, RedshiftService.IntegrationFilter> byIndex = new LinkedHashMap<>();
|
||||
for (String key : params.keySet()) {
|
||||
java.util.regex.Matcher matcher = FILTER_NAME.matcher(key);
|
||||
Matcher matcher = FILTER_NAME.matcher(key);
|
||||
if (!matcher.matches()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.redshift;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
@@ -14,15 +15,11 @@ import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamService;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.PasswordValidator;
|
||||
import io.github.hectorvent.floci.services.redshift.container.RedshiftContainerHandle;
|
||||
import io.github.hectorvent.floci.services.redshift.container.RedshiftContainerManager;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Integration;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Cluster;
|
||||
import io.github.hectorvent.floci.services.redshift.model.ClusterParameterGroup;
|
||||
import io.github.hectorvent.floci.services.redshift.model.ClusterSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Integration;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Parameter;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Snapshot;
|
||||
import io.github.hectorvent.floci.services.redshift.model.SnapshotCopyGrant;
|
||||
@@ -30,28 +27,31 @@ import io.github.hectorvent.floci.services.redshift.proxy.RedshiftProxyManager;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.RandomPasswordGenerator;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.event.Observes;
|
||||
import jakarta.inject.Inject;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
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.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class RedshiftService {
|
||||
@@ -637,7 +637,7 @@ public class RedshiftService {
|
||||
.orElseThrow(() -> new AwsException("ClusterNotFound", "Cluster " + clusterIdentifier + " not found", 404));
|
||||
|
||||
// alterUserPassword runs before any mutation of the cluster object (a live reference
|
||||
// from HybridStorage, not a copy) — if it throws, no metadata has been changed yet.
|
||||
// from HybridStorage, not a copy); if it throws, no metadata has been changed yet.
|
||||
if (masterUserPassword != null && !masterUserPassword.isBlank()) {
|
||||
containerManager.alterUserPassword(clusters.accountId(), clusterIdentifier,
|
||||
cluster.getMasterUsername(), masterUserPassword);
|
||||
@@ -648,9 +648,9 @@ public class RedshiftService {
|
||||
updateManagedMasterSecret(cluster, masterUserPassword);
|
||||
}
|
||||
|
||||
// NodeType only updates metadata — it does not resize the underlying Postgres container
|
||||
// NodeType only updates metadata: it does not resize the underlying Postgres container
|
||||
// (Redshift node-count has no equivalent here). NumberOfNodes is accepted for API-shape
|
||||
// compatibility but is not modelled or stored anywhere — known gap, see plan Task 9.
|
||||
// compatibility but is not modelled or stored anywhere: known gap, see plan Task 9.
|
||||
if (nodeType != null && !nodeType.isBlank()) {
|
||||
cluster.setNodeType(nodeType);
|
||||
}
|
||||
@@ -767,7 +767,7 @@ public class RedshiftService {
|
||||
|
||||
// The container backing a cluster has no persistent volume (see RedshiftContainerManager),
|
||||
// so a plain stop+recreate would silently drop the cluster's data. Dump before stopping and
|
||||
// restore immediately after starting, using a throwaway temp file — no Snapshot resource is
|
||||
// restore immediately after starting, using a throwaway temp file, so no Snapshot resource is
|
||||
// created or exposed to the caller.
|
||||
Path tempDump;
|
||||
try {
|
||||
@@ -835,13 +835,14 @@ public class RedshiftService {
|
||||
} else {
|
||||
if (originalTornDown) {
|
||||
// Once the original container is torn down it holds no volume, so this dump can
|
||||
// be the only surviving copy of the cluster's data — keep it for manual recovery.
|
||||
// be the only surviving copy of the cluster's data, so keep it for manual recovery.
|
||||
LOG.warnv("Reboot of cluster {0} did not complete; retained pre-reboot data dump at {1}",
|
||||
clusterIdentifier, tempDump);
|
||||
} else {
|
||||
try {
|
||||
Files.deleteIfExists(tempDump);
|
||||
} catch (IOException ignored) {
|
||||
} catch (IOException ex) {
|
||||
LOG.warnv(ex, "Failed to clean up temporary dump file {0} after aborted reboot of cluster {1}", tempDump, clusterIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -972,7 +973,7 @@ public class RedshiftService {
|
||||
try {
|
||||
Files.deleteIfExists(Paths.get(snapshot.getSqlDump()));
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
LOG.warnv(e, "Could not delete the dump file of snapshot {0}", snapshotIdentifier);
|
||||
}
|
||||
}
|
||||
snapshot.setStatus("deleted");
|
||||
@@ -1411,7 +1412,7 @@ public class RedshiftService {
|
||||
* where {@code <type>} is one of {@code cluster}, {@code snapshot} (id shape
|
||||
* {@code <clusterId>/<snapshotId>}), {@code parametergroup}, {@code subnetgroup} or
|
||||
* {@code snapshotcopygrant}. Unlike RDS's tag
|
||||
* resolution, there is no bare-name fallback — Redshift tagging is new, so there is no
|
||||
* resolution, there is no bare-name fallback: Redshift tagging is new, so there is no
|
||||
* existing caller to stay backward compatible with.
|
||||
*/
|
||||
private TagHandle resolveTagHandle(String resourceName) {
|
||||
@@ -1533,7 +1534,7 @@ public class RedshiftService {
|
||||
* the original proxy + container were stopped, so the original data-bearing container
|
||||
* is still running and nothing must be touched. Once it is true the original is gone:
|
||||
* tear down the (replacement's) proxy and return its port, and remove any container
|
||||
* running under the cluster's name — {@code containerManager.stop} works by name, so
|
||||
* running under the cluster's name: {@code containerManager.stop} works by name, so
|
||||
* this also cleans a replacement that {@code containerManager.start} created before
|
||||
* throwing (e.g. its readiness check timed out). The pre-reboot data dump is kept by
|
||||
* the caller.
|
||||
|
||||
+9
-6
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.redshift.container;
|
||||
|
||||
import com.github.dockerjava.api.async.ResultCallback;
|
||||
import com.github.dockerjava.api.model.Container;
|
||||
import com.github.dockerjava.api.model.Frame;
|
||||
import com.github.dockerjava.api.model.StreamType;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
@@ -98,14 +99,14 @@ public class RedshiftContainerManager {
|
||||
* persistent volume, so a blind recreate would silently discard the cluster's data;
|
||||
* adopting preserves it whenever the physical container survived. If no such container
|
||||
* exists (first start, or the container itself was removed), this falls back to
|
||||
* {@link #start} — in that case the previous data is unrecoverable, matching this
|
||||
* {@link #start}, and in that case the previous data is unrecoverable, matching this
|
||||
* project's decision not to back Redshift containers with a Docker volume.
|
||||
*/
|
||||
public RedshiftContainerHandle adoptOrStart(String accountId, String clusterIdentifier, String masterUsername, String masterPassword) {
|
||||
String containerName = containerName(accountId, clusterIdentifier);
|
||||
var existing = lifecycleManager.findByName(containerName);
|
||||
Optional<Container> existing = lifecycleManager.findByName(containerName);
|
||||
if (existing.isEmpty()) {
|
||||
LOG.warnv("No surviving container for cluster {0}; starting a fresh empty one — the previous"
|
||||
LOG.warnv("No surviving container for cluster {0}; starting a fresh empty one: the previous"
|
||||
+ " contents are not recoverable (no Docker volume backs Redshift containers)", clusterIdentifier);
|
||||
return start(accountId, clusterIdentifier, masterUsername, masterPassword);
|
||||
}
|
||||
@@ -212,10 +213,10 @@ public class RedshiftContainerManager {
|
||||
throw new AwsException("InvalidParameterValue", "Username must be a valid SQL identifier", 400);
|
||||
}
|
||||
// AWS ModifyCluster rejects ', ", \, / and @ in MasterUserPassword and enforces an
|
||||
// 8-64 length plus at least one uppercase, one lowercase and one digit — we enforce
|
||||
// 8-64 length plus at least one uppercase, one lowercase and one digit, and we enforce
|
||||
// the same set for parity. The single-quote rejection is doubly load-bearing: the
|
||||
// password is spliced into a psql -c SQL literal here, so ' would also break that
|
||||
// literal — but it is AWS-correct regardless, so do not "fix" it away by escaping.
|
||||
// literal, but it is AWS-correct regardless, so do not "fix" it away by escaping.
|
||||
if (newPassword != null) {
|
||||
for (char forbidden : new char[]{'\'', '"', '\\', '/', '@'}) {
|
||||
if (newPassword.indexOf(forbidden) >= 0) {
|
||||
@@ -334,7 +335,8 @@ public class RedshiftContainerManager {
|
||||
} else {
|
||||
out.write(payload);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
} catch (IOException e) {
|
||||
LOG.warnv(e, "Failed to capture output of container exec {0}", execId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,6 +366,7 @@ public class RedshiftContainerManager {
|
||||
try {
|
||||
callback.close();
|
||||
} catch (IOException ignored) {
|
||||
// The exec result is already collected, so a failure to release the callback stream cannot change it.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user