Skip to content

Commit d429906

Browse files
authored
Merge pull request apache#13 from passaro/HADOOP-18073-auditors
Hadoop 18073 auditors
2 parents 2cb1244 + d63ff86 commit d429906

26 files changed

+623
-611
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.amazonaws.SdkClientException;
2828
import com.amazonaws.auth.AWSCredentialsProvider;
2929
import com.amazonaws.client.builder.AwsClientBuilder;
30-
import com.amazonaws.handlers.RequestHandler2;
3130
import com.amazonaws.regions.RegionUtils;
3231
import com.amazonaws.services.s3.AmazonS3;
3332
import com.amazonaws.services.s3.AmazonS3Builder;
@@ -53,6 +52,7 @@
5352

5453
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
5554
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
55+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
5656
import software.amazon.awssdk.core.retry.RetryPolicy;
5757
import software.amazon.awssdk.http.apache.ApacheHttpClient;
5858
import software.amazon.awssdk.http.apache.ProxyConfiguration;
@@ -226,6 +226,12 @@ public S3Client createS3ClientV2(
226226
parameters.getUserAgentSuffix());
227227
}
228228

229+
if (parameters.getExecutionInterceptors() != null) {
230+
for (ExecutionInterceptor interceptor : parameters.getExecutionInterceptors()) {
231+
clientOverrideConfigBuilder.addExecutionInterceptor(interceptor);
232+
}
233+
}
234+
229235
clientOverrideConfigBuilder.retryPolicy(retryPolicyBuilder.build());
230236
httpClientBuilder.proxyConfiguration(proxyConfigBuilder.build());
231237

