ajayydv commented on a change in pull request #927: HDDS-1543. Implement 
addAcl,removeAcl,setAcl,getAcl for Prefix. Contr…
URL: https://github.com/apache/hadoop/pull/927#discussion_r292158071
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/PrefixManagerImpl.java
 ##########
 @@ -0,0 +1,287 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.hadoop.ozone.om;
+
+import com.google.common.base.Strings;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.util.RadixNode;
+import org.apache.hadoop.ozone.util.RadixTree;
+import org.apache.hadoop.utils.db.*;
+import org.apache.hadoop.utils.db.Table.KeyValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.PREFIX_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType.PREFIX;
+
+/**
+ * Implementation of PreManager.
+ */
+public class PrefixManagerImpl implements PrefixManager {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(PrefixManagerImpl.class);
+
+  private final OMMetadataManager metadataManager;
+
+  // In-memory prefix tree to optimize ACL evaluation
+  private RadixTree<OmPrefixInfo> prefixTree;
+
+  public PrefixManagerImpl(OMMetadataManager metadataManager) {
+    this.metadataManager = metadataManager;
+    loadPrefixTree();
+  }
+
+  private void loadPrefixTree() {
+    prefixTree = new RadixTree<>();
+    try (TableIterator<String, ? extends
+        KeyValue<String, OmPrefixInfo>> iterator =
+             getMetadataManager().getPrefixTable().iterator()) {
+      iterator.seekToFirst();
+      while (iterator.hasNext()) {
+        KeyValue<String, OmPrefixInfo> kv = iterator.next();
+        prefixTree.insert(kv.getKey(), kv.getValue());
+      }
+    } catch (IOException ex) {
+      LOG.error("Fail to load prefix tree");
+    }
+  }
+
+
+  @Override
+  public OMMetadataManager getMetadataManager() {
+    return metadataManager;
+  }
+
+  /**
+   * 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 {
+    validateOzoneObj(obj);
+
+    String prefixPath = obj.getPath();
+    metadataManager.getLock().acquirePrefixLock(prefixPath);
+    try {
+      OmPrefixInfo prefixInfo =
+          metadataManager.getPrefixTable().get(prefixPath);
+      List<OzoneAcl> list = null;
+      if (prefixInfo != null) {
+        list = prefixInfo.getAcls();
+
+        if (list != null && list.contains(acl)) {
+          LOG.debug("acl {} exist for prefix path {}", acl, prefixPath);
+          return false;
+        }
+      }
+      if (list == null) {
+        list = new ArrayList<>();
+      }
+      list.add(acl);
 
 Review comment:
   at this point we should check if acl of same type and name exist. If it 
exist we should set the bit for new acls in existing acl instance.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to