Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.13] Handle EMRS exception as 400 #2628

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.amazonaws.services.emrserverless.model.SparkSubmit;
import com.amazonaws.services.emrserverless.model.StartJobRunRequest;
import com.amazonaws.services.emrserverless.model.StartJobRunResult;
import com.amazonaws.services.emrserverless.model.ValidationException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -69,6 +70,11 @@ public String startJobRun(StartJobRequest startJobRequest) {
logger.error("Error while making start job request to emr:", t);
MetricUtils.incrementNumericalMetric(
MetricName.EMR_START_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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.opensearch.sql.spark.constants.TestConstants.SPARK_SUBMIT_PARAMETERS;

import com.amazonaws.services.emrserverless.AWSEMRServerless;
import com.amazonaws.services.emrserverless.model.AWSEMRServerlessException;
import com.amazonaws.services.emrserverless.model.CancelJobRunResult;
import com.amazonaws.services.emrserverless.model.GetJobRunResult;
import com.amazonaws.services.emrserverless.model.JobRun;
Expand Down Expand Up @@ -97,7 +98,9 @@ void testStartJobRun() {

@Test
void testStartJobRunWithErrorMetric() {
doThrow(new ValidationException("Couldn't start job")).when(emrServerless).startJobRun(any());
doThrow(new AWSEMRServerlessException("Couldn't start job"))
.when(emrServerless)
.startJobRun(any());
EmrServerlessClientImpl emrServerlessClient = new EmrServerlessClientImpl(emrServerless);
RuntimeException runtimeException =
Assertions.assertThrows(
Expand Down Expand Up @@ -224,4 +227,33 @@ void testStartJobRunWithLongJobName() {
StartJobRunRequest startJobRunRequest = startJobRunRequestArgumentCaptor.getValue();
Assertions.assertEquals(255, startJobRunRequest.getName().length());
}

@Test
void testStartJobRunThrowsValidationException() {
when(emrServerless.startJobRun(any())).thenThrow(new ValidationException("Unmatched quote"));
EmrServerlessClientImpl emrServerlessClient = new EmrServerlessClientImpl(emrServerless);

IllegalArgumentException exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
emrServerlessClient.startJobRun(
new StartJobRequest(
EMRS_JOB_NAME,
EMRS_APPLICATION_ID,
EMRS_EXECUTION_ROLE,
SPARK_SUBMIT_PARAMETERS,
new HashMap<>(),
false,
DEFAULT_RESULT_INDEX)),
"Expected ValidationException to be thrown");

// Verify that the message in the exception is correct
Assertions.assertEquals(
"The input fails to satisfy the constraints specified by AWS EMR Serverless.",
exception.getMessage());

// Optionally verify that no job run is started
verify(emrServerless, times(1)).startJobRun(any());
}
}
Loading