@@ -253,8 +259,8 @@ public S3Client createS3ClientV2(
253259
s3ClientBuilder.serviceConfiguration(s3Configuration);
254260

255261
// TODO: Some configuration done in configureBasicParams is not done yet.
256-
// Request handlers will be added during auditor work. Need to verify how metrics collection
257-
// can be done, as SDK V2 only seems to have a metrics publisher.
262+
// Need to verify how metrics collection can be done, as SDK V2 only
263+
// seems to have a metrics publisher.
258264

259265
return s3ClientBuilder.build();
260266
}
@@ -359,10 +365,6 @@ private void configureBasicParams(AmazonS3Builder builder,
359365
builder.withMetricsCollector(
360366
new AwsStatisticsCollector(parameters.getMetrics()));
361367
}
362-
if (parameters.getRequestHandlers() != null) {
363-
builder.withRequestHandlers(
364-
parameters.getRequestHandlers().toArray(new RequestHandler2[0]));
365-
}
366368
if (parameters.getMonitoringListener() != null) {
367369
builder.withMonitoringListener(parameters.getMonitoringListener());
368370
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,12 @@
7777
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
7878
import software.amazon.awssdk.awscore.exception.AwsServiceException;
7979
import software.amazon.awssdk.core.sync.RequestBody;
80-
import software.amazon.awssdk.services.s3.S3Client;
8180
import software.amazon.awssdk.services.s3.model.CopyObjectRequest;
8281
import software.amazon.awssdk.services.s3.model.CopyObjectResponse;
8382
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
8483
import software.amazon.awssdk.services.s3.model.DeleteObjectsResponse;
85-
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
86-
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
8784
import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
8885
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
89-
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
90-
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
9186
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
9287
import software.amazon.awssdk.services.s3.model.ObjectIdentifier;
9388
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
@@ -103,6 +98,7 @@
10398
import software.amazon.awssdk.transfer.s3.FileUpload;
10499
import software.amazon.awssdk.transfer.s3.S3TransferManager;
105100
import software.amazon.awssdk.transfer.s3.UploadFileRequest;
101+
import software.amazon.awssdk.transfer.s3.progress.TransferListener;
106102

107103
import org.apache.commons.lang3.tuple.Pair;
108104
import org.apache.hadoop.classification.InterfaceAudience;
@@ -967,7 +963,7 @@ private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
967963
.withPathStyleAccess(conf.getBoolean(PATH_STYLE_ACCESS, false))
968964
.withUserAgentSuffix(uaSuffix)
969965
.withRequesterPays(conf.getBoolean(ALLOW_REQUESTER_PAYS, DEFAULT_ALLOW_REQUESTER_PAYS))
970-
.withRequestHandlers(auditManager.createRequestHandlers());
966+
.withExecutionInterceptors(auditManager.createExecutionInterceptors());
971967

972968
s3 = ReflectionUtils.newInstance(s3ClientFactoryClass, conf)
973969
.createS3Client(getUri(),
@@ -4269,13 +4265,11 @@ private CopyObjectResponse copyFile(String srcKey, String dstKey, long size,
42694265

42704266
// TODO: Transfer manager currently only provides transfer listeners for upload,
42714267
// add progress listener for copy when this is supported.
4272-
// ProgressListener progressListener = progressEvent -> {
4273-
// switch (progressEvent.getEventType()) {
4274-
// case TRANSFER_PART_COMPLETED_EVENT:
4268+
// TODO: Is the above still valid? Try to enable when logger issue is resolved.
4269+
// TransferListener progressListener = new TransferListener() {
4270+
// @Override
4271+
// public void transferComplete(Context.TransferComplete context) {
42754272
// incrementWriteOperations();
4276-
// break;
4277-
// default:
4278-
// break;
42794273
// }
42804274
// };
42814275

@@ -4319,7 +4313,13 @@ private CopyObjectResponse copyFile(String srcKey, String dstKey, long size,
43194313
incrementStatistic(OBJECT_COPY_REQUESTS);
43204314

43214315
Copy copy = transferManagerV2.copy(
4322-
CopyRequest.builder().copyObjectRequest(copyObjectRequestBuilder.build()).build());
4316+
CopyRequest.builder()
4317+
.copyObjectRequest(copyObjectRequestBuilder.build())
4318+
// TODO: Enable when logger issue is resolved.
4319+
// .overrideConfiguration(c -> c
4320+
// .addListener(getAuditManager().createTransferListener())
4321+
// .addListener(progressListener))
4322+
.build());
43234323

43244324
CompletedCopy completedCopy = copy.completionFuture().join();
43254325

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
import com.amazonaws.retry.RetryUtils;
3030
import com.amazonaws.services.s3.model.AmazonS3Exception;
3131
import com.amazonaws.services.s3.model.MultiObjectDeleteException;
32-
import org.apache.hadoop.classification.VisibleForTesting;
33-
import org.apache.hadoop.util.Preconditions;
3432

3533
import org.apache.commons.lang3.StringUtils;
34+
import org.apache.commons.lang3.tuple.Pair;
35+
import org.apache.hadoop.classification.VisibleForTesting;
3636
import org.apache.hadoop.classification.InterfaceAudience;
3737
import org.apache.hadoop.classification.InterfaceStability;
3838
import org.apache.hadoop.conf.Configuration;
@@ -49,6 +49,7 @@
4949
import org.apache.hadoop.fs.s3native.S3xLoginHelper;
5050
import org.apache.hadoop.net.ConnectTimeoutException;
5151
import org.apache.hadoop.security.ProviderUtils;
52+
import org.apache.hadoop.util.Preconditions;
5253
import org.apache.hadoop.util.VersionInfo;
5354

5455
import org.apache.hadoop.util.Lists;

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
import java.util.Map;
2727

2828
import com.amazonaws.auth.AWSCredentialsProvider;
29-
import com.amazonaws.handlers.RequestHandler2;
3029
import com.amazonaws.monitoring.MonitoringListener;
3130
import com.amazonaws.services.s3.AmazonS3;
32-
import software.amazon.awssdk.services.s3.S3Client;
3331

3432
import org.apache.hadoop.classification.InterfaceAudience;
3533
import org.apache.hadoop.classification.InterfaceStability;
3634
import org.apache.hadoop.fs.s3a.statistics.StatisticsFromAwsSdk;
3735

36+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
37+
import software.amazon.awssdk.services.s3.S3Client;
38+
3839
import static org.apache.hadoop.fs.s3a.Constants.DEFAULT_ENDPOINT;
3940

4041
/**
@@ -122,9 +123,9 @@ final class S3ClientCreationParameters {
122123
private boolean requesterPays;
123124

124125
/**
125-
* Request handlers; used for auditing, X-Ray etc.
126-
*/
127-
private List<RequestHandler2> requestHandlers;
126+
* Execution interceptors; used for auditing, X-Ray etc.
127+
* */
128+
private List<ExecutionInterceptor> executionInterceptors;
128129

129130
/**
130131
* Suffix to UA.
@@ -138,22 +139,22 @@ final class S3ClientCreationParameters {
138139
private URI pathUri;
139140

140141
/**
141-
* List of request handlers to include in the chain
142-
* of request execution in the SDK.
143-
* @return the handler list
142+
* List of execution interceptors to include in the chain
143+
* of interceptors in the SDK.
144+
* @return the interceptors list
144145
*/
145-
public List<RequestHandler2> getRequestHandlers() {
146-
return requestHandlers;
146+
public List<ExecutionInterceptor> getExecutionInterceptors() {
147+
return executionInterceptors;
147148
}
148149

149150
/**
150-
* List of request handlers.
151-
* @param handlers handler list.
151+
* List of execution interceptors.
152+
* @param interceptors interceptors list.
152153
* @return this object
153154
*/
154-
public S3ClientCreationParameters withRequestHandlers(
155-
@Nullable final List<RequestHandler2> handlers) {
156-
requestHandlers = handlers;
155+
public S3ClientCreationParameters withExecutionInterceptors(
156+
@Nullable final List<ExecutionInterceptor> interceptors) {
157+
executionInterceptors = interceptors;
157158
return this;
158159
}
159160

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import java.util.List;
2323
import java.util.Optional;
2424

25-
import com.amazonaws.services.s3.model.ListNextBatchOfObjectsRequest;
26-
import com.amazonaws.services.s3.model.ObjectListing;
27-
import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams;
2825
import com.amazonaws.services.s3.model.SSECustomerKey;
2926
import com.amazonaws.services.s3.model.SelectObjectContentRequest;
3027

@@ -81,13 +78,6 @@ public interface RequestFactory {
8178
*/
8279
ObjectCannedACL getCannedACL();
8380

84-
/**
85-
* Create the AWS SDK structure used to configure SSE,
86-
* if the encryption secrets contain the information/settings for this.
87-
* @return an optional set of KMS Key settings
88-
*/
89-
Optional<SSEAwsKeyManagementParams> generateSSEAwsKeyParams();
90-
9181
/**
9282
* Create the SSE-C structure for the AWS SDK, if the encryption secrets
9383
* contain the information/settings for this.
@@ -242,16 +232,6 @@ ListObjectsRequest.Builder newListObjectsV1RequestBuilder(String key,
242232
String delimiter,
243233
int maxKeys);
244234

245-
/**
246-
* Create the next V1 page list request, following
247-
* on from the previous response.
248-
* @param prev previous response
249-
* @return the request
250-
*/
251-
252-
ListNextBatchOfObjectsRequest newListNextBatchOfObjectsRequest(
253-
ObjectListing prev);
254-
255235
/**
256236
* Create a V2 list request builder.
257237
* This will be recycled for any subsequent requests.

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

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

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

21-
import com.amazonaws.AmazonWebServiceRequest;
22-
import com.amazonaws.Request;
23-
import com.amazonaws.Response;
24-
import com.amazonaws.SdkBaseException;
25-
import com.amazonaws.handlers.HandlerAfterAttemptContext;
26-
import com.amazonaws.handlers.HandlerBeforeAttemptContext;
27-
import com.amazonaws.http.HttpResponse;
21+
import software.amazon.awssdk.core.SdkRequest;
22+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
2823

2924
import org.apache.hadoop.fs.s3a.Retries;
3025

@@ -37,10 +32,10 @@
3732
* detect this and raise an exception.
3833
*
3934
* Look at the documentation for
40-
* {@code com.amazonaws.handlers.IRequestHandler2} for details
35+
* {@code ExecutionInterceptor} for details
4136
* on the callbacks.
4237
*/
43-
public interface AWSAuditEventCallbacks {
38+
public interface AWSAuditEventCallbacks extends ExecutionInterceptor {
4439

4540
/**
4641
* Return a span ID which must be unique for all spans within
@@ -66,95 +61,8 @@ public interface AWSAuditEventCallbacks {
6661
* It is not invoked on any AWS requests created in the SDK.
6762
* Avoid raising exceptions or talking to any remote service;
6863
* this callback is for annotation rather than validation.
69-
* @param request request request.
70-
* @param <T> type of request
71-
* @return the request, possibly modified.
64+
* @param builder the request builder.
7265
*/
73-
default <T extends AmazonWebServiceRequest> T requestCreated(T request) {
74-
return request;
75-
}
66+
default void requestCreated(SdkRequest.Builder builder) {}
7667

77-
/**
78-
* Preflight preparation of AWS request.
79-
* @param request request
80-
* @param <T> type of request
81-
* @return an updated request.
82-
* @throws AuditFailureException for generic audit failures
83-
* @throws SdkBaseException for other reasons.
84-
*/
85-
@Retries.OnceRaw
86-
default <T extends AmazonWebServiceRequest> T beforeExecution(T request)
87-
throws AuditFailureException, SdkBaseException {
88-
return request;
89-
}
90-
91-
/**
92-
* Callback after S3 responded to a request.
93-
* @param request request
94-
* @param response response.
95-
* @throws AuditFailureException for generic audit failures
96-
* @throws SdkBaseException for other reasons.
97-
*/
98-
default void afterResponse(Request<?> request,
99-
Response<?> response)
100-
throws AuditFailureException, SdkBaseException {
101-
}
102-
103-
/**
104-
* Callback after a request resulted in an error.
105-
* @param request request
106-
* @param response response.
107-
* @param exception exception raised.
108-
* @throws AuditFailureException for generic audit failures
109-
* @throws SdkBaseException for other reasons.
110-
*/
111-
default void afterError(Request<?> request,
112-
Response<?> response,
113-
Exception exception)
114-
throws AuditFailureException, SdkBaseException {
115-
}
116-
117-
/**
118-
* Request before marshalling.
119-
* @param request request
120-
* @return possibly modified request.
121-
*/
122-
default AmazonWebServiceRequest beforeMarshalling(
123-
AmazonWebServiceRequest request) {
124-
return request;
125-
}
126-
127-
/**
128-
* Request before marshalling.
129-
* @param request request
130-
*/
131-
default void beforeRequest(Request<?> request) {
132-
}
133-
134-
/**
135-
* Before any attempt is made.
136-
* @param context full context, including the request.
137-
*/
138-
default void beforeAttempt(HandlerBeforeAttemptContext context) {
139-
}
140-
141-
/**
142-
* After any attempt is made.
143-
* @param context full context, including the request.
144-
*/
145-
default void afterAttempt(
146-
HandlerAfterAttemptContext context) {
147-
}
148-
149-
/**
150-
* Before unmarshalling the response.
151-
* @param request request made.
152-
* @param httpResponse response received
153-
* @return updated response.
154-
*/
155-
default HttpResponse beforeUnmarshalling(
156-
final Request<?> request,
157-
final HttpResponse httpResponse) {
158-
return httpResponse;
159-
}
16068
}

0 commit comments

Comments
 (0)