Search in sources :

Example 6 with SmartAdmin

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) {
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with SmartAdmin

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();
        }
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) FileOutputStream(java.io.FileOutputStream) RuleInfo(org.smartdata.common.rule.RuleInfo) File(java.io.File) Test(org.junit.Test)

Aggregations

SmartAdmin (org.smartdata.admin.SmartAdmin)7 Test (org.junit.Test)5 RuleInfo (org.smartdata.common.rule.RuleInfo)4 IOException (java.io.IOException)3 SmartConf (org.smartdata.conf.SmartConf)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 SmartServiceState (org.smartdata.common.SmartServiceState)1