You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/03/10 14:55:51 UTC

[GitHub] [ozone] sadanand48 opened a new pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

sadanand48 opened a new pull request #2024:
URL: https://github.com/apache/ozone/pull/2024


   ## What changes were proposed in this pull request?
   Implement ACL api's like getAcl, addAcl, setAcl ,removeAcl in the new layout V1.
   
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/HDDS-4917
   
   ## How was this patch tested?
   Added Unit test
   


----------------------------------------------------------------
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



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


[GitHub] [ozone] rakeshadr commented on a change in pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #2024:
URL: https://github.com/apache/ozone/pull/2024#discussion_r594049834



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/acl/OMKeyAclRequestV1.java
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.request.key.acl;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.ObjectParser;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+
+import java.io.IOException;
+import java.util.Map;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+
+/**
+ * Handles key ACL requests layout version V1.
+ */
+public abstract class OMKeyAclRequestV1 extends OMKeyAclRequest {
+
+  public OMKeyAclRequestV1(OzoneManagerProtocolProtos.OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    OmKeyInfo omKeyInfo = null;
+
+    OzoneManagerProtocolProtos.OMResponse.Builder omResponse = onInit();
+    OMClientResponse omClientResponse = null;
+    IOException exception = null;
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    boolean lockAcquired = false;
+    String volume = null;
+    String bucket = null;
+    String key = null;
+    boolean operationResult = false;
+    Result result = null;
+    try {
+      ObjectParser objectParser = new ObjectParser(getPath(),
+          OzoneManagerProtocolProtos.OzoneObj.ObjectType.KEY);
+
+      volume = objectParser.getVolume();
+      bucket = objectParser.getBucket();
+      key = objectParser.getKey();
+
+      // check Acl
+      if (ozoneManager.getAclsEnabled()) {
+        checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME,
+            OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL,
+            volume, bucket, key);
+      }
+      lockAcquired = omMetadataManager.getLock()
+          .acquireWriteLock(BUCKET_LOCK, volume, bucket);
+      OzoneFileStatus keyStatus = OMFileRequest
+          .getOMKeyInfoIfExists(omMetadataManager, volume, bucket, key, 0);
+      if (keyStatus == null) {
+        throw new OMException("Key not found. Key:" + key, KEY_NOT_FOUND);
+      }
+      omKeyInfo = keyStatus.getKeyInfo();
+      String dbKey = omKeyInfo.getPath();
+      boolean isDirectory = keyStatus.isDirectory();
+      operationResult = apply(omKeyInfo, trxnLogIndex);
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      // Update the modification time when updating ACLs of Key.
+      long modificationTime = omKeyInfo.getModificationTime();
+      if (getOmRequest().getAddAclRequest().hasObj() && operationResult) {
+        modificationTime =
+            getOmRequest().getAddAclRequest().getModificationTime();
+      } else if (getOmRequest().getSetAclRequest().hasObj()) {
+        modificationTime =
+            getOmRequest().getSetAclRequest().getModificationTime();
+      } else if (getOmRequest().getRemoveAclRequest().hasObj()
+          && operationResult) {
+        modificationTime =
+            getOmRequest().getRemoveAclRequest().getModificationTime();
+      }
+      omKeyInfo.setModificationTime(modificationTime);
+
+      // update cache.
+      if (isDirectory) {
+        Table<String, OmDirectoryInfo> dirTable =
+            omMetadataManager.getDirectoryTable();
+        dirTable.addCacheEntry(new CacheKey<>(dbKey),
+            new CacheValue<>(Optional.of(OMFileRequest.
+                getDirectoryInfo(omKeyInfo)), trxnLogIndex));
+      } else {
+        omMetadataManager.getKeyTable().addCacheEntry(new CacheKey<>(dbKey),
+            new CacheValue<>(Optional.of(omKeyInfo), trxnLogIndex));
+      }
+      omClientResponse =
+          onSuccess(omResponse, omKeyInfo, operationResult, isDirectory);
+      result = Result.SUCCESS;
+    } catch (IOException ex) {
+      result = Result.FAILURE;
+      exception = ex;
+      omClientResponse = onFailure(omResponse, ex);

Review comment:
       Thanks @sadanand48 for the good work!
   
   Could you override this method and then return `new OMKeyAclResponseV1()`, this is to ensure that the V1 tables - dir and file tables are cleaned up.




----------------------------------------------------------------
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



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


[GitHub] [ozone] linyiqun commented on a change in pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
linyiqun commented on a change in pull request #2024:
URL: https://github.com/apache/ozone/pull/2024#discussion_r593276437



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/acl/OMKeyAddAclRequestV1.java
##########
@@ -0,0 +1,149 @@
+/**
+ * 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.request.key.acl;
+
+import com.google.common.collect.Lists;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.key.acl.OMKeyAclResponse;
+import org.apache.hadoop.ozone.om.response.key.acl.OMKeyAclResponseV1;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
+import org.apache.hadoop.util.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Handle add Acl request for bucket for layout version V1.
+ */
+public class OMKeyAddAclRequestV1 extends OMKeyAclRequestV1 {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OMKeyAddAclRequestV1.class);
+
+  @Override public OzoneManagerProtocolProtos.OMRequest preExecute(
+      OzoneManager ozoneManager) throws IOException {
+    long modificationTime = Time.now();
+    OzoneManagerProtocolProtos.AddAclRequest.Builder addAclRequestBuilder =
+        getOmRequest().getAddAclRequest().toBuilder()
+            .setModificationTime(modificationTime);
+
+    return getOmRequest().toBuilder().setAddAclRequest(addAclRequestBuilder)
+        .setUserInfo(getUserInfo()).build();
+  }
+
+  private String path;
+  private List<OzoneAcl> ozoneAcls;
+  private OzoneObj obj;
+
+  public OMKeyAddAclRequestV1(OzoneManagerProtocolProtos.OMRequest omRequest) {
+    super(omRequest);
+    OzoneManagerProtocolProtos.AddAclRequest addAclRequest =
+        getOmRequest().getAddAclRequest();
+    obj = OzoneObjInfo.fromProtobuf(addAclRequest.getObj());
+    path = obj.getPath();
+    ozoneAcls =
+        Lists.newArrayList(OzoneAcl.fromProtobuf(addAclRequest.getAcl()));
+  }
+
+  @Override String getPath() {
+    return path;
+  }
+
+  @Override OzoneObj getObject() {
+    return obj;
+  }
+
+  @Override OzoneManagerProtocolProtos.OMResponse.Builder onInit() {
+    return OmResponseUtil.getOMResponseBuilder(getOmRequest());
+  }
+
+  @Override OMClientResponse onSuccess(
+      OzoneManagerProtocolProtos.OMResponse.Builder omResponse,
+      OmKeyInfo omKeyInfo, boolean operationResult) {
+    omResponse.setSuccess(operationResult);
+    omResponse.setAddAclResponse(
+        OzoneManagerProtocolProtos.AddAclResponse.newBuilder()
+            .setResponse(operationResult));
+    return new OMKeyAclResponse(omResponse.build(), omKeyInfo);
+  }
+
+  @Override void onComplete(Result result, boolean operationResult,
+      IOException exception, long trxnLogIndex, AuditLogger auditLogger,
+      Map<String, String> auditMap) {
+    switch (result) {
+    case SUCCESS:
+      if (LOG.isDebugEnabled()) {
+        if (operationResult) {
+          LOG.debug("Add acl: {} to path: {} success!", ozoneAcls, path);
+        } else {
+          LOG.debug("Acl {} already exists in path {}", ozoneAcls, path);
+        }
+      }
+      break;
+    case FAILURE:
+      LOG.error("Add acl {} to path {} failed!", ozoneAcls, path, exception);
+      break;
+    default:
+      LOG.error("Unrecognized Result for OMKeyAddAclRequest: {}",
+          getOmRequest());
+    }
+
+    if (ozoneAcls != null) {
+      auditMap.put(OzoneConsts.ACL, ozoneAcls.toString());
+    }
+    auditLog(auditLogger,
+        buildAuditMessage(OMAction.ADD_ACL, auditMap, exception,
+            getOmRequest().getUserInfo()));
+  }
+
+  @Override boolean apply(OmKeyInfo omKeyInfo, long trxnLogIndex) {
+    // No need to check not null here, this will be never called with null.
+    return omKeyInfo.addAcl(ozoneAcls.get(0));
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    ozoneManager.getMetrics().incNumAddAcl();
+    return super.validateAndUpdateCache(ozoneManager, trxnLogIndex,
+        omDoubleBufferHelper);
+  }
+
+  @Override OMClientResponse onSuccess(
+      OzoneManagerProtocolProtos.OMResponse.Builder omResponse,
+      OmKeyInfo omKeyInfo, boolean operationResult, boolean isDirectory) {
+    omResponse.setSuccess(operationResult);
+    omResponse.setSetAclResponse(
+        OzoneManagerProtocolProtos.SetAclResponse.newBuilder()

Review comment:
       Seems here should be:
   ```java
   omResponse.setAddAclResponse(
           OzoneManagerProtocolProtos.AddAclResponse.newBuilder()
   ```
   

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/acl/OMKeyRemoveAclRequestV1.java
##########
@@ -0,0 +1,153 @@
+/**
+ * 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.request.key.acl;
+
+import com.google.common.collect.Lists;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.key.acl.OMKeyAclResponse;
+import org.apache.hadoop.ozone.om.response.key.acl.OMKeyAclResponseV1;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
+import org.apache.hadoop.util.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Handle remove Acl request for bucket for layout version V1.
+ */
+public class OMKeyRemoveAclRequestV1 extends OMKeyAclRequestV1 {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OMKeyRemoveAclRequestV1.class);
+
+  @Override public OzoneManagerProtocolProtos.OMRequest preExecute(
+      OzoneManager ozoneManager) throws IOException {
+    long modificationTime = Time.now();
+    OzoneManagerProtocolProtos.RemoveAclRequest.Builder
+        removeAclRequestBuilder =
+        getOmRequest().getRemoveAclRequest().toBuilder()
+            .setModificationTime(modificationTime);
+
+    return getOmRequest().toBuilder()
+        .setRemoveAclRequest(removeAclRequestBuilder).setUserInfo(getUserInfo())
+        .build();
+  }
+
+  private String path;
+  private List<OzoneAcl> ozoneAcls;
+  private OzoneObj obj;
+
+  public OMKeyRemoveAclRequestV1(
+      OzoneManagerProtocolProtos.OMRequest omRequest) {
+    super(omRequest);
+    OzoneManagerProtocolProtos.RemoveAclRequest removeAclRequest =
+        getOmRequest().getRemoveAclRequest();
+    obj = OzoneObjInfo.fromProtobuf(removeAclRequest.getObj());
+    path = obj.getPath();
+    ozoneAcls =
+        Lists.newArrayList(OzoneAcl.fromProtobuf(removeAclRequest.getAcl()));
+  }
+
+  @Override String getPath() {
+    return path;
+  }
+
+  @Override OzoneObj getObject() {
+    return obj;
+  }
+
+  @Override OzoneManagerProtocolProtos.OMResponse.Builder onInit() {
+    return OmResponseUtil.getOMResponseBuilder(getOmRequest());
+  }
+
+  @Override OMClientResponse onSuccess(
+      OzoneManagerProtocolProtos.OMResponse.Builder omResponse,
+      OmKeyInfo omKeyInfo, boolean operationResult) {
+    omResponse.setSuccess(operationResult);
+    omResponse.setRemoveAclResponse(
+        OzoneManagerProtocolProtos.RemoveAclResponse.newBuilder()
+            .setResponse(operationResult));
+    return new OMKeyAclResponse(omResponse.build(), omKeyInfo);
+  }
+
+  @Override void onComplete(Result result, boolean operationResult,
+      IOException exception, long trxnLogIndex, AuditLogger auditLogger,
+      Map<String, String> auditMap) {
+    switch (result) {
+    case SUCCESS:
+      if (LOG.isDebugEnabled()) {
+        if (operationResult) {
+          LOG.debug("Remove acl: {} to path: {} success!", ozoneAcls, path);
+        } else {
+          LOG.debug("Acl {} not removed from path {} as it does not exist",
+              ozoneAcls, path);
+        }
+      }
+      break;
+    case FAILURE:
+      LOG.error("Remove acl {} to path {} failed!", ozoneAcls, path, exception);
+      break;
+    default:
+      LOG.error("Unrecognized Result for OMKeyRemoveAclRequest: {}",
+          getOmRequest());
+    }
+
+    if (ozoneAcls != null) {
+      auditMap.put(OzoneConsts.ACL, ozoneAcls.toString());
+    }
+    auditLog(auditLogger,
+        buildAuditMessage(OMAction.REMOVE_ACL, auditMap, exception,
+            getOmRequest().getUserInfo()));
+  }
+
+  @Override boolean apply(OmKeyInfo omKeyInfo, long trxnLogIndex) {
+    // No need to check not null here, this will be never called with null.
+    return omKeyInfo.removeAcl(ozoneAcls.get(0));
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    ozoneManager.getMetrics().incNumRemoveAcl();
+    return super.validateAndUpdateCache(ozoneManager, trxnLogIndex,
+        omDoubleBufferHelper);
+  }
+
+  @Override OMClientResponse onSuccess(
+      OzoneManagerProtocolProtos.OMResponse.Builder omResponse,
+      OmKeyInfo omKeyInfo, boolean operationResult, boolean isDirectory) {
+    omResponse.setSuccess(operationResult);
+    omResponse.setSetAclResponse(
+        OzoneManagerProtocolProtos.SetAclResponse.newBuilder()

Review comment:
       The similar problem, expected:  
    omResponse.setRemoveAclResponse(
           OzoneManagerProtocolProtos.RemoveAclResponse.newBuilder()




----------------------------------------------------------------
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



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


[GitHub] [ozone] rakeshadr commented on pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on pull request #2024:
URL: https://github.com/apache/ozone/pull/2024#issuecomment-799537176


   +1 patch looks good to me.
   
   Thanks @sadanand48 for the contribution. Thanks a lot @linyiqun for the reviews.


----------------------------------------------------------------
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



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


[GitHub] [ozone] rakeshadr commented on pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on pull request #2024:
URL: https://github.com/apache/ozone/pull/2024#issuecomment-799543852


   @xiaoyuyao this patch is expecting prefixes and the key should exist in DB. Otw, it will throw Key_Not_Found exception. IIRC, we have discussed this case of non-existent path and not required to handle this case. Could you please add your thoughts. Thanks!
   
   IMHO, I am open to discuss this point and if we need to support then it can be handled separately in a new jira. I'm merging this PR now.


----------------------------------------------------------------
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



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


[GitHub] [ozone] rakeshadr merged pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
rakeshadr merged pull request #2024:
URL: https://github.com/apache/ozone/pull/2024


   


----------------------------------------------------------------
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



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


[GitHub] [ozone] sadanand48 commented on a change in pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
sadanand48 commented on a change in pull request #2024:
URL: https://github.com/apache/ozone/pull/2024#discussion_r593303562



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/acl/OMKeyRemoveAclRequestV1.java
##########
@@ -0,0 +1,153 @@
+/**
+ * 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.request.key.acl;
+
+import com.google.common.collect.Lists;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.AuditLogger;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.key.acl.OMKeyAclResponse;
+import org.apache.hadoop.ozone.om.response.key.acl.OMKeyAclResponseV1;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
+import org.apache.hadoop.util.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Handle remove Acl request for bucket for layout version V1.
+ */
+public class OMKeyRemoveAclRequestV1 extends OMKeyAclRequestV1 {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(OMKeyRemoveAclRequestV1.class);
+
+  @Override public OzoneManagerProtocolProtos.OMRequest preExecute(
+      OzoneManager ozoneManager) throws IOException {
+    long modificationTime = Time.now();
+    OzoneManagerProtocolProtos.RemoveAclRequest.Builder
+        removeAclRequestBuilder =
+        getOmRequest().getRemoveAclRequest().toBuilder()
+            .setModificationTime(modificationTime);
+
+    return getOmRequest().toBuilder()
+        .setRemoveAclRequest(removeAclRequestBuilder).setUserInfo(getUserInfo())
+        .build();
+  }
+
+  private String path;
+  private List<OzoneAcl> ozoneAcls;
+  private OzoneObj obj;
+
+  public OMKeyRemoveAclRequestV1(
+      OzoneManagerProtocolProtos.OMRequest omRequest) {
+    super(omRequest);
+    OzoneManagerProtocolProtos.RemoveAclRequest removeAclRequest =
+        getOmRequest().getRemoveAclRequest();
+    obj = OzoneObjInfo.fromProtobuf(removeAclRequest.getObj());
+    path = obj.getPath();
+    ozoneAcls =
+        Lists.newArrayList(OzoneAcl.fromProtobuf(removeAclRequest.getAcl()));
+  }
+
+  @Override String getPath() {
+    return path;
+  }
+
+  @Override OzoneObj getObject() {
+    return obj;
+  }
+
+  @Override OzoneManagerProtocolProtos.OMResponse.Builder onInit() {
+    return OmResponseUtil.getOMResponseBuilder(getOmRequest());
+  }
+
+  @Override OMClientResponse onSuccess(
+      OzoneManagerProtocolProtos.OMResponse.Builder omResponse,
+      OmKeyInfo omKeyInfo, boolean operationResult) {
+    omResponse.setSuccess(operationResult);
+    omResponse.setRemoveAclResponse(
+        OzoneManagerProtocolProtos.RemoveAclResponse.newBuilder()
+            .setResponse(operationResult));
+    return new OMKeyAclResponse(omResponse.build(), omKeyInfo);
+  }
+
+  @Override void onComplete(Result result, boolean operationResult,
+      IOException exception, long trxnLogIndex, AuditLogger auditLogger,
+      Map<String, String> auditMap) {
+    switch (result) {
+    case SUCCESS:
+      if (LOG.isDebugEnabled()) {
+        if (operationResult) {
+          LOG.debug("Remove acl: {} to path: {} success!", ozoneAcls, path);
+        } else {
+          LOG.debug("Acl {} not removed from path {} as it does not exist",
+              ozoneAcls, path);
+        }
+      }
+      break;
+    case FAILURE:
+      LOG.error("Remove acl {} to path {} failed!", ozoneAcls, path, exception);
+      break;
+    default:
+      LOG.error("Unrecognized Result for OMKeyRemoveAclRequest: {}",
+          getOmRequest());
+    }
+
+    if (ozoneAcls != null) {
+      auditMap.put(OzoneConsts.ACL, ozoneAcls.toString());
+    }
+    auditLog(auditLogger,
+        buildAuditMessage(OMAction.REMOVE_ACL, auditMap, exception,
+            getOmRequest().getUserInfo()));
+  }
+
+  @Override boolean apply(OmKeyInfo omKeyInfo, long trxnLogIndex) {
+    // No need to check not null here, this will be never called with null.
+    return omKeyInfo.removeAcl(ozoneAcls.get(0));
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    ozoneManager.getMetrics().incNumRemoveAcl();
+    return super.validateAndUpdateCache(ozoneManager, trxnLogIndex,
+        omDoubleBufferHelper);
+  }
+
+  @Override OMClientResponse onSuccess(
+      OzoneManagerProtocolProtos.OMResponse.Builder omResponse,
+      OmKeyInfo omKeyInfo, boolean operationResult, boolean isDirectory) {
+    omResponse.setSuccess(operationResult);
+    omResponse.setSetAclResponse(
+        OzoneManagerProtocolProtos.SetAclResponse.newBuilder()

Review comment:
       Thanks @linyiqun for pointing this out.




----------------------------------------------------------------
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



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


[GitHub] [ozone] sadanand48 commented on a change in pull request #2024: HDDS-4917.[FSO]Implement ACL requests for new layout

Posted by GitBox <gi...@apache.org>.
sadanand48 commented on a change in pull request #2024:
URL: https://github.com/apache/ozone/pull/2024#discussion_r594066221



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/acl/OMKeyAclRequestV1.java
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.request.key.acl;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.ObjectParser;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+
+import java.io.IOException;
+import java.util.Map;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+
+/**
+ * Handles key ACL requests layout version V1.
+ */
+public abstract class OMKeyAclRequestV1 extends OMKeyAclRequest {
+
+  public OMKeyAclRequestV1(OzoneManagerProtocolProtos.OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    OmKeyInfo omKeyInfo = null;
+
+    OzoneManagerProtocolProtos.OMResponse.Builder omResponse = onInit();
+    OMClientResponse omClientResponse = null;
+    IOException exception = null;
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    boolean lockAcquired = false;
+    String volume = null;
+    String bucket = null;
+    String key = null;
+    boolean operationResult = false;
+    Result result = null;
+    try {
+      ObjectParser objectParser = new ObjectParser(getPath(),
+          OzoneManagerProtocolProtos.OzoneObj.ObjectType.KEY);
+
+      volume = objectParser.getVolume();
+      bucket = objectParser.getBucket();
+      key = objectParser.getKey();
+
+      // check Acl
+      if (ozoneManager.getAclsEnabled()) {
+        checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME,
+            OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL,
+            volume, bucket, key);
+      }
+      lockAcquired = omMetadataManager.getLock()
+          .acquireWriteLock(BUCKET_LOCK, volume, bucket);
+      OzoneFileStatus keyStatus = OMFileRequest
+          .getOMKeyInfoIfExists(omMetadataManager, volume, bucket, key, 0);
+      if (keyStatus == null) {
+        throw new OMException("Key not found. Key:" + key, KEY_NOT_FOUND);
+      }
+      omKeyInfo = keyStatus.getKeyInfo();
+      String dbKey = omKeyInfo.getPath();
+      boolean isDirectory = keyStatus.isDirectory();
+      operationResult = apply(omKeyInfo, trxnLogIndex);
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      // Update the modification time when updating ACLs of Key.
+      long modificationTime = omKeyInfo.getModificationTime();
+      if (getOmRequest().getAddAclRequest().hasObj() && operationResult) {
+        modificationTime =
+            getOmRequest().getAddAclRequest().getModificationTime();
+      } else if (getOmRequest().getSetAclRequest().hasObj()) {
+        modificationTime =
+            getOmRequest().getSetAclRequest().getModificationTime();
+      } else if (getOmRequest().getRemoveAclRequest().hasObj()
+          && operationResult) {
+        modificationTime =
+            getOmRequest().getRemoveAclRequest().getModificationTime();
+      }
+      omKeyInfo.setModificationTime(modificationTime);
+
+      // update cache.
+      if (isDirectory) {
+        Table<String, OmDirectoryInfo> dirTable =
+            omMetadataManager.getDirectoryTable();
+        dirTable.addCacheEntry(new CacheKey<>(dbKey),
+            new CacheValue<>(Optional.of(OMFileRequest.
+                getDirectoryInfo(omKeyInfo)), trxnLogIndex));
+      } else {
+        omMetadataManager.getKeyTable().addCacheEntry(new CacheKey<>(dbKey),
+            new CacheValue<>(Optional.of(omKeyInfo), trxnLogIndex));
+      }
+      omClientResponse =
+          onSuccess(omResponse, omKeyInfo, operationResult, isDirectory);
+      result = Result.SUCCESS;
+    } catch (IOException ex) {
+      result = Result.FAILURE;
+      exception = ex;
+      omClientResponse = onFailure(omResponse, ex);

Review comment:
       Thanks @rakeshadr for the review comment . Addressed it.




----------------------------------------------------------------
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



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