From 21fe77e3ab0d3951212ba64cf80f4904f789db66 Mon Sep 17 00:00:00 2001 From: Surendra Singh Lilhore Date: Thu, 3 Jan 2019 18:36:53 +0530 Subject: [PATCH] HDFS-14184. [SPS] Add support for URI based path in satisfystoragepolicy command. Contributed by Ayush Saxena. --- .../hadoop/hdfs/tools/StoragePolicyAdmin.java | 7 +++--- ...TestStoragePolicySatisfyAdminCommands.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) 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 14b31e41eb..98b599b92b 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 @@ -23,7 +23,6 @@ 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 int run(Configuration conf, List args) throws IOException { "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) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicySatisfyAdminCommands.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicySatisfyAdminCommands.java index 61fccfac54..e517d431be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicySatisfyAdminCommands.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestStoragePolicySatisfyAdminCommands.java @@ -109,4 +109,26 @@ public void testStoragePolicySatisfierCommand() throws Exception { 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); + } }