mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
refactor(rds,docdb,neptune): extract shared DescribeGlobalClusters into RdsFamilyQuerySupport (#3648)
DocDbQueryHandler, NeptuneQueryHandler, and RdsQueryHandler each carried their own byte-for-byte identical handleDescribeGlobalClusters: global clusters aren't modeled by any of the three, so all three validate MaxRecords/GlobalClusterIdentifier/Marker the same way and always answer with an empty GlobalClusters list, since DocumentDB and Neptune both accept the RDS-family wire protocol and claim compatibility for this operation. Extracted into a new RdsFamilyQuerySupport under core.common (a static utility, not a CDI-injected sibling handler like RdsQueryHandler's existing DocDbQueryHandler/ NeptuneQueryHandler dependencies: those exist for real cross-service data composition, this operation has no state to share, just identical logic). Each handler's own handleDescribeGlobalClusters is now a one-line delegation, keeping its own LOG so log lines still attribute to the right service. Scope note: CPD also flagged the two other pairwise overlaps this issue names (33-line DocDb/RDS, 26-line Neptune/RDS), but those turned out to be the same handleDescribeGlobalClusters match window overlapping into neighboring methods, not a separate duplicate; this extraction covers them too. A much larger set of CPD matches between DocDbQueryHandler and NeptuneQueryHandler (cluster/instance CRUD, tag parsing, XML builders, effectively most of both handlers) is a separate, pre-existing architectural duplication between those two services well beyond what this issue asks for, and is not touched here. No behavior change. Full docdb, neptune, and rds test suites pass unchanged (one NeptuneOpenCypherIntegrationTest Bolt-protocol timeout is a pre-existing environmental flake, confirmed by reproducing it identically against unmodified main).
This commit is contained in:
1 parent
04a6ad6cbb
commit
de27308bd9
4 files changed
+61
-89
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Query-protocol operations that RDS, DocumentDB, and Neptune answer identically, since
|
||||
* DocumentDB and Neptune both accept the RDS-family wire protocol and claim compatibility for
|
||||
* these operations. Real SDKs sign DocumentDB and Neptune requests with the "rds" scope and can
|
||||
* land on any of the three handlers, so a correction here reaches all of them at once.
|
||||
*/
|
||||
public final class RdsFamilyQuerySupport {
|
||||
|
||||
private RdsFamilyQuerySupport() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers DescribeGlobalClusters the same way for all three services: global clusters are
|
||||
* not modeled, so the response is always an empty list, once MaxRecords,
|
||||
* GlobalClusterIdentifier, and Marker have been validated the way a live account would.
|
||||
*
|
||||
* <p>MaxRecords is rejected before the identifier is looked up, and a marker after it, the
|
||||
* order a live account applies them in. Naming a specific identifier is a different question
|
||||
* from listing none, and AWS errors on it. Filters are accepted without validation, since the
|
||||
* answer is empty for every name AWS accepts, and a partial list of accepted names would
|
||||
* reject filters a live account allows.
|
||||
*/
|
||||
public static Response handleDescribeGlobalClusters(Logger log, MultivaluedMap<String, String> params) {
|
||||
String maxRecords = params.getFirst("MaxRecords");
|
||||
if (maxRecords != null && !maxRecords.isBlank()) {
|
||||
int max = -1;
|
||||
try {
|
||||
max = Integer.parseInt(maxRecords.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
log.debugv("Non-numeric MaxRecords {0} on DescribeGlobalClusters", maxRecords);
|
||||
}
|
||||
if (max < 20 || max > 100) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid value " + maxRecords + " for MaxRecords. Must be between 20 and 100", 400);
|
||||
}
|
||||
}
|
||||
String identifier = params.getFirst("GlobalClusterIdentifier");
|
||||
if (identifier != null && !identifier.isBlank()) {
|
||||
throw new AwsException("GlobalClusterNotFoundFault",
|
||||
"Global cluster '" + identifier + "' not found", 404);
|
||||
}
|
||||
String marker = params.getFirst("Marker");
|
||||
if (marker != null && !marker.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "The request token is invalid.", 400);
|
||||
}
|
||||
String xml = new XmlBuilder().start("GlobalClusters").end("GlobalClusters").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeGlobalClusters", AwsNamespaces.RDS, xml)).build();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.RdsFamilyQuerySupport;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.services.docdb.model.DocDbCluster;
|
||||
@@ -124,39 +125,7 @@ public class DocDbQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleDescribeGlobalClusters(MultivaluedMap<String, String> params) {
|
||||
// Global clusters are not modeled; an empty list is what completes the provider's read.
|
||||
// Real SDKs sign DocumentDB with the "rds" scope and land on RdsQueryHandler instead;
|
||||
// this serves the "docdb" scope Floci also accepts, and must answer the same way.
|
||||
// MaxRecords is rejected before the identifier is looked up, and a marker after it —
|
||||
// the order a live account applies them in.
|
||||
String maxRecords = params.getFirst("MaxRecords");
|
||||
if (maxRecords != null && !maxRecords.isBlank()) {
|
||||
int max = -1;
|
||||
try {
|
||||
max = Integer.parseInt(maxRecords.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.debugv("Non-numeric MaxRecords {0} on DescribeGlobalClusters", maxRecords);
|
||||
}
|
||||
if (max < 20 || max > 100) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid value " + maxRecords + " for MaxRecords. Must be between 20 and 100", 400);
|
||||
}
|
||||
}
|
||||
String identifier = params.getFirst("GlobalClusterIdentifier");
|
||||
if (identifier != null && !identifier.isBlank()) {
|
||||
// Naming one is a different question from listing none, and AWS errors on it.
|
||||
throw new AwsException("GlobalClusterNotFoundFault",
|
||||
"Global cluster '" + identifier + "' not found", 404);
|
||||
}
|
||||
// No page is ever handed out, so any marker a caller presents came from somewhere else.
|
||||
String marker = params.getFirst("Marker");
|
||||
if (marker != null && !marker.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "The request token is invalid.", 400);
|
||||
}
|
||||
// Filters are not validated: the answer is empty for every name AWS accepts, and a partial
|
||||
// list of accepted names would reject filters a live account allows.
|
||||
XmlBuilder xml = new XmlBuilder().start("GlobalClusters").end("GlobalClusters");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeGlobalClusters", AwsNamespaces.RDS, xml.build())).build();
|
||||
return RdsFamilyQuerySupport.handleDescribeGlobalClusters(LOG, params);
|
||||
}
|
||||
|
||||
private Response handleDescribeDbClusterSnapshots(MultivaluedMap<String, String> params) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.core.common.RdsFamilyQuerySupport;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneCluster;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneClusterSettings;
|
||||
@@ -188,30 +189,7 @@ public class NeptuneQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleDescribeGlobalClusters(MultivaluedMap<String, String> params) {
|
||||
String maxRecords = params.getFirst("MaxRecords");
|
||||
if (maxRecords != null && !maxRecords.isBlank()) {
|
||||
int max = -1;
|
||||
try {
|
||||
max = Integer.parseInt(maxRecords.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.debugv("Non-numeric MaxRecords {0} on DescribeGlobalClusters", maxRecords);
|
||||
}
|
||||
if (max < 20 || max > 100) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid value " + maxRecords + " for MaxRecords. Must be between 20 and 100", 400);
|
||||
}
|
||||
}
|
||||
String identifier = params.getFirst("GlobalClusterIdentifier");
|
||||
if (identifier != null && !identifier.isBlank()) {
|
||||
throw new AwsException("GlobalClusterNotFoundFault",
|
||||
"Global cluster '" + identifier + "' not found", 404);
|
||||
}
|
||||
String marker = params.getFirst("Marker");
|
||||
if (marker != null && !marker.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "The request token is invalid.", 400);
|
||||
}
|
||||
XmlBuilder xml = new XmlBuilder().start("GlobalClusters").end("GlobalClusters");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeGlobalClusters", AwsNamespaces.RDS, xml.build())).build();
|
||||
return RdsFamilyQuerySupport.handleDescribeGlobalClusters(LOG, params);
|
||||
}
|
||||
|
||||
// ── Instances ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.RdsFamilyQuerySupport;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.services.rds.model.DatabaseEngine;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbCluster;
|
||||
@@ -1411,38 +1412,7 @@ public class RdsQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleDescribeGlobalClusters(MultivaluedMap<String, String> params) {
|
||||
// Global clusters are not modeled. Both providers read this on every cluster read, and
|
||||
// DocumentDB signs with the "rds" scope, so this handler answers for either service.
|
||||
// MaxRecords is rejected before the identifier is looked up, and a marker after it —
|
||||
// the order a live account applies them in.
|
||||
String maxRecords = params.getFirst("MaxRecords");
|
||||
if (maxRecords != null && !maxRecords.isBlank()) {
|
||||
int max = -1;
|
||||
try {
|
||||
max = Integer.parseInt(maxRecords.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.debugv("Non-numeric MaxRecords {0} on DescribeGlobalClusters", maxRecords);
|
||||
}
|
||||
if (max < 20 || max > 100) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid value " + maxRecords + " for MaxRecords. Must be between 20 and 100", 400);
|
||||
}
|
||||
}
|
||||
String identifier = params.getFirst("GlobalClusterIdentifier");
|
||||
if (identifier != null && !identifier.isBlank()) {
|
||||
// Naming one is a different question from listing none, and AWS errors on it.
|
||||
throw new AwsException("GlobalClusterNotFoundFault",
|
||||
"Global cluster '" + identifier + "' not found", 404);
|
||||
}
|
||||
// No page is ever handed out, so any marker a caller presents came from somewhere else.
|
||||
String marker = params.getFirst("Marker");
|
||||
if (marker != null && !marker.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "The request token is invalid.", 400);
|
||||
}
|
||||
// Filters are not validated: the answer is empty for every name AWS accepts, and a partial
|
||||
// list of accepted names would reject filters a live account allows.
|
||||
String result = new XmlBuilder().start("GlobalClusters").end("GlobalClusters").build();
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeGlobalClusters", AwsNamespaces.RDS, result)).build();
|
||||
return RdsFamilyQuerySupport.handleDescribeGlobalClusters(LOG, params);
|
||||
}
|
||||
|
||||
private Response handleDescribeDbClusterSnapshots(MultivaluedMap<String, String> params) {
|
||||
|
||||
Reference in new issue
Block a user