diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java index e46f4d53f9f1..11efd4e90641 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java @@ -55,6 +55,7 @@ public enum S3GAction implements AuditAction { CREATE_DIRECTORY, GENERATE_SECRET, REVOKE_SECRET, + GET_OBJECT_TORRENT, GET_OBJECT_TAGGING, PUT_OBJECT_TAGGING, DELETE_OBJECT_TAGGING, diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java index ed9602d0fd08..ccc8bcc07cbd 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java @@ -148,6 +148,7 @@ public ObjectEndpoint() { protected void init() { super.init(); ObjectOperationHandler chain = ObjectOperationHandlerChain.newBuilder(this) + .add(new ObjectGetTorrentHandler()) .add(new ObjectAclHandler()) .add(new ObjectTaggingHandler()) .add(new MultipartKeyHandler()) diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectGetTorrentHandler.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectGetTorrentHandler.java new file mode 100644 index 000000000000..312d323d8034 --- /dev/null +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectGetTorrentHandler.java @@ -0,0 +1,48 @@ +/* + * 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 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.exception.OS3Exception; +import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams; + +/** + * Handles GET object {@code ?torrent} ({@code GetObjectTorrent}). + *

+ * This operation is not implemented; previously the request incorrectly fell + * through to GetObject and returned the raw object body. + */ +class ObjectGetTorrentHandler extends ObjectOperationHandler { + + @Override + Response handleGetRequest(ObjectRequestContext context, String keyName) + throws IOException, OS3Exception { + if (queryParams().get(QueryParams.TORRENT) == null) { + return null; + } + + context.setAction(S3GAction.GET_OBJECT_TORRENT); + throw newError(NOT_IMPLEMENTED, "GetObjectTorrent"); + } +} diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java index a2ed3a84c250..65c82d49ca7b 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Consts.java @@ -157,6 +157,8 @@ public static final class QueryParams { public static final String PREFIX = "prefix"; public static final String START_AFTER = "start-after"; public static final String TAGGING = "tagging"; + // GetObjectTorrent is not implemented + public static final String TORRENT = "torrent"; public static final String UPLOAD_ID = "uploadId"; public static final String UPLOAD_ID_MARKER = "upload-id-marker"; public static final String UPLOADS = "uploads"; diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectGetTorrent.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectGetTorrent.java new file mode 100644 index 000000000000..4791d7cf006b --- /dev/null +++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectGetTorrent.java @@ -0,0 +1,54 @@ +/* + * 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.endpoint.EndpointTestUtils.assertErrorResponse; +import static org.apache.hadoop.ozone.s3.endpoint.EndpointTestUtils.get; + +import java.io.IOException; +import org.apache.hadoop.ozone.client.OzoneClient; +import org.apache.hadoop.ozone.client.OzoneClientStub; +import org.apache.hadoop.ozone.s3.exception.S3ErrorTable; +import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** Tests for {@code GET /{bucket}/{key}?torrent} ({@code GetObjectTorrent}). */ +public class TestObjectGetTorrent { + + private static final String BUCKET_NAME = "b1"; + private static final String KEY_NAME = "key1"; + private ObjectEndpoint objectEndpoint; + + @BeforeEach + public void setup() throws IOException { + final OzoneClient clientStub = new OzoneClientStub(); + clientStub.getObjectStore().createS3Bucket(BUCKET_NAME); + + objectEndpoint = EndpointBuilder.newObjectEndpointBuilder() + .setClient(clientStub) + .build(); + } + + @Test + public void getObjectTorrentIsNotImplemented() { + objectEndpoint.queryParamsForTest().set(QueryParams.TORRENT, ""); + + assertErrorResponse(S3ErrorTable.NOT_IMPLEMENTED, () -> get(objectEndpoint, BUCKET_NAME, KEY_NAME)); + } +}