Skip to content

Commit ba657c7

Browse files
committed
Refactor BucketEndpoint.get() into helper methods
1 parent 9d848d5 commit ba657c7

2 files changed

Lines changed: 22 additions & 28 deletions

File tree

hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,17 @@ public Response get(
132132

133133
// Actual bucket processing starts here
134134
// Validate and prepare parameters
135-
BucketListingContext context = validateAndPrepareParameters(
135+
BucketListingContext listingContext = validateAndPrepareParameters(
136136
bucketName, delimiter, encodingType, marker, maxKeys, prefix,
137137
continueToken, startAfter);
138138

139139
// Initialize response object
140140
ListObjectResponse response = initializeListObjectResponse(
141-
bucketName, delimiter, encodingType, marker, maxKeys, prefix,
141+
bucketName, delimiter, encodingType, marker, listingContext.getMaxKeys(), prefix,
142142
continueToken, startAfter);
143143

144144
// Process key listing
145-
processKeyListing(context, response);
145+
processKeyListing(listingContext, response);
146146

147147
// Build final response
148148
return buildFinalResponse(response, s3GAction, startNanos, perf);
@@ -172,7 +172,6 @@ public Response get(
172172

173173
// Log audit entry for empty response to align with previous behavior
174174
long opLatencyNs = getMetrics().updateGetBucketSuccessStats(startNanos);
175-
PerformanceStringBuilder perf = new PerformanceStringBuilder();
176175
perf.appendCount(0);
177176
perf.appendOpLatencyNanos(opLatencyNs);
178177
auditReadSuccess(s3GAction, perf);
@@ -281,20 +280,6 @@ public ContinueToken getDecodedToken() {
281280
}
282281
}
283282

284-
/**
285-
* Handle GetBucketAcl request.
286-
* Implements the GetBucketAcl API operation.
287-
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketAcl.html">GetBucketAcl</a>
288-
*/
289-
Response handleGetBucketAcl(String bucketName, long startNanos)
290-
throws OS3Exception, IOException {
291-
S3GAction s3GAction = S3GAction.GET_ACL;
292-
S3BucketAcl result = getAcl(bucketName);
293-
getMetrics().updateGetAclSuccessStats(startNanos);
294-
auditReadSuccess(s3GAction);
295-
return Response.ok(result, MediaType.APPLICATION_XML_TYPE).build();
296-
}
297-
298283
/**
299284
* Validate and prepare parameters for bucket listing.
300285
*/
@@ -306,20 +291,13 @@ BucketListingContext validateAndPrepareParameters(
306291

307292
// If you specify the encoding-type request parameter, should return encoded key name values
308293
// in the following response elements: Delimiter, Prefix, Key, and StartAfter.
309-
// For detail refer: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#AmazonS3-ListObjectsV2-response-EncodingType
294+
// For detail refer:
295+
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#AmazonS3-ListObjectsV2-response-EncodingType
310296

311297
// Validate encoding type
312298
if (encodingType != null && !encodingType.equals(ENCODING_TYPE)) {
313299
throw S3ErrorTable.newError(S3ErrorTable.INVALID_ARGUMENT, encodingType);
314300
}
315-
// If you specify the encoding-type request parameter,should return
316-
// encoded key name values in the following response elements:
317-
// Delimiter, Prefix, Key, and StartAfter.
318-
//
319-
// For detail refer:
320-
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html
321-
// #AmazonS3-ListObjectsV2-response-EncodingType
322-
//
323301
maxKeys = validateMaxKeys(maxKeys);
324302

325303
if (prefix == null) {
@@ -459,7 +437,8 @@ void processKeyListing(BucketListingContext context, ListObjectResponse response
459437
/**
460438
* Build final response with metrics and audit logging.
461439
*/
462-
Response buildFinalResponse(ListObjectResponse response, S3GAction s3GAction, long startNanos, PerformanceStringBuilder perf) {
440+
Response buildFinalResponse(ListObjectResponse response, S3GAction s3GAction,
441+
long startNanos, PerformanceStringBuilder perf) {
463442
int keyCount = response.getCommonPrefixes().size() + response.getContents().size();
464443
long opLatencyNs = getMetrics().updateGetBucketSuccessStats(startNanos);
465444
getMetrics().incListKeyCount(keyCount);

hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketEndpoint.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
2323

2424
import java.io.IOException;
25+
import javax.ws.rs.core.Response;
2526
import org.apache.hadoop.ozone.client.OzoneClientStub;
2627
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
2728
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
29+
import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
2830
import org.junit.jupiter.api.BeforeEach;
2931
import org.junit.jupiter.api.Test;
3032

@@ -135,4 +137,17 @@ public void testValidateAndPrepareParametersWithNonexistentBucket() {
135137

136138
assertEquals(S3ErrorTable.NO_SUCH_BUCKET.getCode(), exception.getCode());
137139
}
140+
141+
@Test
142+
public void testGetDelegatesToAclHandler() throws Exception {
143+
// When ?acl is present, BucketEndpoint should delegate to BucketAclHandler.
144+
bucketEndpoint.queryParamsForTest().set(QueryParams.ACL, "");
145+
146+
Response response = bucketEndpoint.get(TEST_BUCKET_NAME);
147+
148+
assertNotNull(response);
149+
assertEquals(200, response.getStatus());
150+
assertNotNull(response.getEntity());
151+
assertEquals("S3BucketAcl", response.getEntity().getClass().getSimpleName());
152+
}
138153
}

0 commit comments

Comments
 (0)