-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-14361. Implement bucket CRUD as BucketOperationHandler #9679
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2e3d99
HDDS-14361. Implement bucket CRUD as BucketOperationHandler
Russole f7c1136
Fix CheckStyle Error
Russole 468401e
Remove unnecessary comments
Russole 406cc09
Add comments to BucketCrudHandler
Russole 0760778
Rename and apply shouldHandle in BucketCrudHandler
Russole 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
133 changes: 133 additions & 0 deletions
133
...-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketCrudHandler.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,133 @@ | ||
| /* | ||
| * 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.s3.exception.S3ErrorTable.newError; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import javax.ws.rs.core.Response; | ||
| import org.apache.hadoop.ozone.audit.S3GAction; | ||
| import org.apache.hadoop.ozone.client.OzoneBucket; | ||
| import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
| import org.apache.hadoop.ozone.s3.exception.OS3Exception; | ||
| import org.apache.hadoop.ozone.s3.exception.S3ErrorTable; | ||
| import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.apache.http.HttpStatus; | ||
|
|
||
| /** | ||
| * Handler for default bucket CRUD operations. | ||
| * Implements PUT (create bucket) and DELETE operations when no | ||
| * subresource query parameters are present. | ||
| * | ||
| * This handler processes bucket-level requests that do not target | ||
| * specific subresources (such as {@code ?acl}, {@code ?uploads}, | ||
| * or {@code ?delete}), which are handled by dedicated handlers. | ||
| * | ||
| * This handler extends EndpointBase to inherit all required functionality | ||
| * (configuration, headers, request context, audit logging, metrics, etc.). | ||
| */ | ||
| public class BucketCrudHandler extends EndpointBase implements BucketOperationHandler { | ||
|
|
||
| /** | ||
| * Handle only plain PUT bucket (create bucket), not subresources. | ||
| */ | ||
| private boolean shouldHandle() { | ||
| return queryParams().get(QueryParams.ACL) == null | ||
| && queryParams().get(QueryParams.UPLOADS) == null | ||
| && queryParams().get(QueryParams.DELETE) == null; | ||
| } | ||
|
|
||
| /** | ||
| * Handle PUT /{bucket} for bucket creation. | ||
| */ | ||
| @Override | ||
| public Response handlePutRequest(String bucketName, InputStream body) | ||
| throws IOException, OS3Exception { | ||
|
|
||
| if (!shouldHandle()) { | ||
| return null; | ||
| } | ||
|
|
||
| long startNanos = Time.monotonicNowNanos(); | ||
| S3GAction s3GAction = S3GAction.CREATE_BUCKET; | ||
|
|
||
| try { | ||
| String location = createS3Bucket(bucketName); | ||
| auditWriteSuccess(s3GAction); | ||
| getMetrics().updateCreateBucketSuccessStats(startNanos); | ||
| return Response.status(HttpStatus.SC_OK).header("Location", location) | ||
| .build(); | ||
| } catch (OMException exception) { | ||
| auditWriteFailure(s3GAction, exception); | ||
| getMetrics().updateCreateBucketFailureStats(startNanos); | ||
| if (exception.getResult() == OMException.ResultCodes.INVALID_BUCKET_NAME) { | ||
| throw newError(S3ErrorTable.INVALID_BUCKET_NAME, bucketName, exception); | ||
| } | ||
| throw exception; | ||
| } catch (Exception ex) { | ||
| auditWriteFailure(s3GAction, ex); | ||
| throw ex; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Handle DELETE /{bucket} for bucket deletion. | ||
| */ | ||
| @Override | ||
| public Response handleDeleteRequest(String bucketName) | ||
| throws IOException, OS3Exception { | ||
|
|
||
| if (!shouldHandle()) { | ||
| return null; | ||
| } | ||
|
|
||
| long startNanos = Time.monotonicNowNanos(); | ||
| S3GAction s3GAction = S3GAction.DELETE_BUCKET; | ||
|
|
||
| try { | ||
| if (S3Owner.hasBucketOwnershipVerificationConditions(getHeaders())) { | ||
| OzoneBucket bucket = getBucket(bucketName); | ||
| S3Owner.verifyBucketOwnerCondition(getHeaders(), bucketName, bucket.getOwner()); | ||
| } | ||
| deleteS3Bucket(bucketName); | ||
| } catch (OMException ex) { | ||
| auditWriteFailure(s3GAction, ex); | ||
| getMetrics().updateDeleteBucketFailureStats(startNanos); | ||
| if (ex.getResult() == OMException.ResultCodes.BUCKET_NOT_EMPTY) { | ||
| throw newError(S3ErrorTable.BUCKET_NOT_EMPTY, bucketName, ex); | ||
| } else if (ex.getResult() == OMException.ResultCodes.BUCKET_NOT_FOUND) { | ||
| throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex); | ||
| } else if (isAccessDenied(ex)) { | ||
| throw newError(S3ErrorTable.ACCESS_DENIED, bucketName, ex); | ||
| } else { | ||
| throw ex; | ||
| } | ||
| } catch (Exception ex) { | ||
| auditWriteFailure(s3GAction, ex); | ||
| throw ex; | ||
| } | ||
|
|
||
| auditWriteSuccess(s3GAction); | ||
| getMetrics().updateDeleteBucketSuccessStats(startNanos); | ||
| return Response | ||
| .status(HttpStatus.SC_NO_CONTENT) | ||
| .build(); | ||
| } | ||
| } | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handlers are tried in order, so
BucketCrudHandlerdoes not need to check conditions, just handle all requests that reach it, likeBucketEndpointdid.We can keep this method if you prefer, but then please rename to
shouldHandleand reuse inhandleDeleteRequest.