This is an automated email from the ASF dual-hosted git repository.

aswinshakil pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 077e09b89e HDDS-9950. 'ozone fs -ls' on volume shows the volume owner 
as the bucket owner (#5816)
077e09b89e is described below

commit 077e09b89e4d325243f0d29117a082d9da9a342f
Author: Christos Bisias <[email protected]>
AuthorDate: Wed Dec 20 23:20:08 2023 +0200

    HDDS-9950. 'ozone fs -ls' on volume shows the volume owner as the bucket 
owner (#5816)
---
 .../hadoop/fs/ozone/TestRootedOzoneFileSystem.java | 33 ++++++++++++++++++++++
 .../ozone/BasicRootedOzoneClientAdapterImpl.java   | 14 ++++-----
 2 files changed, 38 insertions(+), 9 deletions(-)

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 272a12a492..c7d19678c9 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 @@ public class TestRootedOzoneFileSystem {
     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 193e080f0e..8e9a6f4b9f 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 @@ public class BasicRootedOzoneClientAdapterImpl
     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,
@@ -1112,12 +1108,9 @@ public class BasicRootedOzoneClientAdapterImpl
    * 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 @@ public class BasicRootedOzoneClientAdapterImpl
               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(),


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to