hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1355556 - in /hadoop/common/trunk/hadoop-hdfs-project: hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/ hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/ hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop...
Date Fri, 29 Jun 2012 20:59:13 GMT
Author: tucu
Date: Fri Jun 29 20:59:11 2012
New Revision: 1355556

URL: http://svn.apache.org/viewvc?rev=1355556&view=rev
Log:
 HDS-3491. HttpFs does not set permissions correctly (tucu)

Modified:
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java
Fri Jun 29 20:59:11 2012
@@ -86,7 +86,7 @@ public class HttpFSFileSystem extends Fi
   public static final String ACCESS_TIME_PARAM = "accesstime";
   public static final String RENEWER_PARAM = "renewer";
 
-  public static final String DEFAULT_PERMISSION = "default";
+  public static final Short DEFAULT_PERMISSION = 0755;
 
   public static final String RENAME_JSON = "boolean";
 
@@ -438,7 +438,7 @@ public class HttpFSFileSystem extends Fi
    * @return the Unix string symbolic reprentation.
    */
   public static String permissionToString(FsPermission p) {
-    return (p == null) ? DEFAULT_PERMISSION : Integer.toString(p.toShort(), 8);
+    return  Integer.toString((p == null) ? DEFAULT_PERMISSION : p.toShort(), 8);
   }
 
   /*

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java
Fri Jun 29 20:59:11 2012
@@ -42,25 +42,6 @@ import java.util.Map;
  */
 public class FSOperations {
 
-  /**
-   * Converts a Unix permission octal
-   * (i.e. 655 or 1777) into a FileSystemAccess permission.
-   *
-   * @param str Unix permission symbolic representation.
-   *
-   * @return the FileSystemAccess permission. If the given string was
-   *         'default', it returns <code>FsPermission.getDefault()</code>.
-   */
-  private static FsPermission getPermission(String str) {
-    FsPermission permission;
-    if (str.equals(HttpFSFileSystem.DEFAULT_PERMISSION)) {
-      permission = FsPermission.getDefault();
-    } else {
-      permission = new FsPermission(Short.parseShort(str, 8));
-    }
-    return permission;
-  }
-
   @SuppressWarnings({"unchecked", "deprecation"})
   private static Map fileStatusToJSONRaw(FileStatus status, boolean emptyPathSuffix) {
     Map json = new LinkedHashMap();
@@ -252,7 +233,7 @@ public class FSOperations {
   public static class FSCreate implements FileSystemAccess.FileSystemExecutor<Void>
{
     private InputStream is;
     private Path path;
-    private String permission;
+    private short permission;
     private boolean override;
     private short replication;
     private long blockSize;
@@ -267,7 +248,8 @@ public class FSOperations {
      * @param repl the replication factor for the file.
      * @param blockSize the block size for the file.
      */
-    public FSCreate(InputStream is, String path, String perm, boolean override, short repl,
long blockSize) {
+    public FSCreate(InputStream is, String path, short perm, boolean override,
+                    short repl, long blockSize) {
       this.is = is;
       this.path = new Path(path);
       this.permission = perm;
@@ -293,7 +275,7 @@ public class FSOperations {
       if (blockSize == -1) {
         blockSize = fs.getDefaultBlockSize(path);
       }
-      FsPermission fsPermission = getPermission(permission);
+      FsPermission fsPermission = new FsPermission(permission);
       int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096);
       OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication,
blockSize, null);
       IOUtils.copyBytes(is, os, bufferSize, true);
@@ -477,7 +459,7 @@ public class FSOperations {
   public static class FSMkdirs implements FileSystemAccess.FileSystemExecutor<JSONObject>
{
 
     private Path path;
-    private String permission;
+    private short permission;
 
     /**
      * Creates a mkdirs executor.
@@ -485,7 +467,7 @@ public class FSOperations {
      * @param path directory path to create.
      * @param permission permission to use.
      */
-    public FSMkdirs(String path, String permission) {
+    public FSMkdirs(String path, short permission) {
       this.path = new Path(path);
       this.permission = permission;
     }
@@ -502,7 +484,7 @@ public class FSOperations {
      */
     @Override
     public JSONObject execute(FileSystem fs) throws IOException {
-      FsPermission fsPermission = getPermission(permission);
+      FsPermission fsPermission = new FsPermission(permission);
       boolean mkdirs = fs.mkdirs(path, fsPermission);
       return toJSON(HttpFSFileSystem.MKDIRS_JSON, mkdirs);
     }
@@ -621,7 +603,7 @@ public class FSOperations {
   public static class FSSetPermission implements FileSystemAccess.FileSystemExecutor<Void>
{
 
     private Path path;
-    private String permission;
+    private short permission;
 
     /**
      * Creates a set-permission executor.
@@ -629,7 +611,7 @@ public class FSOperations {
      * @param path path to set the permission.
      * @param permission permission to set.
      */
-    public FSSetPermission(String path, String permission) {
+    public FSSetPermission(String path, short permission) {
       this.path = new Path(path);
       this.permission = permission;
     }
@@ -645,7 +627,7 @@ public class FSOperations {
      */
     @Override
     public Void execute(FileSystem fs) throws IOException {
-      FsPermission fsPermission = getPermission(permission);
+      FsPermission fsPermission = new FsPermission(permission);
       fs.setPermission(path, fsPermission);
       return null;
     }

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java
Fri Jun 29 20:59:11 2012
@@ -337,25 +337,19 @@ public class HttpFSParametersProvider ex
   /**
    * Class for permission parameter.
    */
-  public static class PermissionParam extends StringParam {
+  public static class PermissionParam extends ShortParam {
 
     /**
      * Parameter name.
      */
     public static final String NAME = HttpFSFileSystem.PERMISSION_PARAM;
 
-    /**
-     * Symbolic Unix permissions regular expression pattern.
-     */
-    private static final Pattern PERMISSION_PATTERN =
-      Pattern.compile(HttpFSFileSystem.DEFAULT_PERMISSION +
-                      "|[0-1]?[0-7][0-7][0-7]");
 
     /**
      * Constructor.
      */
     public PermissionParam() {
-      super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, PERMISSION_PATTERN);
+      super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, 8);
     }
 
   }

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java
Fri Jun 29 20:59:11 2012
@@ -484,7 +484,7 @@ public class HttpFSServer {
             createUploadRedirectionURL(uriInfo,
               HttpFSFileSystem.Operation.CREATE)).build();
         } else {
-          String permission = params.get(PermissionParam.NAME,
+          Short permission = params.get(PermissionParam.NAME,
                                          PermissionParam.class);
           boolean override = params.get(OverwriteParam.NAME,
                                         OverwriteParam.class);
@@ -504,7 +504,7 @@ public class HttpFSServer {
         break;
       }
       case MKDIRS: {
-        String permission = params.get(PermissionParam.NAME,
+        Short permission = params.get(PermissionParam.NAME,
                                        PermissionParam.class);
         FSOperations.FSMkdirs command =
           new FSOperations.FSMkdirs(path, permission);
@@ -533,8 +533,8 @@ public class HttpFSServer {
         break;
       }
       case SETPERMISSION: {
-        String permission = params.get(PermissionParam.NAME,
-                                       PermissionParam.class);
+        Short permission = params.get(PermissionParam.NAME,
+                                      PermissionParam.class);
         FSOperations.FSSetPermission command =
           new FSOperations.FSSetPermission(path, permission);
         fsExecute(user, doAs, command);

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java
Fri Jun 29 20:59:11 2012
@@ -20,12 +20,19 @@ package org.apache.hadoop.lib.wsrs;
 
 public abstract class ShortParam extends Param<Short> {
 
-  public ShortParam(String name, Short defaultValue) {
+  private int radix;
+
+  public ShortParam(String name, Short defaultValue, int radix) {
     super(name, defaultValue);
+    this.radix = radix;
+  }
+
+  public ShortParam(String name, Short defaultValue) {
+    this(name, defaultValue, 10);
   }
 
   protected Short parse(String str) throws Exception {
-    return Short.parseShort(str);
+    return Short.parseShort(str, radix);
   }
 
   @Override

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java
(original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java
Fri Jun 29 20:59:11 2012
@@ -77,6 +77,11 @@ public class TestParam {
     };
     test(param, "S", "a short", (short) 1, (short) 2, "x",
          "" + ((int)Short.MAX_VALUE + 1));
+
+    param = new ShortParam("S", (short) 1, 8) {
+    };
+
+    Assert.assertEquals(new Short((short)01777), param.parse("01777"));
   }
 
   @Test

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1355556&r1=1355555&r2=1355556&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Fri Jun 29 20:59:11 2012
@@ -399,6 +399,8 @@ Branch-2 ( Unreleased changes )
     HDFS-3551. WebHDFS CREATE should use client location for HTTP redirection.
     (szetszwo)
 
+    HDFS-3491. HttpFs does not set permissions correctly (tucu)
+
 Release 2.0.0-alpha - 05-23-2012
 
   INCOMPATIBLE CHANGES



Mime
View raw message