use of org.smartdata.model.CmdletInfo 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.CmdletInfo in project SSM by Intel-bigdata.
the class TestMetaStore method testdeleteFinishedCmdletsWithGenTimeBefore.
@Test
public void testdeleteFinishedCmdletsWithGenTimeBefore() throws Exception {
Map<String, String> args = new HashMap();
CmdletInfo command1 = new CmdletInfo(0, 78, CmdletState.CANCELLED, "test", 123L, 232444444L);
metaStore.insertCmdlet(command1);
CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.DONE, "tt", 128L, 232444994L);
metaStore.insertCmdlet(command2);
ActionInfo actionInfo = new ActionInfo(1, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100);
metaStore.insertAction(actionInfo);
ActionInfo actionInfo2 = new ActionInfo(2, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100);
metaStore.insertAction(actionInfo2);
ActionInfo actionInfo3 = new ActionInfo(3, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100);
metaStore.insertAction(actionInfo3);
metaStore.deleteFinishedCmdletsWithGenTimeBefore(125);
Assert.assertTrue(metaStore.getCmdletById(0) == null);
Assert.assertTrue(metaStore.getActionById(1) == null);
Assert.assertTrue(metaStore.getActionById(2) != null);
}
use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.
the class TestMetaStore method testUpdateDeleteCommand.
@Test
public void testUpdateDeleteCommand() throws Exception {
long commandId = 0;
commandId = metaStore.getMaxCmdletId();
System.out.printf("CommandID = %d\n", commandId);
CmdletInfo command1 = new CmdletInfo(0, 1, CmdletState.PENDING, "test", 123123333L, 232444444L);
CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.PENDING, "tt", 123178333L, 232444994L);
CmdletInfo[] commands = { command1, command2 };
metaStore.insertCmdlets(commands);
String cidCondition = ">= 1 ";
String ridCondition = "= 78 ";
List<CmdletInfo> com = metaStore.getCmdlets(cidCondition, ridCondition, CmdletState.PENDING);
commandId = metaStore.getMaxCmdletId();
Assert.assertTrue(commandId == commands.length);
for (CmdletInfo cmd : com) {
// System.out.printf("Cid = %d \n", cmd.getCid());
metaStore.updateCmdlet(cmd.getCid(), CmdletState.DONE);
}
List<CmdletInfo> com1 = metaStore.getCmdlets(cidCondition, ridCondition, CmdletState.DONE);
Assert.assertTrue(com1.size() == 1);
Assert.assertTrue(com1.get(0).getState().equals(CmdletState.DONE));
metaStore.deleteCmdlet(command2.getCid());
com1 = metaStore.getCmdlets(cidCondition, ridCondition, CmdletState.DONE);
Assert.assertTrue(com1.size() == 0);
}
use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.
the class TestSmartAdmin method test.
@Test
public void test() throws Exception {
waitTillSSMExitSafeMode();
SmartAdmin admin = null;
try {
admin = new SmartAdmin(smartContext.getConf());
// test listRulesInfo and submitRule
List<RuleInfo> ruleInfos = admin.listRulesInfo();
int ruleCounts0 = ruleInfos.size();
long ruleId = admin.submitRule("file: every 5s | path matches \"/foo*\"| cache", RuleState.DRYRUN);
ruleInfos = admin.listRulesInfo();
int ruleCounts1 = ruleInfos.size();
assertEquals(1, ruleCounts1 - ruleCounts0);
// test checkRule
// if success ,no Exception throw
admin.checkRule("file: every 5s | path matches \"/foo*\"| cache");
boolean caughtException = false;
try {
admin.checkRule("file.path");
} catch (IOException e) {
caughtException = true;
}
assertTrue(caughtException);
// test getRuleInfo
RuleInfo ruleInfo = admin.getRuleInfo(ruleId);
assertNotEquals(null, ruleInfo);
// test disableRule
admin.disableRule(ruleId, true);
assertEquals(RuleState.DISABLED, admin.getRuleInfo(ruleId).getState());
// test activateRule
admin.activateRule(ruleId);
assertEquals(RuleState.ACTIVE, admin.getRuleInfo(ruleId).getState());
// test deleteRule
admin.deleteRule(ruleId, true);
assertEquals(RuleState.DELETED, admin.getRuleInfo(ruleId).getState());
// test cmdletInfo
long id = admin.submitCmdlet("cache -file /foo*");
CmdletInfo cmdletInfo = admin.getCmdletInfo(id);
assertTrue("cache -file /foo*".equals(cmdletInfo.getParameters()));
// test actioninfo
List<Long> aidlist = cmdletInfo.getAids();
assertNotEquals(0, aidlist.size());
ActionInfo actionInfo = admin.getActionInfo(aidlist.get(0));
assertEquals(id, actionInfo.getCmdletId());
// test listActionInfoOfLastActions
admin.listActionInfoOfLastActions(2);
List<ActionDescriptor> actions = admin.listActionsSupported();
assertTrue(actions.size() > 0);
// test client close
admin.close();
try {
admin.getRuleInfo(ruleId);
Assert.fail("Should fail because admin has closed.");
} catch (IOException e) {
}
admin = null;
} finally {
if (admin != null) {
admin.close();
}
}
}
use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.
the class TestCmdletDao method testGetAPageOfAction.
@Test
public void testGetAPageOfAction() {
CmdletInfo cmdlet1 = new CmdletInfo(0, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
CmdletInfo cmdlet2 = new CmdletInfo(1, 78, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
cmdletDao.insert(new CmdletInfo[] { cmdlet1, cmdlet2 });
List<String> order = new ArrayList<>();
order.add("cid");
List<Boolean> desc = new ArrayList<>();
desc.add(false);
Assert.assertTrue(cmdletDao.getAPageOfCmdlet(1, 1, order, desc).get(0).equals(cmdlet2));
}
Aggregations