|
@@ -25,7 +25,9 @@ import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
+import com.google.common.collect.Sets;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.BlockStoragePolicySpi;
|
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
@@ -1150,30 +1152,6 @@ public class TestBlockStoragePolicy {
|
|
Assert.assertEquals(3, targets.length);
|
|
Assert.assertEquals(3, targets.length);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Test getting all the storage policies from the namenode
|
|
|
|
- */
|
|
|
|
- @Test
|
|
|
|
- public void testGetAllStoragePolicies() throws Exception {
|
|
|
|
- final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
|
|
|
|
- .numDataNodes(0).build();
|
|
|
|
- cluster.waitActive();
|
|
|
|
- final DistributedFileSystem fs = cluster.getFileSystem();
|
|
|
|
- try {
|
|
|
|
- BlockStoragePolicy[] policies = fs.getStoragePolicies();
|
|
|
|
- Assert.assertEquals(6, policies.length);
|
|
|
|
- Assert.assertEquals(POLICY_SUITE.getPolicy(COLD).toString(),
|
|
|
|
- policies[0].toString());
|
|
|
|
- Assert.assertEquals(POLICY_SUITE.getPolicy(WARM).toString(),
|
|
|
|
- policies[1].toString());
|
|
|
|
- Assert.assertEquals(POLICY_SUITE.getPolicy(HOT).toString(),
|
|
|
|
- policies[2].toString());
|
|
|
|
- } finally {
|
|
|
|
- IOUtils.cleanup(null, fs);
|
|
|
|
- cluster.shutdown();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void testGetFileStoragePolicyAfterRestartNN() throws Exception {
|
|
public void testGetFileStoragePolicyAfterRestartNN() throws Exception {
|
|
//HDFS8219
|
|
//HDFS8219
|
|
@@ -1217,4 +1195,42 @@ public class TestBlockStoragePolicy {
|
|
cluster.shutdown();
|
|
cluster.shutdown();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Verify that {@link FileSystem#getAllStoragePolicies} returns all
|
|
|
|
+ * known storage policies for DFS.
|
|
|
|
+ *
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testGetAllStoragePoliciesFromFs() throws IOException {
|
|
|
|
+ final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
|
|
|
|
+ .numDataNodes(REPLICATION)
|
|
|
|
+ .storageTypes(
|
|
|
|
+ new StorageType[] {StorageType.DISK, StorageType.ARCHIVE})
|
|
|
|
+ .build();
|
|
|
|
+ try {
|
|
|
|
+ cluster.waitActive();
|
|
|
|
+
|
|
|
|
+ // Get policies via {@link FileSystem#getAllStoragePolicies}
|
|
|
|
+ Set<String> policyNamesSet1 = new HashSet<>();
|
|
|
|
+ for (BlockStoragePolicySpi policy :
|
|
|
|
+ cluster.getFileSystem().getAllStoragePolicies()) {
|
|
|
|
+ policyNamesSet1.add(policy.getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Get policies from the default BlockStoragePolicySuite.
|
|
|
|
+ BlockStoragePolicySuite suite = BlockStoragePolicySuite.createDefaultSuite();
|
|
|
|
+ Set<String> policyNamesSet2 = new HashSet<>();
|
|
|
|
+ for (BlockStoragePolicy policy : suite.getAllPolicies()) {
|
|
|
|
+ policyNamesSet2.add(policy.getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Ensure that we got the same set of policies in both cases.
|
|
|
|
+ Assert.assertTrue(Sets.difference(policyNamesSet1, policyNamesSet2).isEmpty());
|
|
|
|
+ Assert.assertTrue(Sets.difference(policyNamesSet2, policyNamesSet1).isEmpty());
|
|
|
|
+ } finally {
|
|
|
|
+ cluster.shutdown();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|