Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,30 @@ public class BucketEndpoint extends EndpointBase {
* for more details.
*/
@GET
@SuppressWarnings({"parameternumber", "methodlength"})
@SuppressWarnings("methodlength")
public Response get(
@PathParam(BUCKET) String bucketName,
@QueryParam(QueryParams.DELIMITER) String delimiter,
@QueryParam(QueryParams.ENCODING_TYPE) String encodingType,
@QueryParam(QueryParams.MARKER) String marker,
@DefaultValue("1000") @QueryParam(QueryParams.MAX_KEYS) int maxKeys,
@QueryParam(QueryParams.PREFIX) String prefix,
@QueryParam(QueryParams.CONTINUATION_TOKEN) String continueToken,
@QueryParam(QueryParams.START_AFTER) String startAfter,
@QueryParam(QueryParams.UPLOADS) String uploads,
@QueryParam(QueryParams.ACL) String aclMarker,
@QueryParam(QueryParams.KEY_MARKER) String keyMarker,
@QueryParam(QueryParams.UPLOAD_ID_MARKER) String uploadIdMarker,
@DefaultValue("1000") @QueryParam(QueryParams.MAX_UPLOADS) int maxUploads
) throws OS3Exception, IOException {
long startNanos = Time.monotonicNowNanos();
S3GAction s3GAction = S3GAction.GET_BUCKET;
PerformanceStringBuilder perf = new PerformanceStringBuilder();

final String continueToken = getQueryParam(QueryParams.CONTINUATION_TOKEN);
final String delimiter = getQueryParam(QueryParams.DELIMITER);
final String encodingType = getQueryParam(QueryParams.ENCODING_TYPE);
final String marker = getQueryParam(QueryParams.MARKER);
String prefix = getQueryParam(QueryParams.PREFIX);
String startAfter = getQueryParam(QueryParams.START_AFTER);

Iterator<? extends OzoneKey> ozoneKeyIterator = null;
ContinueToken decodedToken =
ContinueToken.decodeFromString(continueToken);
OzoneBucket bucket = null;

try {
final String aclMarker = getQueryParam(QueryParams.ACL);
if (aclMarker != null) {
s3GAction = S3GAction.GET_ACL;
S3BucketAcl result = getAcl(bucketName);
Expand All @@ -138,8 +136,11 @@ public Response get(
return Response.ok(result, MediaType.APPLICATION_XML_TYPE).build();
}

final String uploads = getQueryParam(QueryParams.UPLOADS);
if (uploads != null) {
s3GAction = S3GAction.LIST_MULTIPART_UPLOAD;
final String uploadIdMarker = getQueryParam(QueryParams.UPLOAD_ID_MARKER);
final String keyMarker = getQueryParam(QueryParams.KEY_MARKER);
return listMultipartUploads(bucketName, prefix, keyMarker, uploadIdMarker, maxUploads);
}

Expand Down Expand Up @@ -307,13 +308,13 @@ private int validateMaxKeys(int maxKeys) throws OS3Exception {
@PUT
public Response put(
@PathParam(BUCKET) String bucketName,
@QueryParam(QueryParams.ACL) String aclMarker,
InputStream body
) throws IOException, OS3Exception {
long startNanos = Time.monotonicNowNanos();
S3GAction s3GAction = S3GAction.CREATE_BUCKET;

try {
final String aclMarker = getQueryParam(QueryParams.ACL);
if (aclMarker != null) {
s3GAction = S3GAction.PUT_ACL;
Response response = putAcl(bucketName, body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public abstract class EndpointBase {
protected static final AuditLogger AUDIT =
new AuditLogger(AuditLoggerType.S3GLOGGER);

protected String getQueryParam(String key) {
return getQueryParameters().getFirst(key);
}

public MultivaluedMap<String, String> getQueryParameters() {
return context.getUriInfo().getQueryParameters();
}

protected OzoneBucket getBucket(OzoneVolume volume, String bucketName)
throws OS3Exception, IOException {
OzoneBucket bucket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hadoop.ozone.client.OzoneClientStub;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void setup() throws IOException {
.setClient(client)
.setHeaders(headers)
.build();
bucketEndpoint.getQueryParameters().add(QueryParams.ACL, ACL_MARKER);
}

@AfterEach
Expand All @@ -81,8 +83,7 @@ public void clean() throws IOException {
public void testGetAcl() throws Exception {
when(parameterMap.containsKey(ACL_MARKER)).thenReturn(true);
Response response =
bucketEndpoint.get(BUCKET_NAME, null, null, null, 0, null,
null, null, null, ACL_MARKER, null, null, 0);
bucketEndpoint.get(BUCKET_NAME, 0, 0);
assertEquals(HTTP_OK, response.getStatus());
System.out.println(response.getEntity());
}
Expand All @@ -93,7 +94,7 @@ public void testSetAclWithNotSupportedGranteeType() throws Exception {
.thenReturn(S3Acl.ACLIdentityType.GROUP.getHeaderType() + "=root");
when(parameterMap.containsKey(ACL_MARKER)).thenReturn(true);
OS3Exception e = assertThrows(OS3Exception.class, () ->
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null));
bucketEndpoint.put(BUCKET_NAME, null));
assertEquals(e.getHttpCode(), HTTP_NOT_IMPLEMENTED);
}

Expand All @@ -103,7 +104,7 @@ public void testRead() throws Exception {
when(headers.getHeaderString(S3Acl.GRANT_READ))
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(1, getResponse.getAclList().getGrantList().size());
Expand All @@ -117,7 +118,7 @@ public void testWrite() throws Exception {
when(headers.getHeaderString(S3Acl.GRANT_WRITE))
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(1, getResponse.getAclList().getGrantList().size());
Expand All @@ -131,7 +132,7 @@ public void testReadACP() throws Exception {
when(headers.getHeaderString(S3Acl.GRANT_READ_CAP))
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse =
bucketEndpoint.getAcl(BUCKET_NAME);
Expand All @@ -146,7 +147,7 @@ public void testWriteACP() throws Exception {
when(headers.getHeaderString(S3Acl.GRANT_WRITE_CAP))
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(1, getResponse.getAclList().getGrantList().size());
Expand All @@ -160,7 +161,7 @@ public void testFullControl() throws Exception {
when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(1, getResponse.getAclList().getGrantList().size());
Expand All @@ -182,7 +183,7 @@ public void testCombination() throws Exception {
when(headers.getHeaderString(S3Acl.GRANT_FULL_CONTROL))
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(5, getResponse.getAclList().getGrantList().size());
Expand All @@ -195,7 +196,7 @@ public void testPutClearOldAcls() throws Exception {
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
// Put READ
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(1, getResponse.getAclList().getGrantList().size());
Expand All @@ -212,7 +213,7 @@ public void testPutClearOldAcls() throws Exception {
.thenReturn(S3Acl.ACLIdentityType.USER.getHeaderType() + "=root");
//Put WRITE
response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, null);
bucketEndpoint.put(BUCKET_NAME, null);
assertEquals(HTTP_OK, response.getStatus());
getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(1, getResponse.getAclList().getGrantList().size());
Expand All @@ -230,7 +231,7 @@ public void testAclInBodyWithGroupUser() {
.getResourceAsStream("groupAccessControlList.xml");
when(parameterMap.containsKey(ACL_MARKER)).thenReturn(true);
assertThrows(OS3Exception.class, () -> bucketEndpoint.put(
BUCKET_NAME, ACL_MARKER, inputBody));
BUCKET_NAME, inputBody));
}

@Test
Expand All @@ -239,7 +240,7 @@ public void testAclInBody() throws Exception {
.getResourceAsStream("userAccessControlList.xml");
when(parameterMap.containsKey(ACL_MARKER)).thenReturn(true);
Response response =
bucketEndpoint.put(BUCKET_NAME, ACL_MARKER, inputBody);
bucketEndpoint.put(BUCKET_NAME, inputBody);
assertEquals(HTTP_OK, response.getStatus());
S3BucketAcl getResponse = bucketEndpoint.getAcl(BUCKET_NAME);
assertEquals(2, getResponse.getAclList().getGrantList().size());
Expand Down
Loading