Skip to content

Commit 2cb8544

Browse files
committed
Revert "HDDS-14209. Look up query params in ObjectEndpoint"
This reverts commit ea8c924.
1 parent ea8c924 commit 2cb8544

16 files changed

Lines changed: 540 additions & 309 deletions

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

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public class ObjectEndpoint extends EndpointBase {
168168

169169
/*FOR the feature Overriding Response Header
170170
https://docs.aws.amazon.com/de_de/AmazonS3/latest/API/API_GetObject.html */
171-
private final Map<String, String> overrideQueryParameter;
171+
private Map<String, String> overrideQueryParameter;
172172
private int bufferSize;
173173
private int chunkSize;
174174
private boolean datastreamEnabled;
@@ -209,18 +209,17 @@ public void init() {
209209
* See: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html for
210210
* more details.
211211
*/
212-
@SuppressWarnings("checkstyle:MethodLength")
212+
@SuppressWarnings({"checkstyle:MethodLength", "checkstyle:ParameterNumber"})
213213
@PUT
214214
public Response put(
215215
@PathParam(BUCKET) String bucketName,
216216
@PathParam(PATH) String keyPath,
217217
@HeaderParam(HttpHeaders.CONTENT_LENGTH) long length,
218-
final InputStream body
219-
) throws IOException, OS3Exception {
220-
final String aclMarker = queryParams().get(QueryParams.ACL);
221-
final int partNumber = queryParams().getInt(QueryParams.PART_NUMBER, 0);
222-
final String taggingMarker = queryParams().get(QueryParams.TAGGING);
223-
final String uploadID = queryParams().get(QueryParams.UPLOAD_ID);
218+
@QueryParam(QueryParams.PART_NUMBER) int partNumber,
219+
@QueryParam(QueryParams.UPLOAD_ID) @DefaultValue("") String uploadID,
220+
@QueryParam(QueryParams.TAGGING) String taggingMarker,
221+
@QueryParam(QueryParams.ACL) String aclMarker,
222+
final InputStream body) throws IOException, OS3Exception {
224223
long startNanos = Time.monotonicNowNanos();
225224
S3GAction s3GAction = S3GAction.CREATE_KEY;
226225
boolean auditSuccess = true;
@@ -404,26 +403,17 @@ public Response put(
404403
* https://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadListParts.html
405404
* for more details.
406405
*/
407-
@SuppressWarnings("checkstyle:MethodLength")
406+
@SuppressWarnings({"checkstyle:MethodLength", "checkstyle:ParameterNumber"})
408407
@GET
409-
public Response get(
410-
@PathParam(BUCKET) String bucketName,
411-
@PathParam(PATH) String keyPath
412-
) throws IOException, OS3Exception {
413-
final int partNumber = queryParams().getInt(QueryParams.PART_NUMBER, 0);
414-
final int maxParts = queryParams().getInt(QueryParams.MAX_PARTS, 1000);
415-
return get(bucketName, keyPath, partNumber, maxParts);
416-
}
417-
418408
public Response get(
419409
@PathParam(BUCKET) String bucketName,
420410
@PathParam(PATH) String keyPath,
421411
@QueryParam(QueryParams.PART_NUMBER) int partNumber,
422-
@QueryParam(QueryParams.MAX_PARTS) @DefaultValue("1000") int maxParts
423-
) throws IOException, OS3Exception {
424-
final String uploadId = queryParams().get(QueryParams.UPLOAD_ID);
425-
final String partNumberMarker = queryParams().get(QueryParams.PART_NUMBER_MARKER);
426-
final String taggingMarker = queryParams().get(QueryParams.TAGGING);
412+
@QueryParam(QueryParams.UPLOAD_ID) String uploadId,
413+
@QueryParam(QueryParams.MAX_PARTS) @DefaultValue("1000") int maxParts,
414+
@QueryParam(QueryParams.PART_NUMBER_MARKER) String partNumberMarker,
415+
@QueryParam(QueryParams.TAGGING) String taggingMarker)
416+
throws IOException, OS3Exception {
427417
long startNanos = Time.monotonicNowNanos();
428418
S3GAction s3GAction = S3GAction.GET_KEY;
429419
PerformanceStringBuilder perf = new PerformanceStringBuilder();
@@ -730,11 +720,10 @@ private Response abortMultipartUpload(OzoneVolume volume, String bucket,
730720
@SuppressWarnings("emptyblock")
731721
public Response delete(
732722
@PathParam(BUCKET) String bucketName,
733-
@PathParam(PATH) String keyPath
734-
) throws IOException, OS3Exception {
735-
final String taggingMarker = queryParams().get(QueryParams.TAGGING);
736-
final String uploadId = queryParams().get(QueryParams.UPLOAD_ID);
737-
723+
@PathParam(PATH) String keyPath,
724+
@QueryParam(QueryParams.UPLOAD_ID) @DefaultValue("") String uploadId,
725+
@QueryParam(QueryParams.TAGGING) String taggingMarker) throws
726+
IOException, OS3Exception {
738727
long startNanos = Time.monotonicNowNanos();
739728
S3GAction s3GAction = S3GAction.DELETE_KEY;
740729

@@ -809,7 +798,8 @@ public Response delete(
809798
public Response initializeMultipartUpload(
810799
@PathParam(BUCKET) String bucket,
811800
@PathParam(PATH) String key
812-
) throws IOException, OS3Exception {
801+
)
802+
throws IOException, OS3Exception {
813803
long startNanos = Time.monotonicNowNanos();
814804
S3GAction s3GAction = S3GAction.INIT_MULTIPART_UPLOAD;
815805

@@ -873,9 +863,9 @@ private ReplicationConfig getReplicationConfig(OzoneBucket ozoneBucket,
873863
public Response completeMultipartUpload(
874864
@PathParam(BUCKET) String bucket,
875865
@PathParam(PATH) String key,
876-
CompleteMultipartUploadRequest multipartUploadRequest
877-
) throws IOException, OS3Exception {
878-
final String uploadID = queryParams().get(QueryParams.UPLOAD_ID, "");
866+
@QueryParam(QueryParams.UPLOAD_ID) @DefaultValue("") String uploadID,
867+
CompleteMultipartUploadRequest multipartUploadRequest)
868+
throws IOException, OS3Exception {
879869
long startNanos = Time.monotonicNowNanos();
880870
S3GAction s3GAction = S3GAction.COMPLETE_MULTIPART_UPLOAD;
881871
OzoneVolume volume = getVolume();

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.IOException;
2626
import javax.ws.rs.core.Response;
2727
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
28-
import org.apache.hadoop.ozone.s3.util.S3Consts;
2928
import org.apache.http.HttpStatus;
3029
import org.apache.ratis.util.function.CheckedSupplier;
3130

@@ -60,17 +59,12 @@ public static Response put(
6059
String uploadID,
6160
String content
6261
) throws IOException, OS3Exception {
63-
if (uploadID != null) {
64-
subject.queryParamsForTest().set(S3Consts.QueryParams.UPLOAD_ID, uploadID);
65-
}
66-
subject.queryParamsForTest().setInt(S3Consts.QueryParams.PART_NUMBER, partNumber);
67-
6862
if (content == null) {
69-
return subject.put(bucket, key, 0, null);
63+
return subject.put(bucket, key, 0, partNumber, uploadID, null, null, null);
7064
} else {
7165
final long length = content.length();
7266
try (ByteArrayInputStream body = new ByteArrayInputStream(content.getBytes(UTF_8))) {
73-
return subject.put(bucket, key, length, body);
67+
return subject.put(bucket, key, length, partNumber, uploadID, null, null, body);
7468
}
7569
}
7670
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.hadoop.ozone.client.OzoneClientStub;
3131
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
3232
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
33-
import org.apache.hadoop.ozone.s3.util.S3Consts;
3433
import org.junit.jupiter.api.Test;
3534

3635
/**
@@ -64,16 +63,15 @@ public void testAbortMultipartUpload() throws Exception {
6463
assertNotNull(multipartUploadInitiateResponse.getUploadID());
6564
String uploadID = multipartUploadInitiateResponse.getUploadID();
6665

66+
6767
// Abort multipart upload
68-
rest.queryParamsForTest().set(S3Consts.QueryParams.UPLOAD_ID, uploadID);
69-
response = rest.delete(bucket, key);
68+
response = rest.delete(bucket, key, uploadID, null);
7069

7170
assertEquals(204, response.getStatus());
7271

7372
// test with unknown upload Id.
7473
try {
75-
rest.queryParamsForTest().set(S3Consts.QueryParams.UPLOAD_ID, "random");
76-
rest.delete(bucket, key);
74+
rest.delete(bucket, key, "random", null);
7775
} catch (OS3Exception ex) {
7876
assertEquals(S3ErrorTable.NO_SUCH_UPLOAD.getCode(), ex.getCode());
7977
assertEquals(S3ErrorTable.NO_SUCH_UPLOAD.getErrorMessage(),

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.hadoop.ozone.s3.endpoint;
1919

20-
import static org.apache.hadoop.ozone.s3.endpoint.EndpointTestUtils.put;
20+
import static java.nio.charset.StandardCharsets.UTF_8;
2121
import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CLASS_HEADER;
2222
import static org.apache.hadoop.ozone.s3.util.S3Consts.X_AMZ_CONTENT_SHA256;
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -27,14 +27,14 @@
2727
import static org.mockito.Mockito.mock;
2828
import static org.mockito.Mockito.when;
2929

30+
import java.io.ByteArrayInputStream;
3031
import javax.ws.rs.core.HttpHeaders;
3132
import javax.ws.rs.core.Response;
3233
import org.apache.hadoop.ozone.OzoneConsts;
3334
import org.apache.hadoop.ozone.client.OzoneClient;
3435
import org.apache.hadoop.ozone.client.OzoneClientStub;
3536
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
3637
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
37-
import org.apache.hadoop.ozone.s3.util.S3Consts;
3838
import org.junit.jupiter.api.BeforeEach;
3939
import org.junit.jupiter.api.Test;
4040

@@ -44,6 +44,7 @@
4444
public class TestListParts {
4545

4646
private ObjectEndpoint rest;
47+
private String uploadID;
4748

4849
@BeforeEach
4950
public void setUp() throws Exception {
@@ -66,21 +67,34 @@ public void setUp() throws Exception {
6667
OzoneConsts.KEY);
6768
MultipartUploadInitiateResponse multipartUploadInitiateResponse =
6869
(MultipartUploadInitiateResponse) response.getEntity();
69-
String uploadID = multipartUploadInitiateResponse.getUploadID();
70-
assertNotNull(uploadID);
70+
assertNotNull(multipartUploadInitiateResponse.getUploadID());
71+
uploadID = multipartUploadInitiateResponse.getUploadID();
72+
7173
assertEquals(200, response.getStatus());
7274

7375
String content = "Multipart Upload";
74-
for (int i = 1; i <= 3; i++) {
75-
response = put(rest, OzoneConsts.S3_BUCKET, OzoneConsts.KEY, i, uploadID, content);
76-
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
77-
}
76+
ByteArrayInputStream body =
77+
new ByteArrayInputStream(content.getBytes(UTF_8));
78+
response = rest.put(OzoneConsts.S3_BUCKET, OzoneConsts.KEY,
79+
content.length(), 1, uploadID, null, null, body);
80+
81+
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
82+
83+
response = rest.put(OzoneConsts.S3_BUCKET, OzoneConsts.KEY,
84+
content.length(), 2, uploadID, null, null, body);
85+
86+
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
87+
88+
response = rest.put(OzoneConsts.S3_BUCKET, OzoneConsts.KEY,
89+
content.length(), 3, uploadID, null, null, body);
90+
91+
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
7892
}
7993

8094
@Test
8195
public void testListParts() throws Exception {
82-
rest.queryParamsForTest().set(S3Consts.QueryParams.PART_NUMBER_MARKER, "0");
83-
Response response = rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0, 3);
96+
Response response = rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0,
97+
uploadID, 3, "0", null);
8498

8599
ListPartsResponse listPartsResponse =
86100
(ListPartsResponse) response.getEntity();
@@ -92,18 +106,17 @@ public void testListParts() throws Exception {
92106

93107
@Test
94108
public void testListPartsContinuation() throws Exception {
95-
rest.queryParamsForTest().set(S3Consts.QueryParams.PART_NUMBER_MARKER, "0");
96-
Response response = rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0, 2);
109+
Response response = rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0,
110+
uploadID, 2, "0", null);
97111
ListPartsResponse listPartsResponse =
98112
(ListPartsResponse) response.getEntity();
99113

100114
assertTrue(listPartsResponse.getTruncated());
101115
assertEquals(2, listPartsResponse.getPartList().size());
102116

103117
// Continue
104-
rest.queryParamsForTest().set(S3Consts.QueryParams.PART_NUMBER_MARKER,
105-
Integer.toString(listPartsResponse.getNextPartNumberMarker()));
106-
response = rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0, 2);
118+
response = rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0, uploadID, 2,
119+
Integer.toString(listPartsResponse.getNextPartNumberMarker()), null);
107120
listPartsResponse = (ListPartsResponse) response.getEntity();
108121

109122
assertFalse(listPartsResponse.getTruncated());
@@ -113,10 +126,9 @@ public void testListPartsContinuation() throws Exception {
113126

114127
@Test
115128
public void testListPartsWithUnknownUploadID() throws Exception {
116-
rest.queryParamsForTest().set(S3Consts.QueryParams.PART_NUMBER_MARKER, "0");
117-
rest.queryParamsForTest().set(S3Consts.QueryParams.UPLOAD_ID, "no-such-upload");
118129
try {
119-
rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0, 2);
130+
rest.get(OzoneConsts.S3_BUCKET, OzoneConsts.KEY, 0,
131+
uploadID, 2, "0", null);
120132
} catch (OS3Exception ex) {
121133
assertEquals(S3ErrorTable.NO_SUCH_UPLOAD.getErrorMessage(),
122134
ex.getErrorMessage());

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.hadoop.ozone.s3.endpoint;
1919

20-
import static org.apache.hadoop.ozone.s3.endpoint.EndpointTestUtils.put;
20+
import static java.nio.charset.StandardCharsets.UTF_8;
2121
import static org.apache.hadoop.ozone.s3.util.S3Consts.CUSTOM_METADATA_HEADER_PREFIX;
2222
import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CLASS_HEADER;
2323
import static org.apache.hadoop.ozone.s3.util.S3Consts.X_AMZ_CONTENT_SHA256;
@@ -27,6 +27,7 @@
2727
import static org.mockito.Mockito.mock;
2828
import static org.mockito.Mockito.when;
2929

30+
import java.io.ByteArrayInputStream;
3031
import java.io.IOException;
3132
import java.util.ArrayList;
3233
import java.util.Collections;
@@ -44,7 +45,6 @@
4445
import org.apache.hadoop.ozone.s3.endpoint.CompleteMultipartUploadRequest.Part;
4546
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
4647
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
47-
import org.apache.hadoop.ozone.s3.util.S3Consts;
4848
import org.junit.jupiter.api.BeforeEach;
4949
import org.junit.jupiter.api.Test;
5050

@@ -104,7 +104,10 @@ private String initiateMultipartUpload(String key, Map<String, String> metadata)
104104

105105
private Part uploadPart(String key, String uploadID, int partNumber, String
106106
content) throws IOException, OS3Exception {
107-
Response response = put(rest, OzoneConsts.S3_BUCKET, key, partNumber, uploadID, content);
107+
ByteArrayInputStream body =
108+
new ByteArrayInputStream(content.getBytes(UTF_8));
109+
Response response = rest.put(OzoneConsts.S3_BUCKET, key, content.length(),
110+
partNumber, uploadID, null, null, body);
108111
assertEquals(200, response.getStatus());
109112
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
110113
Part part = new Part();
@@ -117,9 +120,8 @@ private Part uploadPart(String key, String uploadID, int partNumber, String
117120
private void completeMultipartUpload(String key,
118121
CompleteMultipartUploadRequest completeMultipartUploadRequest,
119122
String uploadID) throws IOException, OS3Exception {
120-
rest.queryParamsForTest().set(S3Consts.QueryParams.UPLOAD_ID, uploadID);
121123
Response response = rest.completeMultipartUpload(OzoneConsts.S3_BUCKET, key,
122-
completeMultipartUploadRequest);
124+
uploadID, completeMultipartUploadRequest);
123125

124126
assertEquals(200, response.getStatus());
125127

0 commit comments

Comments
 (0)