HDFS-12857. StoragePolicyAdmin should support schema 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/30941d99
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/30941d99
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/30941d99

Branch: refs/heads/HDFS-7240
Commit: 30941d99c9014431981eeb09ab24e90bef629fee
Parents: a2c7a73
Author: Surendra Singh Lilhore <surendralilh...@apache.org>
Authored: Tue Nov 28 23:57:03 2017 +0530
Committer: Surendra Singh Lilhore <surendralilh...@apache.org>
Committed: Tue Nov 28 23:57:03 2017 +0530

----------------------------------------------------------------------
 .../hadoop/hdfs/tools/StoragePolicyAdmin.java   |  6 ++--
 .../tools/TestViewFSStoragePolicyCommands.java  | 37 ++++++++++++++++++--
 2 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/30941d99/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 d5e5b4d..aeb10d9 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
@@ -153,7 +153,7 @@ public class StoragePolicyAdmin extends Configured 
implements Tool {
       }
 
       Path p = new Path(path);
-      final FileSystem fs = FileSystem.get(conf);
+      final FileSystem fs = FileSystem.get(p.toUri(), conf);
       try {
         FileStatus status;
         try {
@@ -233,7 +233,7 @@ public class StoragePolicyAdmin extends Configured 
implements Tool {
         return 1;
       }
       Path p = new Path(path);
-      final FileSystem fs = FileSystem.get(conf);
+      final FileSystem fs = FileSystem.get(p.toUri(), conf);
       try {
         fs.setStoragePolicy(p, policyName);
         System.out.println("Set storage policy " + policyName + " on " + path);
@@ -279,7 +279,7 @@ public class StoragePolicyAdmin extends Configured 
implements Tool {
       }
 
       Path p = new Path(path);
-      final FileSystem fs = FileSystem.get(conf);
+      final FileSystem fs = FileSystem.get(p.toUri(), conf);
       try {
         fs.unsetStoragePolicy(p);
         System.out.println("Unset storage policy from " + path);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/30941d99/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestViewFSStoragePolicyCommands.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestViewFSStoragePolicyCommands.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestViewFSStoragePolicyCommands.java
index b3bb3c4..3a94959 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestViewFSStoragePolicyCommands.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestViewFSStoragePolicyCommands.java
@@ -21,18 +21,19 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.fs.FsConstants;
-
 import org.apache.hadoop.fs.viewfs.ConfigUtil;
 import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.DFSTestUtil;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
 import org.apache.hadoop.hdfs.MiniDFSNNTopology;
-
+import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
+import org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 
 /**
  * Test StoragePolicyAdmin commands with ViewFileSystem.
@@ -77,4 +78,36 @@ public class TestViewFSStoragePolicyCommands extends 
TestStoragePolicyCommands {
     DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /", 2,
         "is not supported for filesystem viewfs on path /");
   }
+
+  @Test
+  public void testStoragePolicyCommandPathWithSchema() throws Exception {
+    Path base1 = new Path("/user1");
+    final Path bar = new Path(base1, "bar");
+    DFSTestUtil.createFile(cluster.getFileSystem(0), bar, 1024, (short) 1, 0);
+
+    // Test with hdfs:// schema
+    String pathHdfsSchema = "hdfs://"
+        + cluster.getNameNode(0).getClientNamenodeAddress() + "/"
+        + bar.toString();
+    checkCommandsWithUriPath(pathHdfsSchema);
+
+    // Test with webhdfs:// schema
+    InetSocketAddress httpAddress = cluster.getNameNode(0).getHttpAddress();
+    String pathWebhdfsSchema = "webhdfs://" + httpAddress.getHostName() + ":"
+        + httpAddress.getPort() + "/" + bar.toString();
+    checkCommandsWithUriPath(pathWebhdfsSchema);
+  }
+
+  private void checkCommandsWithUriPath(String pathWithSchema) throws 
Exception{
+    final StoragePolicyAdmin admin = new StoragePolicyAdmin(conf);
+    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path " + pathWithSchema
+        + " -policy WARM", 0, "Set storage policy WARM on " + pathWithSchema);
+    final BlockStoragePolicySuite suite = BlockStoragePolicySuite
+        .createDefaultSuite();
+    final BlockStoragePolicy warm = suite.getPolicy("WARM");
+    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path " + pathWithSchema, 0,
+        "The storage policy of " + pathWithSchema + ":\n" + warm);
+    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path " + pathWithSchema, 
0,
+        "Unset storage policy from " + pathWithSchema);
+  }
 }


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

Reply via email to