Skip to content

Commit 70b0d89

Browse files
authored
Merge pull request apache#15 from passaro/HADOOP-18073-v2/exceptions
Update Exception Handling for SDK v2
2 parents da64e2e + 30a0f9f commit 70b0d89

30 files changed

+434
-429
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSBadRequestException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonServiceException;
21+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2222

2323
/**
2424
* A 400 "Bad Request" exception was received.
@@ -36,7 +36,7 @@ public class AWSBadRequestException extends AWSServiceIOException {
3636
* @param cause the underlying cause
3737
*/
3838
public AWSBadRequestException(String operation,
39-
AmazonServiceException cause) {
39+
AwsServiceException cause) {
4040
super(operation, cause);
4141
}
4242
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSClientIOException.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,34 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonClientException;
22-
import com.amazonaws.SdkBaseException;
2321
import org.apache.hadoop.util.Preconditions;
2422

2523
import java.io.IOException;
24+
import java.util.Map;
25+
26+
import software.amazon.awssdk.core.exception.SdkException;
2627

2728
/**
28-
* IOException equivalent of an {@link AmazonClientException}.
29+
* IOException equivalent of an {@link SdkException}.
2930
*/
3031
public class AWSClientIOException extends IOException {
3132

3233
private final String operation;
3334

3435
public AWSClientIOException(String operation,
35-
SdkBaseException cause) {
36+
SdkException cause) {
3637
super(cause);
3738
Preconditions.checkArgument(operation != null, "Null 'operation' argument");
3839
Preconditions.checkArgument(cause != null, "Null 'cause' argument");
3940
this.operation = operation;
4041
}
4142

42-
public AmazonClientException getCause() {
43-
return (AmazonClientException) super.getCause();
43+
public SdkException getCause() {
44+
return (SdkException) super.getCause();
4445
}
4546

4647
@Override
4748
public String getMessage() {
4849
return operation + ": " + getCause().getMessage();
4950
}
50-
5151
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSCredentialProviderList.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.concurrent.atomic.AtomicInteger;
2828
import java.util.stream.Collectors;
2929

30-
import com.amazonaws.AmazonClientException;
3130
import com.amazonaws.auth.AWSCredentials;
3231
import com.amazonaws.auth.AWSCredentialsProvider;
3332
import com.amazonaws.auth.AnonymousAWSCredentials;
@@ -43,6 +42,8 @@
4342
import org.apache.hadoop.fs.s3a.auth.NoAwsCredentialsException;
4443
import org.apache.hadoop.io.IOUtils;
4544

45+
import software.amazon.awssdk.core.exception.SdkException;
46+
4647
/**
4748
* A list of providers.
4849
*
@@ -51,10 +52,10 @@
5152
* <ol>
5253
* <li>Allows extra providers to be added dynamically.</li>
5354
* <li>If any provider in the chain throws an exception other than
54-
* an {@link AmazonClientException}, that is rethrown, rather than
55+
* an {@link SdkException}, that is rethrown, rather than
5556
* swallowed.</li>
5657
* <li>Has some more diagnostics.</li>
57-
* <li>On failure, the last "relevant" AmazonClientException raised is
58+
* <li>On failure, the last "relevant" {@link SdkException} raised is
5859
* rethrown; exceptions other than 'no credentials' have priority.</li>
5960
* <li>Special handling of {@link AnonymousAWSCredentials}.</li>
6061
* </ol>
@@ -171,7 +172,7 @@ public AWSCredentials getCredentials() {
171172
return lastProvider.getCredentials();
172173
}
173174

174-
AmazonClientException lastException = null;
175+
SdkException lastException = null;
175176
for (AWSCredentialsProvider provider : providers) {
176177
try {
177178
AWSCredentials credentials = provider.getCredentials();
@@ -196,7 +197,7 @@ public AWSCredentials getCredentials() {
196197
}
197198
LOG.debug("No credentials from {}: {}",
198199
provider, e.toString());
199-
} catch (AmazonClientException e) {
200+
} catch (SdkException e) {
200201
lastException = e;
201202
LOG.debug("No credentials provided by {}: {}",
202203
provider, e.toString(), e);
@@ -229,7 +230,7 @@ List<AWSCredentialsProvider> getProviders() {
229230

230231
/**
231232
* Verify that the provider list is not empty.
232-
* @throws AmazonClientException if there are no providers.
233+
* @throws SdkException if there are no providers.
233234
*/
234235
public void checkNotEmpty() {
235236
if (providers.isEmpty()) {

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSNoResponseException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonServiceException;
21+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2222

2323
/**
2424
* Status code 443, no response from server. This is considered idempotent.
2525
*/
2626
public class AWSNoResponseException extends AWSServiceIOException {
2727
public AWSNoResponseException(String operation,
28-
AmazonServiceException cause) {
28+
AwsServiceException cause) {
2929
super(operation, cause);
3030
}
3131
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSRedirectException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonServiceException;
21+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2222

2323
/**
2424
* Request is redirected.
@@ -32,7 +32,7 @@ public class AWSRedirectException extends AWSServiceIOException {
3232
* @param cause the underlying cause
3333
*/
3434
public AWSRedirectException(String operation,
35-
AmazonServiceException cause) {
35+
AwsServiceException cause) {
3636
super(operation, cause);
3737
}
3838
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSS3IOException.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.services.s3.model.AmazonS3Exception;
21+
import software.amazon.awssdk.services.s3.model.S3Exception;
22+
2223
import org.apache.hadoop.classification.InterfaceAudience;
2324
import org.apache.hadoop.classification.InterfaceStability;
2425

25-
import java.util.Map;
26-
2726
/**
28-
* Wrap a {@link AmazonS3Exception} as an IOE, relaying all
27+
* Wrap a {@link S3Exception} as an IOE, relaying all
2928
* getters.
3029
*/
3130
@InterfaceAudience.Public
@@ -38,24 +37,12 @@ public class AWSS3IOException extends AWSServiceIOException {
3837
* @param cause the underlying cause
3938
*/
4039
public AWSS3IOException(String operation,
41-
AmazonS3Exception cause) {
40+
S3Exception cause) {
4241
super(operation, cause);
4342
}
4443

45-
public AmazonS3Exception getCause() {
46-
return (AmazonS3Exception) super.getCause();
47-
}
48-
49-
public String getErrorResponseXml() {
50-
return getCause().getErrorResponseXml();
51-
}
52-
53-
public Map<String, String> getAdditionalDetails() {
54-
return getCause().getAdditionalDetails();
55-
}
56-
57-
public String getExtendedRequestId() {
58-
return getCause().getExtendedRequestId();
44+
public S3Exception getCause() {
45+
return (S3Exception) super.getCause();
5946
}
6047

6148
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSServiceIOException.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonServiceException;
2221
import org.apache.hadoop.classification.InterfaceAudience;
2322
import org.apache.hadoop.classification.InterfaceStability;
2423

24+
import software.amazon.awssdk.awscore.exception.AwsErrorDetails;
25+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
26+
2527
/**
2628
* A specific exception from AWS operations.
27-
* The exception must always be created with an {@link AmazonServiceException}.
29+
* The exception must always be created with an {@link AwsServiceException}.
2830
* The attributes of this exception can all be directly accessed.
2931
*/
3032
@InterfaceAudience.Public
@@ -37,36 +39,31 @@ public class AWSServiceIOException extends AWSClientIOException {
3739
* @param cause the underlying cause
3840
*/
3941
public AWSServiceIOException(String operation,
40-
AmazonServiceException cause) {
42+
AwsServiceException cause) {
4143
super(operation, cause);
4244
}
4345

44-
public AmazonServiceException getCause() {
45-
return (AmazonServiceException) super.getCause();
46-
}
47-
48-
public String getRequestId() {
49-
return getCause().getRequestId();
46+
public AwsServiceException getCause() {
47+
return (AwsServiceException) super.getCause();
5048
}
5149

52-
public String getServiceName() {
53-
return getCause().getServiceName();
50+
public boolean retryable() {
51+
return getCause().retryable();
5452
}
5553

56-
public String getErrorCode() {
57-
return getCause().getErrorCode();
54+
public String requestId() {
55+
return getCause().requestId();
5856
}
5957

60-
public int getStatusCode() {
61-
return getCause().getStatusCode();
58+
public AwsErrorDetails awsErrorDetails() {
59+
return getCause().awsErrorDetails();
6260
}
6361

64-
public String getRawResponseContent() {
65-
return getCause().getRawResponseContent();
62+
public int statusCode() {
63+
return getCause().statusCode();
6664
}
6765

68-
public boolean isRetryable() {
69-
return getCause().isRetryable();
66+
public String extendedRequestId() {
67+
return getCause().extendedRequestId();
7068
}
71-
7269
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSServiceThrottledException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonServiceException;
21+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2222

2323
/**
2424
* Exception raised when a service was throttled.
@@ -36,7 +36,7 @@ public class AWSServiceThrottledException extends AWSServiceIOException {
3636
* @param cause the underlying cause
3737
*/
3838
public AWSServiceThrottledException(String operation,
39-
AmazonServiceException cause) {
39+
AwsServiceException cause) {
4040
super(operation, cause);
4141
}
4242
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSStatus500Exception.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonServiceException;
21+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2222

2323
/**
2424
* A 500 response came back from a service.
@@ -31,7 +31,7 @@
3131
*/
3232
public class AWSStatus500Exception extends AWSServiceIOException {
3333
public AWSStatus500Exception(String operation,
34-
AmazonServiceException cause) {
34+
AwsServiceException cause) {
3535
super(operation, cause);
3636
}
3737
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/CredentialInitializationException.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,37 @@
1818

1919
package org.apache.hadoop.fs.s3a;
2020

21-
import com.amazonaws.AmazonClientException;
21+
import software.amazon.awssdk.core.exception.SdkException;
2222

2323
import org.apache.hadoop.classification.InterfaceAudience;
2424
import org.apache.hadoop.classification.InterfaceStability;
2525

2626
/**
2727
* Exception which Hadoop's AWSCredentialsProvider implementations should
2828
* throw when there is a problem with the credential setup. This
29-
* is a subclass of {@link AmazonClientException} which sets
30-
* {@link #isRetryable()} to false, so as to fail fast.
29+
* is a subclass of {@link SdkException} which sets
30+
* {@link #retryable()} to false, so as to fail fast.
3131
* This is used in credential providers and elsewhere.
3232
* When passed through {@code S3AUtils.translateException()} it
3333
* is mapped to an AccessDeniedException. As a result, the Invoker
3434
* code will automatically translate
3535
*/
3636
@InterfaceAudience.Public
3737
@InterfaceStability.Stable
38-
public class CredentialInitializationException extends AmazonClientException {
38+
public class CredentialInitializationException extends SdkException {
39+
3940
public CredentialInitializationException(String message, Throwable t) {
40-
super(message, t);
41+
super(builder().message(message).cause(t));
4142
}
4243

4344
public CredentialInitializationException(String message) {
44-
super(message);
45+
super(builder().message(message));
4546
}
4647

4748
/**
4849
* This exception is not going to go away if you try calling it again.
4950
* @return false, always.
5051
*/
5152
@Override
52-
public boolean isRetryable() {
53-
return false;
54-
}
53+
public boolean retryable() { return false; }
5554
}

0 commit comments

Comments
 (0)