Bladeren bron

HADOOP-6869. svn merge -c 979942 from trunk

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.21@979943 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Boudnik 14 jaren geleden
bovenliggende
commit
c2ea35c8c8

+ 3 - 0
CHANGES.txt

@@ -283,6 +283,9 @@ Release 0.21.0 - 2010-07-01
     HADOOP-6692. Add FileContext#listStatus that returns an iterator.
     (hairong)
 
+    HADOOP-6869. Functionality to create file or folder on a remote daemon
+    side (Vinay Thota via cos)
+
   IMPROVEMENTS
 
     HADOOP-6798. Align Ivy version for all Hadoop subprojects. (cos)

+ 50 - 0
src/test/system/aop/org/apache/hadoop/test/system/DaemonProtocolAspect.aj

@@ -34,6 +34,8 @@ import org.apache.hadoop.util.Shell.ShellCommandExecutor;
 import org.apache.hadoop.util.Shell;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.permission.FsAction;
+import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.conf.Configuration;
 
@@ -53,6 +55,10 @@ public aspect DaemonProtocolAspect {
     new HashMap<Object, List<ControlAction>>();
   private static final Log LOG = LogFactory.getLog(
       DaemonProtocolAspect.class.getName());
+
+  private static FsPermission defaultPermission = new FsPermission(
+     FsAction.READ_WRITE, FsAction.READ_WRITE, FsAction.READ_WRITE);
+
   /**
    * Set if the daemon process is ready or not, concrete daemon protocol should
    * implement pointcuts to determine when the daemon is ready and use the
@@ -126,6 +132,50 @@ public aspect DaemonProtocolAspect {
     FileStatus fileStatus = fs.getFileStatus(p);
     return cloneFileStatus(fileStatus);
   }
+  
+  /**
+   * Create a file with given permissions in a file system.
+   * @param path - source path where the file has to create.
+   * @param fileName - file name.
+   * @param permission - file permissions.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  public void DaemonProtocol.createFile(String path, String fileName, 
+     FsPermission permission, boolean local) throws IOException {
+    Path p = new Path(path); 
+    FileSystem fs = getFS(p, local);
+    Path filePath = new Path(path, fileName);
+    fs.create(filePath);
+    if (permission == null) {
+      fs.setPermission(filePath, defaultPermission);
+    } else {
+      fs.setPermission(filePath, permission);
+    }
+    fs.close();
+  }
+
+  /**
+   * Create a folder with given permissions in a file system.
+   * @param path - source path where the file has to be creating.
+   * @param folderName - folder name.
+   * @param permission - folder permissions.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  public void DaemonProtocol.createFolder(String path, String folderName, 
+     FsPermission permission, boolean local) throws IOException {
+    Path p = new Path(path);
+    FileSystem fs = getFS(p, local);
+    Path folderPath = new Path(path, folderName);
+    fs.mkdirs(folderPath);
+    if (permission == null) {
+      fs.setPermission(folderPath, defaultPermission);
+    } else {
+      fs.setPermission(folderPath, permission);
+    }
+    fs.close();
+  }
 
   public FileStatus[] DaemonProtocol.listStatus(String path, boolean local) 
     throws IOException {

+ 52 - 0
src/test/system/java/org/apache/hadoop/test/system/AbstractDaemonClient.java

@@ -27,6 +27,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.test.system.process.RemoteProcess;
 /**
  * Abstract class which encapsulates the DaemonClient which is used in the 
@@ -165,6 +167,56 @@ public abstract class AbstractDaemonClient<PROXY extends DaemonProtocol> {
     return getProxy().getFileStatus(path, local);
   }
 
+  /**
+   * Create a file with full permissions in a file system.
+   * @param path - source path where the file has to create.
+   * @param fileName - file name
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  public void createFile(String path, String fileName, 
+      boolean local) throws IOException {
+    getProxy().createFile(path, fileName, null, local);
+  }
+
+  /**
+   * Create a file with given permissions in a file system.
+   * @param path - source path where the file has to create.
+   * @param fileName - file name.
+   * @param permission - file permissions.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  public void createFile(String path, String fileName, 
+     FsPermission permission,  boolean local) throws IOException {
+    getProxy().createFile(path, fileName, permission, local);
+  }
+
+  /**
+   * Create a folder with default permissions in a file system.
+   * @param path - source path where the file has to be creating.
+   * @param folderName - folder name.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs. 
+   */
+  public void createFolder(String path, String folderName, 
+     boolean local) throws IOException {
+    getProxy().createFolder(path, folderName, null, local);
+  }
+
+  /**
+   * Create a folder with given permissions in a file system.
+   * @param path - source path where the file has to be creating.
+   * @param folderName - folder name.
+   * @param permission - folder permissions.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  public void createFolder(String path, String folderName, 
+     FsPermission permission,  boolean local) throws IOException {
+    getProxy().createFolder(path, folderName, permission, local);
+  }
+
   /**
    * List the statuses of the files/directories in the given path if the path is
    * a directory.

+ 23 - 0
src/test/system/java/org/apache/hadoop/test/system/DaemonProtocol.java

@@ -23,8 +23,10 @@ import java.io.IOException;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.ipc.VersionedProtocol;
+import org.apache.hadoop.fs.permission.FsPermission;
 
 /**
  * RPC interface of a given Daemon.
@@ -76,6 +78,27 @@ public interface DaemonProtocol extends VersionedProtocol{
    */
   FileStatus getFileStatus(String path, boolean local) throws IOException;
 
+  /**
+   * Create a file with given permissions in a file system.
+   * @param path - source path where the file has to create.
+   * @param fileName - file name.
+   * @param permission - file permissions.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  void createFile(String path, String fileName, 
+      FsPermission permission, boolean local) throws IOException;
+   
+  /**
+   * Create a folder with given permissions in a file system.
+   * @param path - source path where the file has to be creating.
+   * @param folderName - folder name.
+   * @param permission - folder permissions.
+   * @param local - identifying the path whether its local or not.
+   * @throws IOException - if an I/O error occurs.
+   */
+  public void createFolder(String path, String folderName, 
+      FsPermission permission, boolean local) throws IOException;
   /**
    * List the statuses of the files/directories in the given path if the path is
    * a directory.