use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestSubmitRule method testSubmitRule.
@Test
public void testSubmitRule() throws Exception {
String rule = "file: every 1s \n | length > 10 | cachefile";
SmartAdmin client = new SmartAdmin(conf);
long ruleId = 0l;
boolean wait = true;
while (wait) {
try {
ruleId = client.submitRule(rule, RuleState.ACTIVE);
wait = false;
} catch (IOException e) {
if (!e.toString().contains("not ready")) {
throw e;
}
}
}
for (int i = 0; i < 10; i++) {
long id = client.submitRule(rule, RuleState.ACTIVE);
Assert.assertTrue(ruleId + i + 1 == id);
}
String badRule = "something else";
try {
client.submitRule(badRule, RuleState.ACTIVE);
Assert.fail("Should have an exception here");
} catch (IOException e) {
}
try {
client.checkRule(badRule);
Assert.fail("Should have an exception here");
} catch (IOException e) {
}
}
use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestSubmitRuleThroughCli method test.
@Test
public void test() throws Exception {
waitTillSSMExitSafeMode();
String ruleFile = TestDBUtil.getUniqueFilePath();
try {
String rule = "file: every 1s \n | length > 10 | cachefile";
FileOutputStream os = new FileOutputStream(ruleFile);
os.write(rule.getBytes());
os.close();
SmartAdmin client = new SmartAdmin(conf);
String[] args = new String[] { "submitrule", ruleFile };
SmartShell.main(args);
Thread.sleep(2000);
List<RuleInfo> infos = client.listRulesInfo();
Assert.assertTrue(infos.size() == 1);
Thread.sleep(1500);
List<RuleInfo> infos2 = client.listRulesInfo();
long diff = infos2.get(0).getNumChecked() - infos.get(0).getNumChecked();
Assert.assertTrue(diff >= 1);
} finally {
File f = new File(ruleFile);
if (f.exists()) {
f.deleteOnExit();
}
}
}
use of org.smartdata.admin.SmartAdmin 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.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestGetRuleInfo method testGetSingleRuleInfo.
@Test
public void testGetSingleRuleInfo() throws Exception {
waitTillSSMExitSafeMode();
String rule = "file: every 1s \n | length > 10 | cache";
SmartAdmin client = new SmartAdmin(smartContext.getConf());
long ruleId = client.submitRule(rule, RuleState.ACTIVE);
RuleInfo info1 = client.getRuleInfo(ruleId);
System.out.println(info1);
Assert.assertTrue(info1.getRuleText().equals(rule));
RuleInfo infoTemp = info1;
for (int i = 0; i < 3; i++) {
Thread.sleep(1000);
infoTemp = client.getRuleInfo(ruleId);
System.out.println(infoTemp);
}
Assert.assertTrue(infoTemp.getNumChecked() >= info1.getNumChecked() + 2);
long fakeRuleId = 10999999999L;
try {
client.getRuleInfo(fakeRuleId);
Assert.fail("Should raise an exception when using a invalid rule id");
} catch (IOException e) {
}
}
use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestGetRuleInfo method testMultiRules.
@Test
public void testMultiRules() throws Exception {
waitTillSSMExitSafeMode();
String rule = "file: every 1s \n | length > 10 | cache";
SmartAdmin client = new SmartAdmin(smartContext.getConf());
int nRules = 10;
for (int i = 0; i < nRules; i++) {
client.submitRule(rule, RuleState.ACTIVE);
}
List<RuleInfo> ruleInfos = client.listRulesInfo();
for (RuleInfo info : ruleInfos) {
System.out.println(info);
}
Assert.assertTrue(ruleInfos.size() == nRules);
}
Aggregations