-
Notifications
You must be signed in to change notification settings - Fork 933
[#12990] fix(catalog-glue): Include the AWS error detail in Glue failure messages #12991
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
Merged
+211
−2
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...alog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueExceptionConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.gravitino.catalog.glue; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import org.apache.gravitino.exceptions.NoSuchSchemaException; | ||
| import org.apache.gravitino.exceptions.NoSuchTableException; | ||
| import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; | ||
| import org.apache.gravitino.exceptions.TableAlreadyExistsException; | ||
| import org.junit.jupiter.api.Test; | ||
| import software.amazon.awssdk.awscore.exception.AwsErrorDetails; | ||
| import software.amazon.awssdk.services.glue.model.AccessDeniedException; | ||
| import software.amazon.awssdk.services.glue.model.AlreadyExistsException; | ||
| import software.amazon.awssdk.services.glue.model.EntityNotFoundException; | ||
| import software.amazon.awssdk.services.glue.model.GlueException; | ||
| import software.amazon.awssdk.services.glue.model.InvalidInputException; | ||
|
|
||
| /** Tests for {@link GlueExceptionConverter}. */ | ||
| public class TestGlueExceptionConverter { | ||
|
|
||
| private static final String IAM_MESSAGE = | ||
| "User: arn:aws:iam::123456789012:user/gravitino is not authorized to perform: " | ||
| + "glue:CreateDatabase on resource: " | ||
| + "arn:aws:glue:us-east-2:123456789012:database/drop_me3 " | ||
| + "because no identity-based policy allows the glue:CreateDatabase action"; | ||
|
|
||
| @Test | ||
| public void testSchemaAccessDeniedKeepsAwsMessage() { | ||
| AccessDeniedException e = | ||
| AccessDeniedException.builder() | ||
| .message(IAM_MESSAGE) | ||
| .awsErrorDetails( | ||
| AwsErrorDetails.builder() | ||
| .errorCode("AccessDeniedException") | ||
| .errorMessage(IAM_MESSAGE) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| RuntimeException converted = GlueExceptionConverter.toSchemaException(e, "schema drop_me"); | ||
|
|
||
| assertEquals(RuntimeException.class, converted.getClass()); | ||
| assertSame(e, converted.getCause()); | ||
| String message = converted.getMessage(); | ||
| assertTrue(message.contains("schema drop_me"), message); | ||
| assertTrue(message.contains("AccessDeniedException"), message); | ||
| assertTrue(message.contains("glue:CreateDatabase"), message); | ||
| assertTrue(message.contains("database/drop_me3"), message); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTableAccessDeniedKeepsAwsMessage() { | ||
| AccessDeniedException e = | ||
| AccessDeniedException.builder() | ||
| .message(IAM_MESSAGE) | ||
| .awsErrorDetails( | ||
| AwsErrorDetails.builder() | ||
| .errorCode("AccessDeniedException") | ||
| .errorMessage(IAM_MESSAGE) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| RuntimeException converted = GlueExceptionConverter.toTableException(e, "table ctas_test"); | ||
|
|
||
| assertEquals(RuntimeException.class, converted.getClass()); | ||
| assertSame(e, converted.getCause()); | ||
| String message = converted.getMessage(); | ||
| assertTrue(message.contains("table ctas_test"), message); | ||
| assertTrue(message.contains("AccessDeniedException"), message); | ||
| assertTrue(message.contains("glue:CreateDatabase"), message); | ||
| } | ||
|
|
||
| @Test | ||
| public void testErrorCodeAloneIsSurfaced() { | ||
| GlueException e = | ||
| (GlueException) | ||
| GlueException.builder() | ||
| .awsErrorDetails( | ||
| AwsErrorDetails.builder().errorCode("InternalServiceException").build()) | ||
| .build(); | ||
|
|
||
| RuntimeException converted = GlueExceptionConverter.toSchemaException(e, "schema db6a"); | ||
|
|
||
| assertTrue(converted.getMessage().contains("InternalServiceException"), converted.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFallsBackToExceptionMessageWithoutAwsErrorDetails() { | ||
| GlueException e = (GlueException) GlueException.builder().message("connection reset").build(); | ||
|
|
||
| RuntimeException converted = GlueExceptionConverter.toSchemaException(e, "schema db6a"); | ||
|
|
||
| assertTrue(converted.getMessage().contains("schema db6a"), converted.getMessage()); | ||
| assertTrue(converted.getMessage().contains("connection reset"), converted.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFallsBackWhenAwsErrorDetailsAreBlank() { | ||
| GlueException e = | ||
| (GlueException) | ||
| GlueException.builder() | ||
| .message("connection reset") | ||
| .awsErrorDetails(AwsErrorDetails.builder().errorCode("").errorMessage("").build()) | ||
| .build(); | ||
|
|
||
| RuntimeException converted = GlueExceptionConverter.toSchemaException(e, "schema db6a"); | ||
|
|
||
| assertTrue(converted.getMessage().contains("connection reset"), converted.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFallsBackToExceptionTypeWithoutAnyMessage() { | ||
| GlueException e = (GlueException) GlueException.builder().build(); | ||
|
|
||
| RuntimeException converted = GlueExceptionConverter.toSchemaException(e, "schema db6a"); | ||
|
|
||
| assertTrue(converted.getMessage().contains("GlueException"), converted.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRecognisedExceptionsKeepTheirMapping() { | ||
| EntityNotFoundException notFound = EntityNotFoundException.builder().message("gone").build(); | ||
| AlreadyExistsException exists = AlreadyExistsException.builder().message("dup").build(); | ||
| InvalidInputException invalid = InvalidInputException.builder().message("bad name").build(); | ||
|
|
||
| assertInstanceOf( | ||
| NoSuchSchemaException.class, | ||
| GlueExceptionConverter.toSchemaException(notFound, "schema db6a")); | ||
| assertInstanceOf( | ||
| SchemaAlreadyExistsException.class, | ||
| GlueExceptionConverter.toSchemaException(exists, "schema db6a")); | ||
| assertInstanceOf( | ||
| IllegalArgumentException.class, | ||
| GlueExceptionConverter.toSchemaException(invalid, "schema db6a")); | ||
|
|
||
| assertInstanceOf( | ||
| NoSuchTableException.class, | ||
| GlueExceptionConverter.toTableException(notFound, "table ctas_test")); | ||
| assertInstanceOf( | ||
| TableAlreadyExistsException.class, | ||
| GlueExceptionConverter.toTableException(exists, "table ctas_test")); | ||
| assertInstanceOf( | ||
| IllegalArgumentException.class, | ||
| GlueExceptionConverter.toTableException(invalid, "table ctas_test")); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.