Search in sources :

Example 1 with ActionStatus

use of org.smartdata.actions.ActionStatus in project SSM by Intel-bigdata.

the class TestAllSsdFileAction method testAllSsd.

@Test
public void testAllSsd() throws Exception {
    final String file = "/testAllSsd/file";
    Path dir = new Path("/testAllSsd");
    dfs.mkdirs(dir);
    // write to DISK
    dfs.setStoragePolicy(dir, "HOT");
    final FSDataOutputStream out = dfs.create(new Path(file));
    out.writeChars("testAllSSD");
    out.close();
    // schedule move to SSD
    AllSsdFileAction action = new AllSsdFileAction();
    action.setDfsClient(dfsClient);
    action.setContext(smartContext);
    action.init(file);
    ActionStatus status = action.getActionStatus();
    action.run();
    while (!status.isFinished()) {
        System.out.println("Mover running time : " + StringUtils.formatTime(status.getRunningTime()));
        Thread.sleep(1000);
    }
    // verify after movement
    Assert.assertTrue(status.isSuccessful());
    LocatedBlock lb = dfsClient.getLocatedBlocks(file, 0).get(0);
    StorageType[] storageTypes = lb.getStorageTypes();
    for (StorageType storageType : storageTypes) {
        Assert.assertTrue(StorageType.SSD == storageType);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) StorageType(org.apache.hadoop.fs.StorageType) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ActionStatus(org.smartdata.actions.ActionStatus) Test(org.junit.Test)

Example 2 with ActionStatus

use of org.smartdata.actions.ActionStatus in project SSM by Intel-bigdata.

the class TestOneSsdFileAction method testAllSsd.

@Test
public void testAllSsd() throws Exception {
    final String file = "/testArchive/file";
    Path dir = new Path("/testArchive");
    dfs.mkdirs(dir);
    // write to DISK
    dfs.setStoragePolicy(dir, "HOT");
    final FSDataOutputStream out = dfs.create(new Path(file));
    out.writeChars("testArchive");
    out.close();
    // schedule move to Archive
    OneSsdFileAction action = new OneSsdFileAction();
    action.setDfsClient(dfsClient);
    action.setContext(smartContext);
    action.init(file);
    ActionStatus status = action.getActionStatus();
    action.run();
    while (!status.isFinished()) {
        System.out.println("Mover running time : " + StringUtils.formatTime(status.getRunningTime()));
        Thread.sleep(1000);
    }
    // verify after movement
    Assert.assertTrue(status.isSuccessful());
    LocatedBlock lb = dfsClient.getLocatedBlocks(file, 0).get(0);
    StorageType[] storageTypes = lb.getStorageTypes();
    int ssdCount = 0;
    int hddCount = 0;
    for (StorageType storageType : storageTypes) {
        if (storageType == StorageType.SSD) {
            ssdCount++;
        } else if (storageType == StorageType.DISK) {
            hddCount++;
        }
    }
    Assert.assertEquals(1, ssdCount);
    Assert.assertEquals(2, hddCount);
}
Also used : Path(org.apache.hadoop.fs.Path) StorageType(org.apache.hadoop.fs.StorageType) LocatedBlock(org.apache.hadoop.hdfs.protocol.LocatedBlock) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ActionStatus(org.smartdata.actions.ActionStatus) Test(org.junit.Test)

Example 3 with ActionStatus

use of org.smartdata.actions.ActionStatus in project SSM by Intel-bigdata.

the class TestMoveFileAction method testParallelMovers.

@Test(timeout = 300000)
public void testParallelMovers() throws Exception {
    final String file1 = "/testParallelMovers/file1";
    final String file2 = "/testParallelMovers/file2";
    Path dir = new Path("/testParallelMovers");
    dfs.mkdirs(dir);
    // write to DISK
    dfs.setStoragePolicy(dir, "HOT");
    final FSDataOutputStream out1 = dfs.create(new Path(file1));
    out1.writeChars("testParallelMovers1");
    out1.close();
    final FSDataOutputStream out2 = dfs.create(new Path(file2));
    out2.writeChars("testParallelMovers2");
    out2.close();
    // schedule move to ARCHIVE or SSD
    MoveFileAction action1 = new MoveFileAction();
    action1.setDfsClient(dfsClient);
    action1.setContext(smartContext);
    action1.init(file1, "COLD");
    MoveFileAction action2 = new MoveFileAction();
    action2.setDfsClient(dfsClient);
    action2.setContext(smartContext);
    action2.init(file2, "ALL_SSD");
    ActionStatus status1 = action1.getActionStatus();
    ActionStatus status2 = action2.getActionStatus();
    action1.run();
    action2.run();
    while (!status1.isFinished() || !status2.isFinished()) {
        System.out.println("Mover 1 running time : " + StringUtils.formatTime(status1.getRunningTime()));
        System.out.println("Mover 2 running time : " + StringUtils.formatTime(status2.getRunningTime()));
        Thread.sleep(3000);
    }
    Assert.assertTrue(status1.isSuccessful());
    Assert.assertTrue(status2.isSuccessful());
    System.out.println("Mover 1 total running time : " + StringUtils.formatTime(status1.getRunningTime()));
    System.out.println("Mover 2 total running time : " + StringUtils.formatTime(status2.getRunningTime()));
}
Also used : Path(org.apache.hadoop.fs.Path) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ActionStatus(org.smartdata.actions.ActionStatus) Test(org.junit.Test)

Example 4 with ActionStatus

use of org.smartdata.actions.ActionStatus in project SSM by Intel-bigdata.

the class TestMoveFileAction method scheduleMoverWithPercentage.

private void scheduleMoverWithPercentage(String dir, String storageType, long totalSize, long totolBlocks) throws Exception {
    MoveFileAction moveFileAction = new MoveFileAction();
    moveFileAction.setDfsClient(dfsClient);
    moveFileAction.setContext(smartContext);
    moveFileAction.init(dir, storageType);
    ActionStatus status = moveFileAction.getActionStatus();
    moveFileAction.run();
    if (status instanceof MoverStatus) {
        MoverStatus moverStatus = (MoverStatus) status;
        while (!moverStatus.isFinished()) {
            System.out.println("Mover running time : " + StringUtils.formatTime(moverStatus.getRunningTime()));
            System.out.println("Moved/Total : " + moverStatus.getMovedBlocks() + "/" + moverStatus.getTotalBlocks());
            System.out.println("Move percentage : " + moverStatus.getPercentage() * 100 + "%");
            Assert.assertTrue(moverStatus.getPercentage() <= 1);
            Thread.sleep(1000);
        }
        System.out.println("Mover is finished.");
        Assert.assertEquals(1.0f, moverStatus.getPercentage(), 0.00001f);
        Assert.assertEquals(totalSize, moverStatus.getTotalSize());
        Assert.assertEquals(totolBlocks, moverStatus.getTotalBlocks());
    }
}
Also used : ActionStatus(org.smartdata.actions.ActionStatus) MoverStatus(org.smartdata.actions.hdfs.move.MoverStatus)

Example 5 with ActionStatus

use of org.smartdata.actions.ActionStatus in project SSM by Intel-bigdata.

the class TestCheckStorageAction method testCheckStorageAction.

@Test
public void testCheckStorageAction() throws IOException {
    CheckStorageAction checkStorageAction = new CheckStorageAction();
    checkStorageAction.setDfsClient(dfsClient);
    checkStorageAction.setContext(smartContext);
    final String file = "/testParallelMovers/file1";
    dfsClient.mkdirs("/testParallelMovers");
    // write to HDFS
    final OutputStream out = dfsClient.create(file, true);
    byte[] content = ("This is a file containing two blocks" + "......................").getBytes();
    out.write(content);
    out.close();
    // do CheckStorageAction
    checkStorageAction.init(new String[] { file });
    checkStorageAction.run();
    ActionStatus actionStatus = checkStorageAction.getActionStatus();
    System.out.println(StringUtils.formatTime(actionStatus.getRunningTime()));
    Assert.assertTrue(actionStatus.isFinished());
    Assert.assertTrue(actionStatus.isSuccessful());
    Assert.assertEquals(1.0f, actionStatus.getPercentage(), 0.00001f);
    ByteArrayOutputStream resultStream = actionStatus.getResultStream();
    System.out.println(resultStream);
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ActionStatus(org.smartdata.actions.ActionStatus) Test(org.junit.Test)

Aggregations

ActionStatus (org.smartdata.actions.ActionStatus)17 Test (org.junit.Test)7 Path (org.apache.hadoop.fs.Path)5 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)4 IOException (java.io.IOException)3 StorageType (org.apache.hadoop.fs.StorageType)3 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)3 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)3 OutputStream (java.io.OutputStream)2 SmartAction (org.smartdata.actions.SmartAction)2 ActionInfo (org.smartdata.common.actions.ActionInfo)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 BlockLocation (org.apache.hadoop.fs.BlockLocation)1 DFSInputStream (org.apache.hadoop.hdfs.DFSInputStream)1 MoverStatus (org.smartdata.actions.hdfs.move.MoverStatus)1 ActionInfoComparator (org.smartdata.common.actions.ActionInfoComparator)1