Search in sources :

Example 31 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class ActionDao method searchAction.

public List<ActionInfo> searchAction(String path, long start, long offset, List<String> orderBy, List<Boolean> isDesc, long[] retTotalNumActions) {
    List<ActionInfo> ret;
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    boolean ifHasAid = false;
    String sqlFilter = TABLE_NAME + " WHERE (" + "aid LIKE '%" + path + "%' ESCAPE '/' " + "OR cid LIKE '%" + path + "%' ESCAPE '/' " + "OR args LIKE '%" + path + "%' ESCAPE '/' " + "OR result LIKE '%" + path + "%' ESCAPE '/' " + "OR exec_host LIKE '%" + path + "%' ESCAPE '/' " + "OR progress LIKE '%" + path + "%' ESCAPE '/' " + "OR log LIKE '%" + path + "%' ESCAPE '/' " + "OR action_name LIKE '%" + path + "%' ESCAPE '/')";
    String sql = "SELECT * FROM " + sqlFilter;
    String sqlCount = "SELECT count(*) FROM " + sqlFilter + ";";
    if (orderBy.size() == 0) {
        sql += " LIMIT " + start + "," + offset + ";";
        ret = jdbcTemplate.query(sql, new ActionRowMapper());
    } else {
        sql += " ORDER BY ";
        for (int i = 0; i < orderBy.size(); i++) {
            String ob = orderBy.get(i);
            if (!tableColumns.contains(ob)) {
                continue;
            }
            if (ob.equals("aid")) {
                ifHasAid = true;
            }
            if (ob.equals(RUNNING_TIME)) {
                sql = sql + "(finish_time - create_time)";
            } else {
                sql = sql + ob;
            }
            if (isDesc.size() > i) {
                if (isDesc.get(i)) {
                    sql = sql + " desc ";
                }
                sql = sql + ",";
            }
        }
        if (!ifHasAid) {
            sql = sql + "aid,";
        }
        // delete the last char
        sql = sql.substring(0, sql.length() - 1);
        // add limit
        sql = sql + " LIMIT " + start + "," + offset + ";";
        ret = jdbcTemplate.query(sql, new ActionRowMapper());
    }
    if (retTotalNumActions != null) {
        retTotalNumActions[0] = jdbcTemplate.queryForObject(sqlCount, Long.class);
    }
    return ret;
}
Also used : ActionInfo(org.smartdata.model.ActionInfo) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 32 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestActionRpc method testActionProgress.

@Test
public void testActionProgress() throws Exception {
    waitTillSSMExitSafeMode();
    SmartAdmin admin = new SmartAdmin(smartContext.getConf());
    long cmdId = admin.submitCmdlet("sleep -ms 6000");
    try {
        CmdletInfo cinfo = admin.getCmdletInfo(cmdId);
        long actId = cinfo.getAids().get(0);
        ActionInfo actionInfo;
        while (true) {
            actionInfo = admin.getActionInfo(actId);
            if (actionInfo.isFinished()) {
                Assert.fail("No intermediate progress observed.");
            }
            if (actionInfo.getProgress() > 0 && actionInfo.getProgress() < 1.0) {
                return;
            }
            Thread.sleep(500);
        }
    } finally {
        admin.close();
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 33 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestCmdletManager method testSubmitAPI.

@Test
public void testSubmitAPI() throws Exception {
    waitTillSSMExitSafeMode();
    DistributedFileSystem dfs = cluster.getFileSystem();
    Path dir = new Path("/testMoveFile");
    dfs.mkdirs(dir);
    // Move to SSD
    dfs.setStoragePolicy(dir, "HOT");
    FSDataOutputStream out1 = dfs.create(new Path("/testMoveFile/file1"), true, 1024);
    out1.writeChars("/testMoveFile/file1");
    out1.close();
    Path dir3 = new Path("/testCacheFile");
    dfs.mkdirs(dir3);
    Assert.assertTrue(ActionRegistry.supportedActions().size() > 0);
    CmdletManager cmdletManager = ssm.getCmdletManager();
    long cmdId = cmdletManager.submitCmdlet("allssd -file /testMoveFile/file1 ; cache -file /testCacheFile ; " + "write -file /test -length 1024");
    Thread.sleep(1200);
    List<ActionInfo> actionInfos = cmdletManager.listNewCreatedActions(10);
    Assert.assertTrue(actionInfos.size() > 0);
    while (true) {
        CmdletState state = cmdletManager.getCmdletInfo(cmdId).getState();
        if (state == CmdletState.DONE) {
            break;
        }
        Assert.assertFalse(CmdletState.isTerminalState(state));
        System.out.printf("Cmdlet still running.\n");
        Thread.sleep(1000);
    }
    List<CmdletInfo> com = ssm.getMetaStore().getCmdlets(null, null, CmdletState.DONE);
    Assert.assertTrue(com.size() >= 1);
    List<ActionInfo> result = ssm.getMetaStore().getActions(null, null);
    Assert.assertTrue(result.size() == 3);
}
Also used : Path(org.apache.hadoop.fs.Path) CmdletState(org.smartdata.model.CmdletState) ActionInfo(org.smartdata.model.ActionInfo) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 34 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestCmdletManager method flushToDB.

public void flushToDB(MetaStore metaStore, List<ActionInfo> actionInfos, CmdletInfo cmdletInfo) throws Exception {
    for (ActionInfo actionInfo : actionInfos) {
        cmdletInfo.addAction(actionInfo.getActionId());
    }
    metaStore.insertCmdlet(cmdletInfo);
    metaStore.insertActions(actionInfos.toArray(new ActionInfo[actionInfos.size()]));
}
Also used : ActionInfo(org.smartdata.model.ActionInfo)

Example 35 with ActionInfo

use of org.smartdata.model.ActionInfo in project SSM by Intel-bigdata.

the class TestCmdletManager method testCreateFromDescriptor.

@Test
public void testCreateFromDescriptor() throws Exception {
    waitTillSSMExitSafeMode();
    String cmd = "allssd -file /testMoveFile/file1 ; cache -file /testCacheFile ; " + "write -file /test -length 1024";
    CmdletDescriptor cmdletDescriptor = generateCmdletDescriptor(cmd);
    List<ActionInfo> actionInfos = ssm.getCmdletManager().createActionInfos(cmdletDescriptor, 0);
    Assert.assertTrue(cmdletDescriptor.getActionSize() == actionInfos.size());
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) ActionInfo(org.smartdata.model.ActionInfo) Test(org.junit.Test)

Aggregations

ActionInfo (org.smartdata.model.ActionInfo)48 Test (org.junit.Test)23 HashMap (java.util.HashMap)16 CmdletInfo (org.smartdata.model.CmdletInfo)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 SmartAdmin (org.smartdata.admin.SmartAdmin)5 MetaStore (org.smartdata.metastore.MetaStore)5 Path (org.apache.hadoop.fs.Path)4 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)4 MetaStoreException (org.smartdata.metastore.MetaStoreException)4 FileInfo (org.smartdata.model.FileInfo)4 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)3 ActionScheduler (org.smartdata.model.action.ActionScheduler)3 ServiceException (com.google.protobuf.ServiceException)2 ParseException (java.text.ParseException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 QueueFullException (org.smartdata.exception.QueueFullException)2 DetailedFileAction (org.smartdata.model.DetailedFileAction)2