ZihanLi58 commented on a change in pull request #3457:
URL: https://github.com/apache/gobblin/pull/3457#discussion_r793177224



##########
File path: 
gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/CopyableFile.java
##########
@@ -354,6 +359,36 @@ public static OwnerAndPermission 
resolveReplicatedOwnerAndPermission(FileSystem
     return ownerAndPermissions;
   }
 
+  public static Map<String, OwnerAndPermission> 
resolveReplicatedAncestorOwnerAndPermissionsRecursively(FileSystem sourceFs, 
Path fromPath,
+      Path toPath, CopyConfiguration copyConfiguration) throws IOException {
+
+    Map<String, OwnerAndPermission> ownerAndPermissions = Maps.newHashMap();
+
+    // We only pass directories to this method anyways. Those directories 
themselves need permissions set.

Review comment:
       Should we add one check if you have assumption here?

##########
File path: 
gobblin-data-management/src/main/java/org/apache/gobblin/util/commit/SetPermissionCommitStep.java
##########
@@ -0,0 +1,80 @@
+/*
+ * 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
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.gobblin.util.commit;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.security.AccessControlException;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.commit.CommitStep;
+import org.apache.gobblin.data.management.copy.OwnerAndPermission;
+
+/**
+ * An implementation of {@link CommitStep} for setting any file permissions.
+ * Current implementation only sets permissions, but it is capable of setting 
owner and group as well.
+ */
+@Slf4j
+public class SetPermissionCommitStep implements CommitStep {
+  Map<String, OwnerAndPermission> pathAndPermissions;
+  private final URI fsUri;
+  public final boolean stopOnError;
+  public static final String STOP_ON_ERROR_KEY = "stop.on.error";
+  public static final String DEFAULT_STOP_ON_ERROR = "false";
+  private boolean isCompleted = false;
+
+  public SetPermissionCommitStep(FileSystem targetFs, Map<String, 
OwnerAndPermission> pathAndPermissions,
+      Properties props) {
+    this.pathAndPermissions = pathAndPermissions;
+    this.fsUri = targetFs.getUri();
+    this.stopOnError = 
Boolean.parseBoolean(props.getProperty(STOP_ON_ERROR_KEY, 
DEFAULT_STOP_ON_ERROR));
+  }
+
+  @Override
+  public boolean isCompleted() throws IOException {
+    return isCompleted;
+  }
+
+  @Override
+  public void execute() throws IOException {
+    FileSystem fs = FileSystem.get(this.fsUri, new Configuration());
+
+    for (Map.Entry<String, OwnerAndPermission> entry : 
pathAndPermissions.entrySet()) {
+      Path path = new Path(entry.getKey());
+      try {
+        log.info("Setting permission {} on path {}", 
entry.getValue().getFsPermission(), path);

Review comment:
       We seems only set permission here? how about owner and groups info?

##########
File path: 
gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/CopyableFile.java
##########
@@ -354,6 +359,36 @@ public static OwnerAndPermission 
resolveReplicatedOwnerAndPermission(FileSystem
     return ownerAndPermissions;
   }
 
+  public static Map<String, OwnerAndPermission> 
resolveReplicatedAncestorOwnerAndPermissionsRecursively(FileSystem sourceFs, 
Path fromPath,
+      Path toPath, CopyConfiguration copyConfiguration) throws IOException {
+
+    Map<String, OwnerAndPermission> ownerAndPermissions = Maps.newHashMap();
+
+    // We only pass directories to this method anyways. Those directories 
themselves need permissions set.
+    Path currentOriginPath = fromPath;
+    Path currentTargetPath = toPath;
+
+    if (!PathUtils.isAncestor(currentTargetPath, currentOriginPath)) {
+      throw new IOException(String.format("currentTargetPath %s must be an 
ancestor of currentOriginPath %s.", currentTargetPath, currentOriginPath));
+    }
+
+    while (PathUtils.isAncestor(currentTargetPath, 
currentOriginPath.getParent())) {
+      
ownerAndPermissions.put(PathUtils.getPathWithoutSchemeAndAuthority(currentOriginPath).toString(),
 resolveReplicatedOwnerAndPermission(sourceFs, currentOriginPath, 
copyConfiguration));
+      currentOriginPath = currentOriginPath.getParent();
+    }
+    // Now currentTargetPath and currentOriginPath are the same path.
+
+    // Walk through the parents and preserve the permissions from Origin -> 
Target as we go in lockstep.
+    while (currentOriginPath != null && currentTargetPath != null
+        && currentOriginPath.getName().equals(currentTargetPath.getName())) {
+      
ownerAndPermissions.put(PathUtils.getPathWithoutSchemeAndAuthority(currentOriginPath).toString(),
 resolveReplicatedOwnerAndPermission(sourceFs, currentOriginPath, 
copyConfiguration));
+      currentOriginPath = currentOriginPath.getParent();

Review comment:
       if currentTargetPath and currentOriginPath are the same path, why we 
want to maintain and compare these two in the loop?

##########
File path: 
gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/CopyableFile.java
##########
@@ -354,6 +359,36 @@ public static OwnerAndPermission 
resolveReplicatedOwnerAndPermission(FileSystem
     return ownerAndPermissions;
   }
 
+  public static Map<String, OwnerAndPermission> 
resolveReplicatedAncestorOwnerAndPermissionsRecursively(FileSystem sourceFs, 
Path fromPath,
+      Path toPath, CopyConfiguration copyConfiguration) throws IOException {
+
+    Map<String, OwnerAndPermission> ownerAndPermissions = Maps.newHashMap();
+
+    // We only pass directories to this method anyways. Those directories 
themselves need permissions set.
+    Path currentOriginPath = fromPath;
+    Path currentTargetPath = toPath;
+
+    if (!PathUtils.isAncestor(currentTargetPath, currentOriginPath)) {
+      throw new IOException(String.format("currentTargetPath %s must be an 
ancestor of currentOriginPath %s.", currentTargetPath, currentOriginPath));
+    }
+
+    while (PathUtils.isAncestor(currentTargetPath, 
currentOriginPath.getParent())) {
+      
ownerAndPermissions.put(PathUtils.getPathWithoutSchemeAndAuthority(currentOriginPath).toString(),
 resolveReplicatedOwnerAndPermission(sourceFs, currentOriginPath, 
copyConfiguration));
+      currentOriginPath = currentOriginPath.getParent();
+    }
+    // Now currentTargetPath and currentOriginPath are the same path.
+
+    // Walk through the parents and preserve the permissions from Origin -> 
Target as we go in lockstep.
+    while (currentOriginPath != null && currentTargetPath != null

Review comment:
       What's the reason that we want to change the parent permission as well




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to