hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [hadoop] ajayydv commented on a change in pull request #874: HDDS-1540. Implement addAcl, removeAcl, setAcl, getAcl for Bucket. Contributed by Ajay Kumar.
Date Thu, 30 May 2019 23:32:25 GMT
ajayydv commented on a change in pull request #874: HDDS-1540. Implement addAcl,removeAcl,setAcl,getAcl
for Bucket. Contributed by Ajay Kumar.
URL: https://github.com/apache/hadoop/pull/874#discussion_r289210837
 
 

 ##########
 File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/BucketManagerImpl.java
 ##########
 @@ -423,4 +428,205 @@ private void commitDeleteBucketInfoToOMDB(String dbBucketKey)
         volumeName, startBucket, bucketPrefix, maxNumOfBuckets);
 
   }
+
+  /**
+   * Add acl for Ozone object. Return true if acl is added successfully else
+   * false.
+   *
+   * @param obj Ozone object for which acl should be added.
+   * @param acl ozone acl top be added.
+   * @throws IOException if there is error.
+   */
+  @Override
+  public boolean addAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
+    Objects.requireNonNull(obj);
+    Objects.requireNonNull(acl);
+    if (!obj.getResourceType().equals(OzoneObj.ResourceType.BUCKET)) {
+      throw new IllegalArgumentException("Unexpected argument passed to " +
+          "BucketManager. OzoneObj type:" + obj.getResourceType());
+    }
+    String volume = obj.getVolumeName();
+    String bucket = obj.getBucketName();
+    metadataManager.getLock().acquireBucketLock(volume, bucket);
+    try {
+      String dbBucketKey = metadataManager.getBucketKey(volume, bucket);
+      OmBucketInfo bucketInfo =
+          metadataManager.getBucketTable().get(dbBucketKey);
+      if (bucketInfo == null) {
+        LOG.debug("Bucket:{}/{} does not exist", volume, bucket);
+        throw new OMException("Bucket " + bucket + " is not found",
+            BUCKET_NOT_FOUND);
+      }
+      List<OzoneAcl> list = bucketInfo.getAcls();
+      list.add(acl);
+      OmBucketInfo updatedBucket = OmBucketInfo.newBuilder()
+          .setVolumeName(bucketInfo.getVolumeName())
+          .setBucketName(bucketInfo.getBucketName())
+          .setStorageType(bucketInfo.getStorageType())
+          .setIsVersionEnabled(bucketInfo.getIsVersionEnabled())
+          .setCreationTime(bucketInfo.getCreationTime())
+          .setBucketEncryptionKey(bucketInfo.getEncryptionKeyInfo())
+          .addAllMetadata(bucketInfo.getMetadata())
+          .setAcls(list)
+          .build();
+
+      metadataManager.getBucketTable().put(dbBucketKey, updatedBucket);
+    } catch (IOException ex) {
+      if (!(ex instanceof OMException)) {
+        LOG.error("Add acl operation failed for bucket:{}/{} acl:{}",
+            volume, bucket, acl, ex);
+      }
+      throw ex;
+    } finally {
+      metadataManager.getLock().releaseBucketLock(volume, bucket);
+    }
+
+    return true;
+  }
+
+  /**
+   * Remove acl for Ozone object. Return true if acl is removed successfully
+   * else false.
+   *
+   * @param obj Ozone object.
+   * @param acl Ozone acl to be removed.
+   * @throws IOException if there is error.
+   */
+  @Override
+  public boolean removeAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
+    Objects.requireNonNull(obj);
+    Objects.requireNonNull(acl);
+    if (!obj.getResourceType().equals(OzoneObj.ResourceType.BUCKET)) {
+      throw new IllegalArgumentException("Unexpected argument passed to " +
+          "BucketManager. OzoneObj type:" + obj.getResourceType());
+    }
+    String volume = obj.getVolumeName();
+    String bucket = obj.getBucketName();
+    metadataManager.getLock().acquireBucketLock(volume, bucket);
+    try {
+      String dbBucketKey = metadataManager.getBucketKey(volume, bucket);
+      OmBucketInfo bucketInfo =
+          metadataManager.getBucketTable().get(dbBucketKey);
+      if (bucketInfo == null) {
+        LOG.debug("Bucket:{}/{} does not exist", volume, bucket);
+        throw new OMException("Bucket " + bucket + " is not found",
+            BUCKET_NOT_FOUND);
+      }
+      List<OzoneAcl> list = bucketInfo.getAcls();
+      list.remove(acl);
 
 Review comment:
   added check which return false if it doesn't exist.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org


Mime
View raw message