hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vinayakum...@apache.org
Subject [1/3] hadoop git commit: HDFS-11177. 'storagepolicies -getStoragePolicy' command should accept URI based path. (Contributed by Surendra Singh Lilhore)
Date Tue, 21 Feb 2017 12:49:17 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 274c02d2f -> 00ca9f179
  refs/heads/branch-2.8 8a05ea4ab -> 2b3e8b75c
  refs/heads/trunk 6ba61d20d -> 480405063


HDFS-11177. 'storagepolicies -getStoragePolicy' command should accept URI based path. (Contributed
by Surendra Singh Lilhore)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/48040506
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/48040506
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/48040506

Branch: refs/heads/trunk
Commit: 480405063063f564ae0cdb34e0757ac3990569aa
Parents: 6ba61d2
Author: Vinayakumar B <vinayakumarb@apache.org>
Authored: Tue Feb 21 18:13:19 2017 +0530
Committer: Vinayakumar B <vinayakumarb@apache.org>
Committed: Tue Feb 21 18:13:19 2017 +0530

----------------------------------------------------------------------
 .../apache/hadoop/hdfs/tools/AdminHelper.java   | 12 ++++++++++
 .../hadoop/hdfs/tools/StoragePolicyAdmin.java   | 23 +++++++++++---------
 .../hdfs/tools/TestStoragePolicyCommands.java   | 14 +++++++-----
 3 files changed, 33 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/48040506/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
index 153fb36..8bab550 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.hdfs.tools;
 
 import com.google.common.base.Preconditions;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hdfs.DFSUtil;
@@ -26,6 +27,7 @@ import org.apache.hadoop.hdfs.protocol.CachePoolInfo;
 import org.apache.hadoop.tools.TableListing;
 
 import java.io.IOException;
+import java.net.URI;
 import java.util.List;
 
 /**
@@ -48,6 +50,16 @@ public class AdminHelper {
     return (DistributedFileSystem)fs;
   }
 
+  static DistributedFileSystem getDFS(URI uri, Configuration conf)
+      throws IOException {
+    FileSystem fs = FileSystem.get(uri, conf);
+    if (!(fs instanceof DistributedFileSystem)) {
+      throw new IllegalArgumentException("FileSystem " + fs.getUri()
+          + " is not an HDFS file system");
+    }
+    return (DistributedFileSystem) fs;
+  }
+
   /**
    * NN exceptions contain the stack trace as part of the exception message.
    * When it's a known error, pretty-print the error and squish the stack trace.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/48040506/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/StoragePolicyAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/StoragePolicyAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/StoragePolicyAdmin.java
index d99b88a..4e4f018 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/StoragePolicyAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/StoragePolicyAdmin.java
@@ -148,9 +148,11 @@ public class StoragePolicyAdmin extends Configured implements Tool {
         return 1;
       }
 
-      final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
+      Path p = new Path(path);
+      final DistributedFileSystem dfs = AdminHelper.getDFS(p.toUri(), conf);
       try {
-        HdfsFileStatus status = dfs.getClient().getFileInfo(path);
+        HdfsFileStatus status = dfs.getClient().getFileInfo(
+            Path.getPathWithoutSchemeAndAuthority(p).toString());
         if (status == null) {
           System.err.println("File/Directory does not exist: " + path);
           return 2;
@@ -161,9 +163,9 @@ public class StoragePolicyAdmin extends Configured implements Tool {
           return 0;
         }
         Collection<BlockStoragePolicy> policies = dfs.getAllStoragePolicies();
-        for (BlockStoragePolicy p : policies) {
-          if (p.getId() == storagePolicyId) {
-            System.out.println("The storage policy of " + path + ":\n" + p);
+        for (BlockStoragePolicy policy : policies) {
+          if (policy.getId() == storagePolicyId) {
+            System.out.println("The storage policy of " + path + ":\n" + policy);
             return 0;
           }
         }
@@ -215,10 +217,10 @@ public class StoragePolicyAdmin extends Configured implements Tool {
             getLongUsage());
         return 1;
       }
-
-      final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
+      Path p = new Path(path);
+      final DistributedFileSystem dfs = AdminHelper.getDFS(p.toUri(), conf);
       try {
-        dfs.setStoragePolicy(new Path(path), policyName);
+        dfs.setStoragePolicy(p, policyName);
         System.out.println("Set storage policy " + policyName + " on " + path);
       } catch (Exception e) {
         System.err.println(AdminHelper.prettifyException(e));
@@ -261,9 +263,10 @@ public class StoragePolicyAdmin extends Configured implements Tool {
         return 1;
       }
 
-      final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
+      Path p = new Path(path);
+      final DistributedFileSystem dfs = AdminHelper.getDFS(p.toUri(), conf);
       try {
-        dfs.unsetStoragePolicy(new Path(path));
+        dfs.unsetStoragePolicy(p);
         System.out.println("Unset storage policy from " + path);
       } catch (Exception e) {
         System.err.println(AdminHelper.prettifyException(e));

http://git-wip-us.apache.org/repos/asf/hadoop/blob/48040506/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicyCommands.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicyCommands.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicyCommands.java
index 63f8484..149dabb 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicyCommands.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicyCommands.java
@@ -74,8 +74,9 @@ public class TestStoragePolicyCommands {
      * test: set storage policy
      */
     final StoragePolicyAdmin admin = new StoragePolicyAdmin(conf);
-    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo -policy WARM", 0,
-        "Set storage policy WARM on " + foo.toString());
+    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path " + fs.getUri()
+        + "/foo -policy WARM", 0, "Set storage policy WARM on " + fs.getUri()
+        + "/foo");
     DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo/bar -policy COLD",
         0, "Set storage policy COLD on " + bar.toString());
     DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo/bar/wow -policy HOT",
@@ -91,8 +92,9 @@ public class TestStoragePolicyCommands {
     final BlockStoragePolicy warm = suite.getPolicy("WARM");
     final BlockStoragePolicy cold = suite.getPolicy("COLD");
     final BlockStoragePolicy hot = suite.getPolicy("HOT");
-    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo", 0,
-        "The storage policy of " + foo.toString() + ":\n" + warm);
+    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path " + fs.getUri()
+        + "/foo", 0, "The storage policy of " + fs.getUri() + "/foo:\n"
+        + warm);
     DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar", 0,
         "The storage policy of " + bar.toString() + ":\n" + cold);
     DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar/wow", 0,
@@ -103,8 +105,8 @@ public class TestStoragePolicyCommands {
     /*
      * test: unset storage policy
      */
-    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path /foo", 0,
-        "Unset storage policy from " + foo.toString());
+    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path " + fs.getUri()
+        + "/foo", 0, "Unset storage policy from " + fs.getUri() + "/foo");
     DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path /foo/bar", 0,
         "Unset storage policy from " + bar.toString());
     DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path /foo/bar/wow", 0,


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message