Search in sources :

Example 6 with BlockStoragePolicySuite

use of org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite in project hadoop by apache.

the class TestStoragePolicyCommands method testSetAndGetStoragePolicy.

@Test
public void testSetAndGetStoragePolicy() throws Exception {
    final Path foo = new Path("/foo");
    final Path bar = new Path(foo, "bar");
    DFSTestUtil.createFile(fs, bar, SIZE, REPL, 0);
    final StoragePolicyAdmin admin = new StoragePolicyAdmin(conf);
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo", 0, "The storage policy of " + foo.toString() + " is unspecified");
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar", 0, "The storage policy of " + bar.toString() + " is unspecified");
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo -policy WARM", 0, "Set storage policy WARM on " + foo.toString());
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo/bar -policy COLD", 0, "Set storage policy COLD on " + bar.toString());
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /fooz -policy WARM", 2, "File/Directory does not exist: /fooz");
    final BlockStoragePolicySuite suite = BlockStoragePolicySuite.createDefaultSuite();
    final BlockStoragePolicy warm = suite.getPolicy("WARM");
    final BlockStoragePolicy cold = suite.getPolicy("COLD");
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo", 0, "The storage policy of " + foo.toString() + ":\n" + warm);
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar", 0, "The storage policy of " + bar.toString() + ":\n" + cold);
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /fooz", 2, "File/Directory does not exist: /fooz");
}
Also used : Path(org.apache.hadoop.fs.Path) BlockStoragePolicySuite(org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite) BlockStoragePolicy(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy) Test(org.junit.Test)

Example 7 with BlockStoragePolicySuite

use of org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite in project hadoop by apache.

the class TestStoragePolicyCommands method testSetAndUnsetStoragePolicy.

@Test
public void testSetAndUnsetStoragePolicy() throws Exception {
    final Path foo = new Path("/foo");
    final Path bar = new Path(foo, "bar");
    final Path wow = new Path(bar, "wow");
    DFSTestUtil.createFile(fs, wow, SIZE, REPL, 0);
    /*
     * test: set storage policy
     */
    final StoragePolicyAdmin admin = new StoragePolicyAdmin(conf);
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path " + fs.getUri() + "/foo -policy WARM", 0, "Set storage policy WARM on " + fs.getUri() + "/foo");
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo/bar -policy COLD", 0, "Set storage policy COLD on " + bar.toString());
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /foo/bar/wow -policy HOT", 0, "Set storage policy HOT on " + wow.toString());
    DFSTestUtil.toolRun(admin, "-setStoragePolicy -path /fooz -policy WARM", 2, "File/Directory does not exist: /fooz");
    /*
     * test: get storage policy after set
     */
    final BlockStoragePolicySuite suite = BlockStoragePolicySuite.createDefaultSuite();
    final BlockStoragePolicy warm = suite.getPolicy("WARM");
    final BlockStoragePolicy cold = suite.getPolicy("COLD");
    final BlockStoragePolicy hot = suite.getPolicy("HOT");
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path " + fs.getUri() + "/foo", 0, "The storage policy of " + fs.getUri() + "/foo:\n" + warm);
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar", 0, "The storage policy of " + bar.toString() + ":\n" + cold);
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar/wow", 0, "The storage policy of " + wow.toString() + ":\n" + hot);
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /fooz", 2, "File/Directory does not exist: /fooz");
    /*
     * test: unset storage policy
     */
    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path " + fs.getUri() + "/foo", 0, "Unset storage policy from " + fs.getUri() + "/foo");
    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path /foo/bar", 0, "Unset storage policy from " + bar.toString());
    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path /foo/bar/wow", 0, "Unset storage policy from " + wow.toString());
    DFSTestUtil.toolRun(admin, "-unsetStoragePolicy -path /fooz", 2, "File/Directory does not exist: /fooz");
    /*
     * test: get storage policy after unset
     */
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo", 0, "The storage policy of " + foo.toString() + " is unspecified");
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar", 0, "The storage policy of " + bar.toString() + " is unspecified");
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /foo/bar/wow", 0, "The storage policy of " + wow.toString() + " is unspecified");
    DFSTestUtil.toolRun(admin, "-getStoragePolicy -path /fooz", 2, "File/Directory does not exist: /fooz");
}
Also used : Path(org.apache.hadoop.fs.Path) BlockStoragePolicySuite(org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite) BlockStoragePolicy(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy) Test(org.junit.Test)

Example 8 with BlockStoragePolicySuite

use of org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite in project hadoop by apache.

the class TestStoragePolicySummary method testMultipleWarmsInDifferentOrder.

