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
10 changes: 8 additions & 2 deletions hadoop-ozone/dist/src/main/smoketest/s3/bucketlist.robot
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ ${BUCKET} generated
*** Test Cases ***

List buckets
${result} = Execute AWSS3APICli list-buckets | jq -r '.Buckets[].Name'
Should contain ${result} ${BUCKET}
${result} = Execute AWSS3APICli list-buckets
${bucket_names} = Execute echo '''${result}''' | jq -r '.Buckets[].Name'
Should contain ${bucket_names} ${BUCKET}
${ownerId} = Execute echo '''${result}''' | jq -r '.Owner.ID'
Should Not Be Equal ${ownerId} null
${ownerDisplayName} = Execute echo '''${result}''' | jq -r '.Owner.DisplayName'
Should Not Be Equal ${ownerDisplayName} null


Get bucket info with Ozone Shell to check the owner field
Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import org.apache.hadoop.ozone.s3.S3ClientFactory;
import org.apache.hadoop.ozone.s3.S3GatewayService;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ozone.test.OzoneTestBase;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -249,7 +250,7 @@ public void testBucketACLOperations() {
}

@Test
public void testListBuckets() {
public void testListBuckets() throws IOException {
List<String> bucketNames = new ArrayList<>();
for (int i = 0; i <= 5; i++) {
String bucketName = getBucketName(String.valueOf(i));
Expand All @@ -262,6 +263,14 @@ public void testListBuckets() {
.map(Bucket::getName).collect(Collectors.toList());

assertThat(listBucketNames).containsAll(bucketNames);

UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
String expectOwner = ugi.getShortUserName();

Owner s3AccountOwner = s3Client.getS3AccountOwner();

assertThat(s3AccountOwner.getDisplayName()).isEqualTo(expectOwner);
assertThat(s3AccountOwner.getId()).isEqualTo(expectOwner);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.s3.S3ClientFactory;
import org.apache.hadoop.ozone.s3.S3GatewayService;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ozone.test.OzoneTestBase;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
Expand All @@ -71,6 +72,7 @@
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
Expand Down Expand Up @@ -129,6 +131,20 @@ static void shutdownCluster() throws IOException {
}
}

@Test
public void listBuckets() throws Exception {
final String bucketName = getBucketName();
final String expectedOwner = UserGroupInformation.getCurrentUser().getUserName();

s3Client.createBucket(b -> b.bucket(bucketName));

ListBucketsResponse syncResponse = s3Client.listBuckets();
assertEquals(1, syncResponse.buckets().size());
assertEquals(bucketName, syncResponse.buckets().get(0).name());
assertEquals(expectedOwner, syncResponse.owner().displayName());
assertEquals(expectedOwner, syncResponse.owner().id());
}

@Test
public void testPutObject() {
final String bucketName = getBucketName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -236,11 +237,12 @@ protected void deleteS3Bucket(String s3BucketName)
* buckets if bucket prefix is null.
*
* @param prefix Bucket prefix to match
* @param volumeProcessor Volume processor to operate on volume
* @return {@code Iterator<OzoneBucket>}
*/
protected Iterator<? extends OzoneBucket> listS3Buckets(String prefix)
protected Iterator<? extends OzoneBucket> listS3Buckets(String prefix, Consumer<OzoneVolume> volumeProcessor)
throws IOException, OS3Exception {
return iterateBuckets(volume -> volume.listBuckets(prefix));
return iterateBuckets(volume -> volume.listBuckets(prefix), volumeProcessor);
}

/**
Expand All @@ -254,15 +256,18 @@ protected Iterator<? extends OzoneBucket> listS3Buckets(String prefix)
* @return {@code Iterator<OzoneBucket>}
*/
protected Iterator<? extends OzoneBucket> listS3Buckets(String prefix,
String previousBucket) throws IOException, OS3Exception {
return iterateBuckets(volume -> volume.listBuckets(prefix, previousBucket));
String previousBucket, Consumer<OzoneVolume> volumeProcessor) throws IOException, OS3Exception {
return iterateBuckets(volume -> volume.listBuckets(prefix, previousBucket), volumeProcessor);
}

private Iterator<? extends OzoneBucket> iterateBuckets(
Function<OzoneVolume, Iterator<? extends OzoneBucket>> query)
Function<OzoneVolume, Iterator<? extends OzoneBucket>> query,
Consumer<OzoneVolume> ownerSetter)
throws IOException, OS3Exception {
try {
return query.apply(getVolume());
OzoneVolume volume = getVolume();
ownerSetter.accept(volume);
return query.apply(volume);
} catch (OMException e) {
if (e.getResult() == ResultCodes.VOLUME_NOT_FOUND) {
return Collections.emptyIterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class ListBucketResponse {
@XmlElement(name = "Bucket")
private List<BucketMetadata> buckets = new ArrayList<>();

@XmlElement(name = "Owner")
private S3Owner owner;

public List<BucketMetadata> getBuckets() {
return buckets;
}
Expand All @@ -55,4 +58,12 @@ public void setBuckets(List<BucketMetadata> buckets) {
public void addBucket(BucketMetadata bucket) {
buckets.add(bucket);
}

public S3Owner getOwner() {
return owner;
}

public void setOwner(S3Owner owner) {
this.owner = owner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public Response get()
boolean auditSuccess = true;
try {
ListBucketResponse response = new ListBucketResponse();

Iterator<? extends OzoneBucket> bucketIterator;
try {
bucketIterator = listS3Buckets(null);
bucketIterator =
listS3Buckets(null, volume -> response.setOwner(new S3Owner(volume.getOwner(), volume.getOwner())));
} catch (Exception e) {
getMetrics().updateListS3BucketsFailureStats(startNanos);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientStub;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -32,6 +33,8 @@ public class TestRootList {
private OzoneClient clientStub;
private RootEndpoint rootEndpoint;

private static final String DEFAULT_VOLUME = OzoneConfigKeys.OZONE_S3_VOLUME_NAME_DEFAULT;

@BeforeEach
public void setup() throws Exception {

Expand All @@ -43,6 +46,7 @@ public void setup() throws Exception {
.setClient(clientStub)
.build();

clientStub.getObjectStore().createVolume(DEFAULT_VOLUME);

}

Expand All @@ -60,6 +64,8 @@ public void testListBucket() throws Exception {
}
response = (ListBucketResponse) rootEndpoint.get().getEntity();
assertEquals(10, response.getBucketsNum());
assertEquals("root", response.getOwner().getDisplayName());
assertEquals("root", response.getOwner().getId());
}

}