mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 18:48:00 -05:00
refactor(glue): reuse catalog refusal in connection batches (#10092)
BatchDeleteConnection and the ordinary Glue actions now share one nonDefaultCatalogRefusal decision. The batch still answers a refusal for each connection name and leaves connections in the default catalog intact, which a new handler test covers for an existing non-default catalog; the batch refusal checks share one test helper.
This commit is contained in:
1 parent
053e2aa76b
commit
39aa20b68b
2 files changed
+55
-26
No files matched your search
@@ -507,17 +507,7 @@ public class GlueJsonHandler {
|
||||
: null;
|
||||
String catalogId = JsonNodes.asText(request.path("CatalogId"), null);
|
||||
glueService.validateBatchDeleteConnectionNames(names);
|
||||
AwsException refusal = null;
|
||||
try {
|
||||
if (!isDefaultOrExistingCatalog("BatchDeleteConnection", catalogId, region)) {
|
||||
refusal = catalogRefusal("BatchDeleteConnection", catalogId, false);
|
||||
}
|
||||
} catch (AwsException e) {
|
||||
if (!"EntityNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
refusal = e;
|
||||
}
|
||||
AwsException refusal = nonDefaultCatalogRefusal("BatchDeleteConnection", catalogId, region);
|
||||
if (refusal != null) {
|
||||
Map<String, GlueService.ErrorDetail> errors = new LinkedHashMap<>();
|
||||
for (String name : names) {
|
||||
@@ -754,10 +744,24 @@ public class GlueJsonHandler {
|
||||
return;
|
||||
}
|
||||
String catalogId = JsonNodes.asText(request.path("CatalogId"), null);
|
||||
if (isDefaultOrExistingCatalog(action, catalogId, region)) {
|
||||
return;
|
||||
AwsException refusal = nonDefaultCatalogRefusal(action, catalogId, region);
|
||||
if (refusal != null) {
|
||||
throw refusal;
|
||||
}
|
||||
}
|
||||
|
||||
private AwsException nonDefaultCatalogRefusal(String action, String catalogId, String region) {
|
||||
try {
|
||||
if (isDefaultOrExistingCatalog(action, catalogId, region)) {
|
||||
return null;
|
||||
}
|
||||
return catalogRefusal(action, catalogId, false);
|
||||
} catch (AwsException e) {
|
||||
if (!"EntityNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
throw catalogRefusal(action, catalogId, false);
|
||||
}
|
||||
|
||||
private boolean isDefaultOrExistingCatalog(String action, String catalogId, String region) {
|
||||
|
||||
@@ -886,18 +886,43 @@ class GlueJsonHandlerTest {
|
||||
assertEquals(expected, error.getMessage());
|
||||
}
|
||||
|
||||
ObjectNode batch = mapper.createObjectNode();
|
||||
batch.put("CatalogId", catalogId);
|
||||
batch.putArray("ConnectionNameList").add("first").add("second");
|
||||
Response batchResponse = handler.handle("BatchDeleteConnection", batch, REGION);
|
||||
assertEquals(200, batchResponse.getStatus());
|
||||
JsonNode result = mapper.valueToTree(batchResponse.getEntity());
|
||||
assertEquals(0, result.get("Succeeded").size());
|
||||
for (String name : List.of("first", "second")) {
|
||||
JsonNode error = result.get("Errors").get(name);
|
||||
assertEquals("EntityNotFoundException", error.get("ErrorCode").asString());
|
||||
assertEquals(expected, error.get("ErrorMessage").asString());
|
||||
}
|
||||
assertBatchDeleteConnectionRefusal(mapper.createObjectNode().put("CatalogId", catalogId),
|
||||
"EntityNotFoundException", expected, List.of("first", "second"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void existingNonDefaultCatalogBatchDeleteKeepsDefaultConnections() throws Exception {
|
||||
ObjectNode catalog = mapper.createObjectNode().put("Name", "other");
|
||||
catalog.putObject("CatalogInput");
|
||||
handler.handle("CreateCatalog", catalog, REGION);
|
||||
|
||||
ObjectNode connection = mapper.createObjectNode();
|
||||
connection.set("ConnectionInput", connectionInput("orders"));
|
||||
handler.handle("CreateConnection", connection, REGION);
|
||||
|
||||
assertBatchDeleteConnectionRefusal(mapper.createObjectNode().put("CatalogId", "other"),
|
||||
"InvalidInputException", "Glue BatchDeleteConnection does not support catalog other",
|
||||
List.of("orders", "missing"));
|
||||
assertEquals("orders", mapper.valueToTree(handler.handle("GetConnection",
|
||||
mapper.createObjectNode().put("Name", "orders"), REGION).getEntity())
|
||||
.get("Connection").get("Name").asString());
|
||||
}
|
||||
|
||||
private void assertBatchDeleteConnectionRefusal(ObjectNode request, String expectedCode, String expectedMessage,
|
||||
List<String> names) throws Exception {
|
||||
ArrayNode connectionNames = request.putArray("ConnectionNameList");
|
||||
for (String name : names) {
|
||||
connectionNames.add(name);
|
||||
}
|
||||
Response response = handler.handle("BatchDeleteConnection", request, REGION);
|
||||
assertEquals(200, response.getStatus());
|
||||
JsonNode result = mapper.valueToTree(response.getEntity());
|
||||
assertEquals(0, result.get("Succeeded").size());
|
||||
for (String name : names) {
|
||||
JsonNode error = result.get("Errors").get(name);
|
||||
assertEquals(expectedCode, error.get("ErrorCode").asString());
|
||||
assertEquals(expectedMessage, error.get("ErrorMessage").asString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user