Search in sources :

Example 11 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class TestRuleManager method testSubmitNewDisabledRule.

@Test
public void testSubmitNewDisabledRule() throws Exception {
    String rule = "file: every 1s \n | length > 300 | cache";
    long id = ruleManager.submitRule(rule, RuleState.DISABLED);
    RuleInfo ruleInfo = ruleManager.getRuleInfo(id);
    Assert.assertTrue(ruleInfo.getRuleText().equals(rule));
    RuleInfo info = ruleInfo;
    for (int i = 0; i < 5; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    Assert.assertTrue(info.getNumChecked() - ruleInfo.getNumChecked() == 0);
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 12 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class TestRuleManager method testSubmitAutoEndsRule.

@Test
public void testSubmitAutoEndsRule() throws Exception {
    String rule = "file: every 1s from now to now + 2s \n | " + "length > 300 | cache";
    long id = ruleManager.submitRule(rule, RuleState.ACTIVE);
    RuleInfo ruleInfo = ruleManager.getRuleInfo(id);
    Assert.assertTrue(ruleInfo.getRuleText().equals(rule));
    RuleInfo info = ruleInfo;
    for (int i = 0; i < 5; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    Assert.assertTrue(info.getState() == RuleState.FINISHED);
    Assert.assertTrue(info.getNumChecked() - ruleInfo.getNumChecked() <= 3);
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 13 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class TestSmallFileRule method testRule.

@Test(timeout = 180000)
public void testRule() throws Exception {
    waitTillSSMExitSafeMode();
    String rule = "file: path matches \"/test/small_files/file*\" and length < 20KB" + " | compact -containerFile \"/test/small_files/container_file_1\"";
    SmartAdmin admin = new SmartAdmin(smartContext.getConf());
    admin.submitRule(rule, RuleState.ACTIVE);
    Thread.sleep(6000);
    List<RuleInfo> ruleInfoList = admin.listRulesInfo();
    for (RuleInfo info : ruleInfoList) {
        System.out.println(info);
    }
    Assert.assertEquals(1, ruleInfoList.size());
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 14 with RuleInfo

use of org.smartdata.model.RuleInfo 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();
        }
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) ActionDescriptor(org.smartdata.model.ActionDescriptor) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException) RuleInfo(org.smartdata.model.RuleInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 15 with RuleInfo

use of org.smartdata.model.RuleInfo in project SSM by Intel-bigdata.

the class TestRuleDao method testUpdateRule.

@Test
public void testUpdateRule() throws Exception {
    String rule = "file : accessCount(10m) > 20 \n\n" + "and length() > 3 | cache";
    long submitTime = System.currentTimeMillis();
    RuleInfo info1 = new RuleInfo(20L, submitTime, rule, RuleState.ACTIVE, 12, 12, 12);
    ruleDao.insert(info1);
    long rid = ruleDao.update(info1.getId(), RuleState.DISABLED.getValue());
    Assert.assertTrue(rid == info1.getId());
    info1 = ruleDao.getById(info1.getId());
    Assert.assertTrue(info1.getNumChecked() == 12L);
    ruleDao.update(rid, System.currentTimeMillis(), 100, 200);
    RuleInfo info2 = ruleDao.getById(rid);
    Assert.assertTrue(info2.getNumChecked() == 100L);
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Aggregations

RuleInfo (org.smartdata.model.RuleInfo)28 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)6 DetailedRuleInfo (org.smartdata.model.DetailedRuleInfo)6 IOException (java.io.IOException)5 SmartAdmin (org.smartdata.admin.SmartAdmin)4 RuleInfoRepo (org.smartdata.server.engine.rule.RuleInfoRepo)4 CmdletInfo (org.smartdata.model.CmdletInfo)3 ServiceException (com.google.protobuf.ServiceException)2 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 ActionInfo (org.smartdata.model.ActionInfo)2 BackUpInfo (org.smartdata.model.BackUpInfo)2 FileInfo (org.smartdata.model.FileInfo)2 TimeBasedScheduleInfo (org.smartdata.model.rule.TimeBasedScheduleInfo)2 TranslateResult (org.smartdata.model.rule.TranslateResult)2 RuleInfoProto (org.smartdata.protocol.AdminServerProto.RuleInfoProto)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1