@Test
public void testMultipleWarmsInDifferentOrder() {
    BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite();
    StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies());
    BlockStoragePolicy warm = bsps.getPolicy("WARM");
    //DISK:1,ARCHIVE:1
    sts.add(new StorageType[] { StorageType.DISK, StorageType.ARCHIVE }, warm);
    sts.add(new StorageType[] { StorageType.ARCHIVE, StorageType.DISK }, warm);
    //DISK:2,ARCHIVE:1
    sts.add(new StorageType[] { StorageType.ARCHIVE, StorageType.DISK, StorageType.DISK }, warm);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.ARCHIVE, StorageType.DISK }, warm);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK, StorageType.ARCHIVE }, warm);
    //DISK:1,ARCHIVE:2
    sts.add(new StorageType[] { StorageType.DISK, StorageType.ARCHIVE, StorageType.ARCHIVE }, warm);
    sts.add(new StorageType[] { StorageType.ARCHIVE, StorageType.DISK, StorageType.ARCHIVE }, warm);
    sts.add(new StorageType[] { StorageType.ARCHIVE, StorageType.ARCHIVE, StorageType.DISK }, warm);
    //DISK:2,ARCHIVE:2
    sts.add(new StorageType[] { StorageType.ARCHIVE, StorageType.ARCHIVE, StorageType.DISK, StorageType.DISK }, warm);
    Map<String, Long> actualOutput = convertToStringMap(sts);
    Assert.assertEquals(4, actualOutput.size());
    Map<String, Long> expectedOutput = new HashMap<>();
    expectedOutput.put("WARM|DISK:1,ARCHIVE:1(WARM)", 2l);
    expectedOutput.put("WARM|DISK:2,ARCHIVE:1", 3l);
    expectedOutput.put("WARM|DISK:1,ARCHIVE:2(WARM)", 3l);
    expectedOutput.put("WARM|DISK:2,ARCHIVE:2", 1l);
    Assert.assertEquals(expectedOutput, actualOutput);
}
Also used : BlockStoragePolicySuite(org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BlockStoragePolicy(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy) Test(org.junit.Test)

Example 9 with BlockStoragePolicySuite

use of org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite in project hadoop by apache.

the class TestStoragePolicySummary method testMultipleHots.

@Test
public void testMultipleHots() {
    BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite();
    StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies());
    BlockStoragePolicy hot = bsps.getPolicy("HOT");
    sts.add(new StorageType[] { StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK, StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK, StorageType.DISK, StorageType.DISK }, hot);
    Map<String, Long> actualOutput = convertToStringMap(sts);
    Assert.assertEquals(4, actualOutput.size());
    Map<String, Long> expectedOutput = new HashMap<>();
    expectedOutput.put("HOT|DISK:1(HOT)", 1l);
    expectedOutput.put("HOT|DISK:2(HOT)", 1l);
    expectedOutput.put("HOT|DISK:3(HOT)", 1l);
    expectedOutput.put("HOT|DISK:4(HOT)", 1l);
    Assert.assertEquals(expectedOutput, actualOutput);
}
Also used : BlockStoragePolicySuite(org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BlockStoragePolicy(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy) Test(org.junit.Test)

Example 10 with BlockStoragePolicySuite

use of org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite in project hadoop by apache.

the class TestStoragePolicySummary method testMultipleHotsWithDifferentCounts.

@Test
public void testMultipleHotsWithDifferentCounts() {
    BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite();
    StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies());
    BlockStoragePolicy hot = bsps.getPolicy("HOT");
    sts.add(new StorageType[] { StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK, StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK, StorageType.DISK }, hot);
    sts.add(new StorageType[] { StorageType.DISK, StorageType.DISK, StorageType.DISK, StorageType.DISK }, hot);
    Map<String, Long> actualOutput = convertToStringMap(sts);
    Assert.assertEquals(4, actualOutput.size());
    Map<String, Long> expectedOutput = new HashMap<>();
    expectedOutput.put("HOT|DISK:1(HOT)", 1l);
    expectedOutput.put("HOT|DISK:2(HOT)", 2l);
    expectedOutput.put("HOT|DISK:3(HOT)", 2l);
    expectedOutput.put("HOT|DISK:4(HOT)", 1l);
    Assert.assertEquals(expectedOutput, actualOutput);
}
Also used : BlockStoragePolicySuite(org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BlockStoragePolicy(org.apache.hadoop.hdfs.protocol.BlockStoragePolicy) Test(org.junit.Test)

Aggregations

BlockStoragePolicySuite (org.apache.hadoop.hdfs.server.blockmanagement.BlockStoragePolicySuite)16 BlockStoragePolicy (org.apache.hadoop.hdfs.protocol.BlockStoragePolicy)14 Test (org.junit.Test)13 Path (org.apache.hadoop.fs.Path)7 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 LinkedHashMap (java.util.LinkedHashMap)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)2 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 BlockStoragePolicySpi (org.apache.hadoop.fs.BlockStoragePolicySpi)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 HdfsAdmin (org.apache.hadoop.hdfs.client.HdfsAdmin)1 Block (org.apache.hadoop.hdfs.protocol.Block)1 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)1 BlockInfo (org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo)1