From 39aa20b68b548bd19342b2b2ed3e0ae9bb3f1262 Mon Sep 17 00:00:00 2001 From: Jimmy Liu Jia <91264074+JimmyLiuJia@users.noreply.github.com> Date: Fri, 4 Dec 2026 05:55:44 +0800 Subject: [PATCH] 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. --- .../aws/services/glue/GlueJsonHandler.java | 32 ++++++------ .../services/glue/GlueJsonHandlerTest.java | 49 ++++++++++++++----- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/floci/aws/services/glue/GlueJsonHandler.java b/src/main/java/io/floci/aws/services/glue/GlueJsonHandler.java index b825ca0ee0..6773b4df07 100644 --- a/src/main/java/io/floci/aws/services/glue/GlueJsonHandler.java +++ b/src/main/java/io/floci/aws/services/glue/GlueJsonHandler.java @@ -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 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) { diff --git a/src/test/java/io/floci/aws/services/glue/GlueJsonHandlerTest.java b/src/test/java/io/floci/aws/services/glue/GlueJsonHandlerTest.java index f86c5442b1..67738ec702 100644 --- a/src/test/java/io/floci/aws/services/glue/GlueJsonHandlerTest.java +++ b/src/test/java/io/floci/aws/services/glue/GlueJsonHandlerTest.java @@ -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 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()); } }