Search in sources :

Example 21 with RuleInfo

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

the class TestRulesTable method testRuleInsert.

/**
 * Insert rules into table and retrieve them back.
 * @throws Exception
 */
@Test
public void testRuleInsert() throws Exception {
    initDao();
    MetaStore adapter = new MetaStore(druidPool);
    String rule = "file : accessCount(10m) > 20 \n\n" + "and length() > 3 | cache";
    long submitTime = System.currentTimeMillis();
    RuleInfo info1 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
    Assert.assertTrue(adapter.insertNewRule(info1));
    RuleInfo info11 = adapter.getRuleInfo(info1.getId());
    Assert.assertTrue(info1.equals(info11));
    RuleInfo info2 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
    Assert.assertTrue(adapter.insertNewRule(info2));
    RuleInfo info21 = adapter.getRuleInfo(info2.getId());
    Assert.assertFalse(info11.equals(info21));
    List<RuleInfo> infos = adapter.getRuleInfo();
    assert (infos.size() == 2);
    closeDao();
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 22 with RuleInfo

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

the class TestRuleManager method testSubmitNewMultiRules.

@Test
public void testSubmitNewMultiRules() throws Exception {
    String rule = "file: every 1s \n | length > 300 | cache";
    // id increasing
    int nRules = 3;
    long[] ids = new long[nRules];
    for (int i = 0; i < nRules; i++) {
        ids[i] = ruleManager.submitRule(rule, RuleState.DISABLED);
        System.out.println(ruleManager.getRuleInfo(ids[i]));
        if (i > 0) {
            Assert.assertTrue(ids[i] - ids[i - 1] == 1);
        }
    }
    for (int i = 0; i < nRules; i++) {
        ruleManager.deleteRule(ids[i], true);
        RuleInfo info = ruleManager.getRuleInfo(ids[i]);
        Assert.assertTrue(info.getState() == RuleState.DELETED);
    }
    long[] ids2 = new long[nRules];
    for (int i = 0; i < nRules; i++) {
        ids2[i] = ruleManager.submitRule(rule, RuleState.DISABLED);
        System.out.println(ruleManager.getRuleInfo(ids2[i]));
        if (i > 0) {
            Assert.assertTrue(ids2[i] - ids2[i - 1] == 1);
        }
        Assert.assertTrue(ids2[i] > ids[nRules - 1]);
    }
    System.out.println("\nFinal state:");
    List<RuleInfo> allRules = ruleManager.listRulesInfo();
    // Deleted rules are not included in the list
    Assert.assertTrue(allRules.size() == nRules);
    for (RuleInfo info : allRules) {
        System.out.println(info);
    }
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 23 with RuleInfo

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

the class TestRuleManager method testMultiThreadChangeState.

@Test
public void testMultiThreadChangeState() throws Exception {
    String rule = "file: every 1s \n | length > 10 | cache";
    long now = System.currentTimeMillis();
    long length = 100;
    long fid = 10000;
    FileInfo[] files = { new FileInfo("/tmp/testfile", fid, length, false, (short) 3, 1024, now, now, (short) 1, null, null, (byte) 3, (byte) 0) };
    metaStore.insertFiles(files);
    long rid = ruleManager.submitRule(rule, RuleState.ACTIVE);
    long start = System.currentTimeMillis();
    int nThreads = 2;
    Thread[] threads = new Thread[nThreads];
    for (int i = 0; i < nThreads; i++) {
        threads[i] = new Thread(new StateChangeWorker(rid));
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    long end = System.currentTimeMillis();
    System.out.println("Time used = " + (end - start) + " ms");
    // This is needed due to async threads
    Thread.sleep(1000);
    RuleInfo res = ruleManager.getRuleInfo(rid);
    System.out.println(res);
    Thread.sleep(5000);
    RuleInfo after = ruleManager.getRuleInfo(rid);
    System.out.println(after);
    if (res.getState() == RuleState.ACTIVE) {
        Assert.assertTrue(after.getNumCmdsGen() - res.getNumCmdsGen() <= 6);
    } else {
        Assert.assertTrue(after.getNumCmdsGen() == res.getNumCmdsGen());
    }
}
Also used : FileInfo(org.smartdata.model.FileInfo) RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 24 with RuleInfo

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

the class TestRuleManager method testResumeRule.

@Test
public void testResumeRule() throws Exception {
    String rule = "file: every 1s from now to now + 100s \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 < 2; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    Assert.assertTrue(info.getNumChecked() > ruleInfo.getNumChecked());
    ruleManager.disableRule(ruleInfo.getId(), true);
    Thread.sleep(1000);
    RuleInfo info2 = ruleManager.getRuleInfo(id);
    for (int i = 0; i < 3; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    Assert.assertTrue(info.getNumChecked() == info2.getNumChecked());
    RuleInfo info3 = info;
    ruleManager.activateRule(ruleInfo.getId());
    for (int i = 0; i < 3; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    Assert.assertTrue(info.getNumChecked() > info3.getNumChecked());
}
Also used : RuleInfo(org.smartdata.model.RuleInfo) Test(org.junit.Test)

Example 25 with RuleInfo

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

the class TestRuleManager method testStopRule.

@Test
public void testStopRule() throws Exception {
    String rule = "file: every 1s from now to now + 100s \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 < 2; i++) {
        Thread.sleep(1000);
        info = ruleManager.getRuleInfo(id);
        System.out.println(info);
    }
    ruleManager.deleteRule(ruleInfo.getId(), true);
    Thread.sleep(3000);
    RuleInfo endInfo = ruleManager.getRuleInfo(info.getId());
    System.out.println(endInfo);
    Assert.assertTrue(endInfo.getState() == RuleState.DELETED);
    Assert.assertTrue(endInfo.getNumChecked() - info.getNumChecked() <= 1);
}
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