adoroszlai commented on code in PR #10045:
URL: https://github.com/apache/ozone/pull/10045#discussion_r3217966562
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -103,161 +98,23 @@ public Response get(
}
@Override
- Response handleGetRequest(S3RequestContext context, String bucketName)
throws IOException, OS3Exception {
- final String continueToken =
queryParams().get(QueryParams.CONTINUATION_TOKEN);
- final String delimiter = queryParams().get(QueryParams.DELIMITER);
- final String encodingType = queryParams().get(QueryParams.ENCODING_TYPE);
- final String marker = queryParams().get(QueryParams.MARKER);
- int maxKeys = queryParams().getInt(QueryParams.MAX_KEYS, 1000);
- String prefix = queryParams().get(QueryParams.PREFIX, "");
- String startAfter = queryParams().get(QueryParams.START_AFTER);
-
- Iterator<? extends OzoneKey> ozoneKeyIterator = null;
- ContinueToken decodedToken = ContinueToken.decodeFromString(continueToken);
- OzoneBucket bucket = null;
-
+ Response handleGetRequest(S3RequestContext context, String bucketName)
+ throws IOException, OS3Exception {
+ long startNanos = context.getStartNanos();
+ PerformanceStringBuilder perf = context.getPerf();
try {
- maxKeys = validateMaxKeys(maxKeys);
-
- // Assign marker to startAfter. for the compatibility of aws api v1
- if (startAfter == null && marker != null) {
- startAfter = marker;
- }
-
- // If continuation token and start after both are provided, then we
- // ignore start After
- String prevKey = continueToken != null ? decodedToken.getLastKey()
- : startAfter;
-
- // If shallow is true, only list immediate children
- // delimited by OZONE_URI_DELIMITER
- boolean shallow = listKeysShallowEnabled
- && OZONE_URI_DELIMITER.equals(delimiter);
-
- bucket = context.getVolume().getBucket(bucketName);
- S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName,
bucket.getOwner());
-
- ozoneKeyIterator = bucket.listKeys(prefix, prevKey, shallow);
-
+ return BucketListing.fromQueryParams(this, bucketName)
+ .buildResponse(startNanos, perf);
} catch (OMException ex) {
- getMetrics().updateGetBucketFailureStats(context.getStartNanos());
- if (ex.getResult() == ResultCodes.FILE_NOT_FOUND) {
- // File not found, continue and send normal response with 0 keyCount
- LOG.debug("Key Not found prefix: {}", prefix);
- } else {
- throw ex;
+ getMetrics().updateGetBucketFailureStats(startNanos);
+ if (isAccessDenied(ex)) {
+ throw newError(S3ErrorTable.ACCESS_DENIED, bucketName, ex);
}
+ throw ex;
} catch (Exception ex) {
- getMetrics().updateGetBucketFailureStats(context.getStartNanos());
+ getMetrics().updateGetBucketFailureStats(startNanos);
Review Comment:
nit: unnecessary change
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketListing.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.hadoop.ozone.s3.endpoint;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
+import static
org.apache.hadoop.ozone.audit.AuditLogger.PerformanceStringBuilder;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
+import static org.apache.hadoop.ozone.s3.util.S3Consts.ENCODING_TYPE;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Objects;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneKey;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes;
+import org.apache.hadoop.ozone.s3.commontypes.EncodingTypeObject;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
+import org.apache.hadoop.ozone.s3.util.ContinueToken;
+import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class BucketListing {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(BucketListing.class);
+
+ private final BucketEndpoint endpoint;
+ private final String bucketName;
+ private final String delimiter;
+ private final String encodingType;
+ private final String marker;
+ private final String continueToken;
+ private String prefix;
+ private String startAfter;
+ private int maxKeys;
+ private String prevKey;
+ private boolean shallow;
+ private OzoneBucket bucket;
+ private Iterator<? extends OzoneKey> ozoneKeyIterator;
+ private ContinueToken decodedToken;
+
+ private BucketListing(BucketEndpoint endpoint, String bucketName) {
+ this.endpoint = endpoint;
+ this.bucketName = bucketName;
+ this.delimiter = endpoint.queryParams().get(QueryParams.DELIMITER);
+ this.encodingType = endpoint.queryParams().get(QueryParams.ENCODING_TYPE);
+ this.marker = endpoint.queryParams().get(QueryParams.MARKER);
+ this.maxKeys = endpoint.queryParams().getInt(QueryParams.MAX_KEYS, 1000);
+ this.prefix = endpoint.queryParams().get(QueryParams.PREFIX);
+ this.continueToken =
endpoint.queryParams().get(QueryParams.CONTINUATION_TOKEN);
+ this.startAfter = endpoint.queryParams().get(QueryParams.START_AFTER);
+ }
+
+ static BucketListing fromQueryParams(BucketEndpoint endpoint, String
bucketName)
+ throws IOException, OS3Exception {
+ BucketListing listing = new BucketListing(endpoint, bucketName);
+ listing.validateAndPrepare();
+ return listing;
+ }
+
+ Response buildResponse(long startNanos, PerformanceStringBuilder perf) {
+ ListObjectResponse response = initializeListObjectResponse();
+ processKeyListing(response);
+ return buildFinalResponse(response, startNanos, perf);
+ }
+
+ int getMaxKeys() {
+ return maxKeys;
+ }
+
+ String getPrefix() {
+ return prefix;
+ }
+
+ private void validateAndPrepare() throws OS3Exception, IOException {
+ validateEncodingType();
+ maxKeys = validateMaxKeys(maxKeys);
+
+ if (prefix == null) {
+ prefix = "";
+ }
+
+ if (startAfter == null && marker != null) {
+ startAfter = marker;
+ }
+
+ decodedToken = ContinueToken.decodeFromString(continueToken);
+ prevKey = continueToken != null ? decodedToken.getLastKey() : startAfter;
+ shallow = endpoint.isListKeysShallowEnabled()
+ && OZONE_URI_DELIMITER.equals(delimiter);
+
+ bucket = endpoint.getVolume().getBucket(bucketName);
Review Comment:
`context.getVolume()` can be used here (after passing `S3RequestContext`)
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -103,161 +98,23 @@ public Response get(
}
@Override
- Response handleGetRequest(S3RequestContext context, String bucketName)
throws IOException, OS3Exception {
- final String continueToken =
queryParams().get(QueryParams.CONTINUATION_TOKEN);
- final String delimiter = queryParams().get(QueryParams.DELIMITER);
- final String encodingType = queryParams().get(QueryParams.ENCODING_TYPE);
- final String marker = queryParams().get(QueryParams.MARKER);
- int maxKeys = queryParams().getInt(QueryParams.MAX_KEYS, 1000);
- String prefix = queryParams().get(QueryParams.PREFIX, "");
- String startAfter = queryParams().get(QueryParams.START_AFTER);
-
- Iterator<? extends OzoneKey> ozoneKeyIterator = null;
- ContinueToken decodedToken = ContinueToken.decodeFromString(continueToken);
- OzoneBucket bucket = null;
-
+ Response handleGetRequest(S3RequestContext context, String bucketName)
+ throws IOException, OS3Exception {
+ long startNanos = context.getStartNanos();
+ PerformanceStringBuilder perf = context.getPerf();
try {
- maxKeys = validateMaxKeys(maxKeys);
-
- // Assign marker to startAfter. for the compatibility of aws api v1
- if (startAfter == null && marker != null) {
- startAfter = marker;
- }
-
- // If continuation token and start after both are provided, then we
- // ignore start After
- String prevKey = continueToken != null ? decodedToken.getLastKey()
- : startAfter;
-
- // If shallow is true, only list immediate children
- // delimited by OZONE_URI_DELIMITER
- boolean shallow = listKeysShallowEnabled
- && OZONE_URI_DELIMITER.equals(delimiter);
-
- bucket = context.getVolume().getBucket(bucketName);
- S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName,
bucket.getOwner());
-
- ozoneKeyIterator = bucket.listKeys(prefix, prevKey, shallow);
-
+ return BucketListing.fromQueryParams(this, bucketName)
+ .buildResponse(startNanos, perf);
} catch (OMException ex) {
- getMetrics().updateGetBucketFailureStats(context.getStartNanos());
- if (ex.getResult() == ResultCodes.FILE_NOT_FOUND) {
- // File not found, continue and send normal response with 0 keyCount
- LOG.debug("Key Not found prefix: {}", prefix);
- } else {
- throw ex;
+ getMetrics().updateGetBucketFailureStats(startNanos);
+ if (isAccessDenied(ex)) {
+ throw newError(S3ErrorTable.ACCESS_DENIED, bucketName, ex);
}
+ throw ex;
Review Comment:
Seems like unintended change.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -103,161 +98,23 @@ public Response get(
}
@Override
- Response handleGetRequest(S3RequestContext context, String bucketName)
throws IOException, OS3Exception {
- final String continueToken =
queryParams().get(QueryParams.CONTINUATION_TOKEN);
- final String delimiter = queryParams().get(QueryParams.DELIMITER);
- final String encodingType = queryParams().get(QueryParams.ENCODING_TYPE);
- final String marker = queryParams().get(QueryParams.MARKER);
- int maxKeys = queryParams().getInt(QueryParams.MAX_KEYS, 1000);
- String prefix = queryParams().get(QueryParams.PREFIX, "");
- String startAfter = queryParams().get(QueryParams.START_AFTER);
-
- Iterator<? extends OzoneKey> ozoneKeyIterator = null;
- ContinueToken decodedToken = ContinueToken.decodeFromString(continueToken);
- OzoneBucket bucket = null;
-
+ Response handleGetRequest(S3RequestContext context, String bucketName)
+ throws IOException, OS3Exception {
+ long startNanos = context.getStartNanos();
+ PerformanceStringBuilder perf = context.getPerf();
try {
- maxKeys = validateMaxKeys(maxKeys);
-
- // Assign marker to startAfter. for the compatibility of aws api v1
- if (startAfter == null && marker != null) {
- startAfter = marker;
- }
-
- // If continuation token and start after both are provided, then we
- // ignore start After
- String prevKey = continueToken != null ? decodedToken.getLastKey()
- : startAfter;
-
- // If shallow is true, only list immediate children
- // delimited by OZONE_URI_DELIMITER
- boolean shallow = listKeysShallowEnabled
- && OZONE_URI_DELIMITER.equals(delimiter);
-
- bucket = context.getVolume().getBucket(bucketName);
- S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName,
bucket.getOwner());
-
- ozoneKeyIterator = bucket.listKeys(prefix, prevKey, shallow);
-
+ return BucketListing.fromQueryParams(this, bucketName)
+ .buildResponse(startNanos, perf);
Review Comment:
Pass `S3RequestContext context` to `BucketListing`:
- use it to access `volume`, which may be cached already
- no need to pass individual parameters `startNanos, perf`
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -273,11 +130,6 @@ public Response put(
}
}
- @Override
- Response handlePutRequest(S3RequestContext context, String bucketName,
InputStream body) {
- throw newError(S3ErrorTable.NOT_IMPLEMENTED, "PUT bucket");
- }
-
Review Comment:
Please don't remove this.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -321,11 +173,6 @@ public Response delete(@PathParam(BUCKET) String
bucketName)
}
}
- @Override
- Response handleDeleteRequest(S3RequestContext context, String bucketName) {
- throw newError(S3ErrorTable.NOT_IMPLEMENTED, "DELETE bucket");
- }
-
Review Comment:
Please don't remove this.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -417,7 +264,6 @@ protected void init() {
OZONE_S3G_LIST_MAX_KEYS_LIMIT,
OZONE_S3G_LIST_MAX_KEYS_LIMIT_DEFAULT);
- // initialize handlers
Review Comment:
nit: unnecessary change
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]