Search in sources :

Example 11 with ActionStatus

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

the class SetStoragePolicyAction method execute.

@Override
protected void execute() {
    ActionStatus actionStatus = getActionStatus();
    actionStatus.begin();
    try {
        dfsClient.setStoragePolicy(fileName, storagePolicy);
        actionStatus.setSuccessful(true);
    } catch (Exception e) {
        actionStatus.setSuccessful(false);
        throw new RuntimeException(e);
    } finally {
        actionStatus.end();
    }
}
Also used : ActionStatus(org.smartdata.actions.ActionStatus)

Example 12 with ActionStatus

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

the class CommandExecutor method getActionInfo.

public ActionInfo getActionInfo(long actionID) {
    SmartAction smartAction = actionPool.get(actionID);
    ActionStatus status = smartAction.getActionStatus();
    return new ActionInfo(status.getId(), 0, smartAction.getName(), smartAction.getArguments(), status.getResultPrintStream().toString(), status.getLogPrintStream().toString(), status.isSuccessful(), status.getStartTime(), status.isSuccessful(), status.getRunningTime(), status.getPercentage());
}
Also used : SmartAction(org.smartdata.actions.SmartAction) ActionInfo(org.smartdata.common.actions.ActionInfo) ActionStatus(org.smartdata.actions.ActionStatus)

Example 13 with ActionStatus

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

the class CommandExecutor method listNewCreatedActions.

public List<ActionInfo> listNewCreatedActions(int maxNumActions) throws IOException {
    ArrayList<ActionInfo> actionInfos = new ArrayList<>();
    boolean flag = true;
    for (Command cmd : commandPool.getcommands()) {
        long cmdId = cmd.getId();
        for (SmartAction smartAction : cmd.getActions()) {
            ActionStatus status = smartAction.getActionStatus();
            actionInfos.add(new ActionInfo(status.getId(), cmdId, smartAction.getName(), smartAction.getArguments(), status.getResultPrintStream().toString(), status.getLogPrintStream().toString(), status.isSuccessful(), status.getStartTime(), status.isSuccessful(), status.getRunningTime(), status.getPercentage()));
        }
    }
    // Sort and get top maxNumActions
    Collections.sort(actionInfos, new ActionInfoComparator());
    if (maxNumActions >= actionInfos.size()) {
        return actionInfos;
    } else {
        return actionInfos.subList(0, maxNumActions);
    }
}
Also used : ActionInfoComparator(org.smartdata.common.actions.ActionInfoComparator) ArrayList(java.util.ArrayList) SmartAction(org.smartdata.actions.SmartAction) ActionInfo(org.smartdata.common.actions.ActionInfo) ActionStatus(org.smartdata.actions.ActionStatus)

Example 14 with ActionStatus

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

the class TestArchiveFileAction 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
    ArchiveFileAction action = new ArchiveFileAction();
    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.ARCHIVE == 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 15 with ActionStatus

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

the class TestReadFileAction method testExecute.

@Test
public void testExecute() throws IOException {
    String filePath = "/testWriteFile/file";
    int size = 66560;
    writeFile(filePath, size);
    String[] args = { filePath };
    ReadFileAction readFileAction = new ReadFileAction();
    readFileAction.setDfsClient(dfsClient);
    readFileAction.setContext(smartContext);
    readFileAction.init(args);
    readFileAction.run();
    // check results
    ActionStatus actionStatus = readFileAction.getActionStatus();
    Assert.assertTrue(actionStatus.isFinished());
    Assert.assertTrue(actionStatus.isSuccessful());
    System.out.println("Read file action running time : " + StringUtils.formatTime(actionStatus.getRunningTime()));
    Assert.assertEquals(1.0f, actionStatus.getPercentage(), 0.00001f);
}
Also used : 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