Skip to content

Commit

Permalink
Throw IllegalArgumentException when cancelJob failed with ValidationE…
Browse files Browse the repository at this point in the history
…xception (#2986) (#3006)

(cherry picked from commit c22929b)

Signed-off-by: Tomoyuki Morita <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 3146b2f commit 9915e73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: jobId=" + jobId, 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9915e73

Please sign in to comment.