Search in sources :

Example 11 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 12 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)

Example 13 with SmartAdmin

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();
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 14 with SmartAdmin

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

Example 15 with SmartAdmin

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);
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Aggregations

SmartAdmin (org.smartdata.admin.SmartAdmin)19 Test (org.junit.Test)15 IOException (java.io.IOException)7 ActionInfo (org.smartdata.model.ActionInfo)5 RuleInfo (org.smartdata.model.RuleInfo)4 Path (org.apache.hadoop.fs.Path)3 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)3 RuleInfo (org.smartdata.common.rule.RuleInfo)3 MetaStore (org.smartdata.metastore.MetaStore)3 SmartServiceState (org.smartdata.SmartServiceState)2 CmdletInfo (org.smartdata.model.CmdletInfo)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 SmartServiceState (org.smartdata.common.SmartServiceState)1 SmartConf (org.smartdata.conf.SmartConf)1 ActionDescriptor (org.smartdata.model.ActionDescriptor)1 S3FileState (org.smartdata.model.S3FileState)1