HDFS-12857. StoragePolicyAdmin should support schema based path. Contributed by Surendra Singh Lilhore.
This commit is contained in:
parent
a2c7a73e33
commit
30941d99c9
@ -153,7 +153,7 @@ public int run(Configuration conf, List<String> args) throws IOException {
|
||||
}
|
||||
|
||||
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 int run(Configuration conf, List<String> args) throws IOException {
|
||||
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 int run(Configuration conf, List<String> args) throws IOException {
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -21,18 +21,19 @@
|
||||
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 void testStoragePolicyRoot() throws Exception {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user