diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java index 272a12a492b..c7d19678c91 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java @@ -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. */ diff --git a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java index 193e080f0e0..8e9a6f4b9fb 100644 --- a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java +++ b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java @@ -790,16 +790,12 @@ private List 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 iter = volume.listBuckets(null, ofsStartPath.getBucketName()); List 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, @@ -1112,12 +1108,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(); @@ -1127,6 +1120,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(),