Browse Source

HDFS-14184. [SPS] Add support for URI based path in satisfystoragepolicy command. Contributed by Ayush Saxena.

Surendra Singh Lilhore 6 years ago
parent
commit
21fe77e3ab

+ 3 - 4
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/StoragePolicyAdmin.java

@@ -23,7 +23,6 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.BlockStoragePolicySpi;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
@@ -278,10 +277,10 @@ public class StoragePolicyAdmin extends Configured implements Tool {
             "policy.\nUsage: " + getLongUsage());
         return 1;
       }
-
-      final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
+      Path p = new Path(path);
+      final FileSystem fs = FileSystem.get(p.toUri(), conf);
       try {
-        dfs.satisfyStoragePolicy(new Path(path));
+        fs.satisfyStoragePolicy(p);
         System.out.println("Scheduled blocks to move based on the current"
             + " storage policy on " + path);
       } catch (Exception e) {

+ 22 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicySatisfyAdminCommands.java

@@ -109,4 +109,26 @@ public class TestStoragePolicySatisfyAdminCommands {
     DFSTestUtil.waitExpectedStorageType(file, StorageType.ARCHIVE, 1, 30000,
         dfs);
   }
+
+  @Test(timeout = 30000)
+  public void testStoragePolicySatisfierCommandWithURI() throws Exception {
+    final String file = "/testStoragePolicySatisfierCommandURI";
+    DFSTestUtil.createFile(dfs, new Path(file), SIZE, REPL, 0);
+
+    final StoragePolicyAdmin admin = new StoragePolicyAdmin(conf);
+    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path " + file, 0,
+        "The storage policy of " + file + " is unspecified");
+
+    DFSTestUtil.toolRun(admin,
+        "-setStoragePolicy -path " + file + " -policy COLD", 0,
+        "Set storage policy COLD on " + file.toString());
+
+    DFSTestUtil.toolRun(admin,
+        "-satisfyStoragePolicy -path " + dfs.getUri() + file, 0,
+        "Scheduled blocks to move based on the current storage policy on "
+            + dfs.getUri() + file.toString());
+
+    DFSTestUtil.waitExpectedStorageType(file, StorageType.ARCHIVE, 1, 30000,
+        dfs);
+  }
 }