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 @@ -1012,6 +1012,39 @@ private void teardownVolumeBucketWithDir(Path bucketPath1)
objectStore.deleteVolume(ofsPath.getVolumeName());
}

/**
* Create a bucket with a different owner than the volume owner
* and test the owner on listStatus.
*/
@Test
public void testListStatusWithDifferentBucketOwner() throws IOException {
String volName = getRandomNonExistVolumeName();
objectStore.createVolume(volName);
OzoneVolume ozoneVolume = objectStore.getVolume(volName);

String buckName = "bucket-" + RandomStringUtils.randomNumeric(5);
UserGroupInformation currUgi = UserGroupInformation.getCurrentUser();
String bucketOwner = currUgi.getUserName() + RandomStringUtils.randomNumeric(5);
BucketArgs bucketArgs = BucketArgs.newBuilder()
.setOwner(bucketOwner)
.build();
ozoneVolume.createBucket(buckName, bucketArgs);

Path volPath = new Path(OZONE_URI_DELIMITER + volName);

OzoneBucket ozoneBucket = ozoneVolume.getBucket(buckName);

FileStatus[] fileStatusVolume = ofs.listStatus(volPath);
assertEquals(1, fileStatusVolume.length);
// FileStatus owner is different from the volume owner.
// Owner is the same as the bucket owner returned by the ObjectStore.
assertNotEquals(ozoneVolume.getOwner(), fileStatusVolume[0].getOwner());
assertEquals(ozoneBucket.getOwner(), fileStatusVolume[0].getOwner());

ozoneVolume.deleteBucket(buckName);
objectStore.deleteVolume(volName);
}

/**
* OFS: Test non-recursive listStatus on root and volume.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,12 @@ private List<FileStatusAdapter> listStatusVolume(String volumeStr,
OFSPath ofsStartPath = new OFSPath(startPath, config);
// list buckets in the volume
OzoneVolume volume = objectStore.getVolume(volumeStr);
UserGroupInformation ugi =
UserGroupInformation.createRemoteUser(volume.getOwner());
String owner = ugi.getShortUserName();
String group = getGroupName(ugi);
Iterator<? extends OzoneBucket> iter =
volume.listBuckets(null, ofsStartPath.getBucketName());
List<FileStatusAdapter> res = new ArrayList<>();
while (iter.hasNext() && res.size() < numEntries) {
OzoneBucket bucket = iter.next();
res.add(getFileStatusAdapterForBucket(bucket, uri, owner, group));
res.add(getFileStatusAdapterForBucket(bucket, uri));
if (recursive) {
String pathStrNext = volumeStr + OZONE_URI_DELIMITER + bucket.getName();
res.addAll(listStatus(pathStrNext, recursive, startPath,
Expand Down Expand Up @@ -1161,12 +1157,9 @@ private static FileStatusAdapter getFileStatusAdapterForVolume(
* Generate a FileStatusAdapter for a bucket.
* @param ozoneBucket OzoneBucket object.
* @param uri Full URI to OFS root.
* @param owner Owner of the parent volume of the bucket.
* @param group Group of the parent volume of the bucket.
* @return FileStatusAdapter for a bucket.
*/
private static FileStatusAdapter getFileStatusAdapterForBucket(
OzoneBucket ozoneBucket, URI uri, String owner, String group) {
private static FileStatusAdapter getFileStatusAdapterForBucket(OzoneBucket ozoneBucket, URI uri) {
String pathStr = uri.toString() +
OZONE_URI_DELIMITER + ozoneBucket.getVolumeName() +
OZONE_URI_DELIMITER + ozoneBucket.getName();
Expand All @@ -1176,6 +1169,9 @@ private static FileStatusAdapter getFileStatusAdapterForBucket(
ozoneBucket.getName(), pathStr);
}
Path path = new Path(pathStr);
UserGroupInformation ugi = UserGroupInformation.createRemoteUser(ozoneBucket.getOwner());
String owner = ugi.getShortUserName();
String group = getGroupName(ugi);
return new FileStatusAdapter(0L, 0L, path, true, (short)0, 0L,
ozoneBucket.getCreationTime().getEpochSecond() * 1000, 0L,
FsPermission.getDirDefault().toShort(),
Expand Down