From e7f2e70f411145bdd63a4da184197b458c516311 Mon Sep 17 00:00:00 2001 From: Tomoyuki Morita Date: Thu, 5 Sep 2024 10:25:25 -0700 Subject: [PATCH] Throw IllegalArgumentException when cancelJob failed with ValidationException Signed-off-by: Tomoyuki Morita --- .../sql/spark/client/EmrServerlessClientImpl.java | 13 +++++++++---- .../spark/client/EmrServerlessClientImplTest.java | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/async-query-core/src/main/java/org/opensearch/sql/spark/client/EmrServerlessClientImpl.java b/async-query-core/src/main/java/org/opensearch/sql/spark/client/EmrServerlessClientImpl.java index c785067398..707a845c8e 100644 --- a/async-query-core/src/main/java/org/opensearch/sql/spark/client/EmrServerlessClientImpl.java +++ b/async-query-core/src/main/java/org/opensearch/sql/spark/client/EmrServerlessClientImpl.java @@ -116,11 +116,16 @@ public CancelJobRunResult cancelJobRun( } catch (Throwable t) { if (allowExceptionPropagation) { throw t; - } else { - logger.error("Error while making cancel job request to emr:", t); - metricsService.incrementNumericalMetric(EMR_CANCEL_JOB_REQUEST_FAILURE_COUNT); - throw new RuntimeException(GENERIC_INTERNAL_SERVER_ERROR_MESSAGE); } + + logger.error("Error while making cancel job request to emr:", t); + metricsService.incrementNumericalMetric(EMR_CANCEL_JOB_REQUEST_FAILURE_COUNT); + if (t instanceof ValidationException) { + throw new IllegalArgumentException( + "The input fails to satisfy the constraints specified by AWS EMR" + + " Serverless."); + } + throw new RuntimeException(GENERIC_INTERNAL_SERVER_ERROR_MESSAGE); } }); logger.info(String.format("Job : %s cancelled", cancelJobRunResult.getJobRunId())); diff --git a/async-query-core/src/test/java/org/opensearch/sql/spark/client/EmrServerlessClientImplTest.java b/async-query-core/src/test/java/org/opensearch/sql/spark/client/EmrServerlessClientImplTest.java index 42d703f9ac..b3a2bda36a 100644 --- a/async-query-core/src/test/java/org/opensearch/sql/spark/client/EmrServerlessClientImplTest.java +++ b/async-query-core/src/test/java/org/opensearch/sql/spark/client/EmrServerlessClientImplTest.java @@ -172,10 +172,12 @@ void testCancelJobRunWithValidationException() { RuntimeException runtimeException = Assertions.assertThrows( - RuntimeException.class, + IllegalArgumentException.class, () -> emrServerlessClient.cancelJobRun(EMRS_APPLICATION_ID, EMR_JOB_ID, false)); - Assertions.assertEquals("Internal Server Error.", runtimeException.getMessage()); + Assertions.assertEquals( + "The input fails to satisfy the constraints specified by AWS EMR Serverless.", + runtimeException.getMessage()); } @Test