use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestRuleExecutorPlugin method testPlugin.
@Test
public void testPlugin() throws Exception {
waitTillSSMExitSafeMode();
TestPlugin plugin = new TestPlugin();
try {
RuleExecutorPluginManager.addPlugin(plugin);
RuleExecutorPluginManager.addPlugin(plugin);
String rule = "file: every 1s \n | length > 10 | cache";
SmartAdmin client = new SmartAdmin(smartContext.getConf());
long ruleId = client.submitRule(rule, RuleState.ACTIVE);
Assert.assertEquals(plugin.getNumOnNewRuleExecutor(), 1);
Thread.sleep(3000);
Assert.assertEquals(plugin.getNumOnNewRuleExecutor(), 1);
Assert.assertTrue(plugin.getNumPreExecution() >= 2);
Assert.assertTrue(plugin.getNumPreSubmitCmdlet() >= 2);
Assert.assertTrue(plugin.getNumOnRuleExecutorExit() == 0);
client.disableRule(ruleId, true);
Thread.sleep(1100);
int numPreExecution = plugin.getNumPreExecution();
int numPreSubmitCmdlet = plugin.getNumPreSubmitCmdlet();
Thread.sleep(2500);
Assert.assertTrue(plugin.getNumOnNewRuleExecutor() == 1);
Assert.assertTrue(plugin.getNumPreExecution() == numPreExecution);
Assert.assertTrue(plugin.getNumPreSubmitCmdlet() == numPreSubmitCmdlet);
Assert.assertTrue(plugin.getNumOnRuleExecutorExit() == 1);
RuleExecutorPluginManager.deletePlugin(plugin);
client.activateRule(ruleId);
Thread.sleep(500);
Assert.assertTrue(plugin.getNumOnNewRuleExecutor() == 1);
Assert.assertTrue(plugin.getNumPreExecution() == numPreExecution);
} finally {
RuleExecutorPluginManager.deletePlugin(plugin);
}
}
use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestRulePlugin method testPlugin.
@Test
public void testPlugin() throws Exception {
waitTillSSMExitSafeMode();
SimplePlugin plugin = new SimplePlugin();
try {
RulePluginManager.addPlugin(plugin);
int adding = plugin.getAdding();
int added = plugin.getAdded();
SmartAdmin admin = new SmartAdmin(smartContext.getConf());
admin.submitRule("file : path matches \"/home/*\" | cache", RuleState.ACTIVE);
Assert.assertTrue(adding + 1 == plugin.getAdding());
Assert.assertTrue(added + 1 == plugin.getAdded());
try {
admin.submitRule("file : path matches \"/user/*\" | cache", RuleState.DISABLED);
Assert.fail("Should not success.");
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("MUST ACTIVE"));
}
Assert.assertTrue(adding + 1 == plugin.getAdding());
Assert.assertTrue(added + 1 == plugin.getAdded());
} finally {
RulePluginManager.deletePlugin(plugin);
}
}
use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.
the class TestCopy2S3Scheduler method testZeroLength.
@Test(timeout = 45000)
public void testZeroLength() throws Exception {
waitTillSSMExitSafeMode();
MetaStore metaStore = ssm.getMetaStore();
SmartAdmin admin = new SmartAdmin(smartContext.getConf());
DistributedFileSystem dfs = cluster.getFileSystem();
final String srcPath = "/src/";
dfs.mkdirs(new Path(srcPath));
// Write to src
for (int i = 0; i < 3; i++) {
// Create test files
DFSTestUtil.createFile(dfs, new Path(srcPath + i), 0, (short) 1, 1);
}
long ruleId = admin.submitRule("file: path matches \"/src/*\"| copy2s3 -dest s3a://xxxctest/dest/", RuleState.ACTIVE);
Thread.sleep(2500);
List<ActionInfo> actions = metaStore.getActions(ruleId, 0);
Assert.assertEquals(actions.size(), 0);
}
use of org.smartdata.admin.SmartAdmin 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();
}
}
}
Aggregations