-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-14398. Create ObjectOperationHandler interface #9683
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
Open
adoroszlai
wants to merge
1
commit into
apache:master
Choose a base branch
from
adoroszlai:HDDS-14398
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+568
−125
Open
Changes from all commits
Commits
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
94 changes: 94 additions & 0 deletions
94
...way/src/main/java/org/apache/hadoop/ozone/s3/endpoint/AuditingObjectOperationHandler.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,94 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.io.InputStream; | ||
| import javax.ws.rs.core.Response; | ||
| import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext; | ||
| import org.apache.hadoop.ozone.s3.exception.OS3Exception; | ||
|
|
||
| /** Performs audit logging for {@link ObjectOperationHandler}s. */ | ||
| class AuditingObjectOperationHandler extends ObjectOperationHandler { | ||
|
|
||
| private final ObjectOperationHandler delegate; | ||
|
|
||
| AuditingObjectOperationHandler(ObjectOperationHandler delegate) { | ||
| this.delegate = delegate; | ||
| copyDependenciesFrom(delegate); | ||
| } | ||
|
|
||
| @Override | ||
| Response handleDeleteRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception { | ||
| try { | ||
| verifyBucketOwner(context); | ||
| Response response = delegate.handleDeleteRequest(context, keyName); | ||
| auditWriteSuccess(context.getAction()); | ||
| return response; | ||
| } catch (Exception e) { | ||
| auditWriteFailure(context.getAction(), e); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| Response handleGetRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception { | ||
| try { | ||
| verifyBucketOwner(context); | ||
| Response response = delegate.handleGetRequest(context, keyName); | ||
| auditReadSuccess(context.getAction(), context.getPerf()); | ||
| return response; | ||
| } catch (Exception e) { | ||
| auditReadFailure(context.getAction(), e); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| Response handleHeadRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception { | ||
| try { | ||
| verifyBucketOwner(context); | ||
| Response response = delegate.handleHeadRequest(context, keyName); | ||
| auditReadSuccess(context.getAction()); | ||
| return response; | ||
| } catch (Exception e) { | ||
| auditReadFailure(context.getAction(), e); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| Response handlePutRequest(ObjectRequestContext context, String keyName, InputStream body) | ||
| throws IOException, OS3Exception { | ||
| try { | ||
| verifyBucketOwner(context); | ||
| Response response = delegate.handlePutRequest(context, keyName, body); | ||
| auditWriteSuccess(context.getAction(), context.getPerf()); | ||
| return response; | ||
| } catch (Exception e) { | ||
| auditWriteFailure(context.getAction(), e); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| private void verifyBucketOwner(ObjectRequestContext context) throws IOException { | ||
| if (S3Owner.hasBucketOwnershipVerificationConditions(getHeaders())) { | ||
| S3Owner.verifyBucketOwnerCondition(getHeaders(), context.getBucketName(), context.getBucket().getOwner()); | ||
| } | ||
| } | ||
| } |
107 changes: 107 additions & 0 deletions
107
...ay/src/main/java/org/apache/hadoop/ozone/s3/endpoint/CompositeObjectOperationHandler.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,107 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import javax.ws.rs.core.Response; | ||
| import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext; | ||
| import org.apache.hadoop.ozone.s3.exception.OS3Exception; | ||
|
|
||
| /** Chain of responsibility for {@link ObjectOperationHandler}s. */ | ||
| final class CompositeObjectOperationHandler extends ObjectOperationHandler { | ||
|
|
||
| private final List<ObjectOperationHandler> handlers; | ||
|
|
||
| private CompositeObjectOperationHandler(List<ObjectOperationHandler> handlers) { | ||
| this.handlers = handlers; | ||
| } | ||
|
|
||
| @Override | ||
| Response handleDeleteRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception { | ||
| for (ObjectOperationHandler handler : handlers) { | ||
| Response response = handler.handleDeleteRequest(context, keyName); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| Response handleGetRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception { | ||
| for (ObjectOperationHandler handler : handlers) { | ||
| Response response = handler.handleGetRequest(context, keyName); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| Response handleHeadRequest(ObjectRequestContext context, String keyName) throws IOException, OS3Exception { | ||
| for (ObjectOperationHandler handler : handlers) { | ||
| Response response = handler.handleHeadRequest(context, keyName); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| Response handlePutRequest(ObjectRequestContext context, String keyName, InputStream body) | ||
| throws IOException, OS3Exception { | ||
| for (ObjectOperationHandler handler : handlers) { | ||
| Response response = handler.handlePutRequest(context, keyName, body); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| static Builder newBuilder(ObjectEndpoint endpoint) { | ||
| return new Builder(endpoint); | ||
| } | ||
|
|
||
| /** Builds {@code CompositeObjectOperationHandler}. */ | ||
| static final class Builder { | ||
| private final List<ObjectOperationHandler> handlers = new LinkedList<>(); | ||
| private final ObjectEndpoint endpoint; | ||
|
|
||
| private Builder(ObjectEndpoint endpoint) { | ||
| this.endpoint = endpoint; | ||
| } | ||
|
|
||
| /** Append {@code handler} to the list of delegates. */ | ||
| Builder add(ObjectOperationHandler handler) { | ||
| handlers.add(handler.copyDependenciesFrom(endpoint)); | ||
| return this; | ||
| } | ||
|
|
||
| /** Create {@code CompositeObjectOperationHandler} with the list of delegates. */ | ||
| ObjectOperationHandler build() { | ||
| return new CompositeObjectOperationHandler(handlers) | ||
| .copyDependenciesFrom(endpoint); | ||
| } | ||
| } | ||
| } |
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
61 changes: 61 additions & 0 deletions
61
...p-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectAclHandler.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,61 @@ | ||
| /* | ||
| * 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.NOT_IMPLEMENTED; | ||
| import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import javax.ws.rs.HttpMethod; | ||
| import javax.ws.rs.core.Response; | ||
| import org.apache.hadoop.ozone.audit.S3GAction; | ||
| import org.apache.hadoop.ozone.s3.endpoint.ObjectEndpoint.ObjectRequestContext; | ||
| import org.apache.hadoop.ozone.s3.util.S3Consts; | ||
|
|
||
| /** Not implemented yet. */ | ||
| class ObjectAclHandler extends ObjectOperationHandler { | ||
|
|
||
| @Override | ||
| Response handlePutRequest(ObjectRequestContext context, String keyName, InputStream body) throws IOException { | ||
| if (context.ignore(getAction())) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| throw newError(NOT_IMPLEMENTED, keyName); | ||
| } catch (Exception e) { | ||
| getMetrics().updatePutObjectAclFailureStats(context.getStartNanos()); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("SwitchStatementWithTooFewBranches") | ||
| S3GAction getAction() { | ||
| if (queryParams().get(S3Consts.QueryParams.ACL) == null) { | ||
| return null; | ||
| } | ||
|
|
||
| switch (getContext().getMethod()) { | ||
| case HttpMethod.PUT: | ||
| return S3GAction.PUT_OBJECT_ACL; | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
maybe use chain as its name is better? just suggestion