Search in sources :

Example 11 with RuleInfo

use of org.smartdata.common.rule.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 | cachefile";
    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.common.rule.RuleInfo) Test(org.junit.Test)

Example 12 with RuleInfo

use of org.smartdata.common.rule.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 | cachefile";
    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.common.rule.RuleInfo) Test(org.junit.Test)

Example 13 with RuleInfo

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

the class TestRuleManager method testSubmitNewActiveRule.

@Test
public void testSubmitNewActiveRule() throws Exception {
    String rule = "file: every 1s \n | accessCount(5s) > 3 | cachefile";
    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.getNumChecked() - ruleInfo.getNumChecked() > 3);
}
Also used : RuleInfo(org.smartdata.common.rule.RuleInfo) Test(org.junit.Test)

Example 14 with RuleInfo

use of org.smartdata.common.rule.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 {
    String dbFile = TestDBUtil.getUniqueDBFilePath();
    Connection conn = null;
    try {
        conn = Util.createSqliteConnection(dbFile);
        Util.initializeDataBase(conn);
        String rule = "file : accessCountX(10m) > 20 \n\n" + "and length() > 3 | cachefile";
        long submitTime = System.currentTimeMillis();
        RuleInfo info1 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
        DBAdapter adapter = new DBAdapter(conn);
        Assert.assertTrue(adapter.insertNewRule(info1));
        RuleInfo info1_1 = adapter.getRuleInfo(info1.getId());
        Assert.assertTrue(info1.equals(info1_1));
        RuleInfo info2 = new RuleInfo(0, submitTime, rule, RuleState.ACTIVE, 0, 0, 0);
        Assert.assertTrue(adapter.insertNewRule(info2));
        RuleInfo info2_1 = adapter.getRuleInfo(info2.getId());
        Assert.assertFalse(info1_1.equals(info2_1));
        List<RuleInfo> infos = adapter.getRuleInfo();
        assert (infos.size() == 2);
    } finally {
        if (conn != null) {
            conn.close();
        }
        File file = new File(dbFile);
        file.deleteOnExit();
    }
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) Connection(java.sql.Connection) RuleInfo(org.smartdata.common.rule.RuleInfo) File(java.io.File) Test(org.junit.Test)

Example 15 with RuleInfo

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

the class DBAdapter method doGetRuleInfo.

private List<RuleInfo> doGetRuleInfo(String sql) throws SQLException {
    QueryHelper queryHelper = new QueryHelper(sql);
    List<RuleInfo> infos = new LinkedList<>();
    try {
        ResultSet rs = queryHelper.executeQuery();
        while (rs.next()) {
            infos.add(new RuleInfo(rs.getLong("id"), rs.getLong("submit_time"), rs.getString("rule_text"), RuleState.fromValue((int) rs.getByte("state")), rs.getLong("checked_count"), rs.getLong("commands_generated"), rs.getLong("last_check_time")));
        }
        return infos;
    } finally {
        queryHelper.close();
    }
}
Also used : ResultSet(java.sql.ResultSet) RuleInfo(org.smartdata.common.rule.RuleInfo) LinkedList(java.util.LinkedList)

Aggregations

RuleInfo (org.smartdata.common.rule.RuleInfo)22 Test (org.junit.Test)14 IOException (java.io.IOException)5 SmartAdmin (org.smartdata.admin.SmartAdmin)4 ArrayList (java.util.ArrayList)3 ServiceException (com.google.protobuf.ServiceException)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 RuleInfoProto (org.smartdata.common.protocol.AdminServerProto.RuleInfoProto)2 DBAdapter (org.smartdata.server.metastore.DBAdapter)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 ListRulesInfoRequestProto (org.smartdata.common.protocol.AdminServerProto.ListRulesInfoRequestProto)1