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;
}
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();
}
}
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);
}
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()]));
}
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());
}
Aggregations