Search in sources :

Example 16 with RuleInfo

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

the class TestSmartAdmin method test.

@Test
public void test() throws Exception {
    final SmartConf conf = new SmartConf();
    final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
    // dfs not used , but datanode.ReplicaNotFoundException throws without dfs
    final DistributedFileSystem dfs = cluster.getFileSystem();
    final Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
    List<URI> uriList = new ArrayList<>(namenodes);
    conf.set(DFS_NAMENODE_HTTP_ADDRESS_KEY, uriList.get(0).toString());
    conf.set(SmartConfKeys.DFS_SSM_NAMENODE_RPCSERVER_KEY, uriList.get(0).toString());
    // Set db used
    String dbFile = TestDBUtil.getUniqueEmptySqliteDBFile();
    String dbUrl = Util.SQLITE_URL_PREFIX + dbFile;
    conf.set(SmartConfKeys.DFS_SSM_DEFAULT_DB_URL_KEY, dbUrl);
    // rpcServer start in SmartServer
    SmartServer server = SmartServer.createSSM(null, conf);
    SmartAdmin ssmClient = new SmartAdmin(conf);
    while (true) {
        //test getServiceStatus
        String state = ssmClient.getServiceState().getName();
        if ("ACTIVE".equals(state)) {
            break;
        }
        Thread.sleep(1000);
    }
    //test listRulesInfo and submitRule
    List<RuleInfo> ruleInfos = ssmClient.listRulesInfo();
    int ruleCounts0 = ruleInfos.size();
    long ruleId = ssmClient.submitRule("file: every 5s | path matches \"/foo*\"| cachefile", RuleState.DRYRUN);
    ruleInfos = ssmClient.listRulesInfo();
    int ruleCounts1 = ruleInfos.size();
    assertEquals(1, ruleCounts1 - ruleCounts0);
    //test checkRule
    //if success ,no Exception throw
    ssmClient.checkRule("file: every 5s | path matches \"/foo*\"| cachefile");
    boolean caughtException = false;
    try {
        ssmClient.checkRule("file.path");
    } catch (IOException e) {
        caughtException = true;
    }
    assertTrue(caughtException);
    //test getRuleInfo
    RuleInfo ruleInfo = ssmClient.getRuleInfo(ruleId);
    assertNotEquals(null, ruleInfo);
    //test disableRule
    ssmClient.disableRule(ruleId, true);
    assertEquals(RuleState.DISABLED, ssmClient.getRuleInfo(ruleId).getState());
    //test activateRule
    ssmClient.activateRule(ruleId);
    assertEquals(RuleState.ACTIVE, ssmClient.getRuleInfo(ruleId).getState());
    //test deleteRule
    ssmClient.deleteRule(ruleId, true);
    assertEquals(RuleState.DELETED, ssmClient.getRuleInfo(ruleId).getState());
    //test single SSM
    caughtException = false;
    try {
        conf.set(SmartConfKeys.DFS_SSM_RPC_ADDRESS_KEY, "localhost:8043");
        SmartServer.createSSM(null, conf);
    } catch (IOException e) {
        assertEquals("java.io.IOException: Another SmartServer is running", e.toString());
        caughtException = true;
    }
    assertTrue(caughtException);
    //test client close
    caughtException = false;
    ssmClient.close();
    try {
        ssmClient.getRuleInfo(ruleId);
    } catch (IOException e) {
        caughtException = true;
    }
    assertEquals(true, caughtException);
    server.shutdown();
    cluster.shutdown();
}
Also used : MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) SmartAdmin(org.smartdata.admin.SmartAdmin) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) URI(java.net.URI) SmartConf(org.smartdata.conf.SmartConf) RuleInfo(org.smartdata.common.rule.RuleInfo) Test(org.junit.Test)

Example 17 with RuleInfo

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

the class SmartAdminProtocolAdminSideTranslatorPB method listRulesInfo.

@Override
public List<RuleInfo> listRulesInfo() throws IOException {
    try {
        ListRulesInfoRequestProto req = ListRulesInfoRequestProto.newBuilder().build();
        List<RuleInfoProto> infoProtos = rpcProxy.listRulesInfo(null, req).getRulesInfoList();
        if (infoProtos == null) {
            return null;
        }
        List<RuleInfo> ret = new ArrayList<>();
        for (RuleInfoProto infoProto : infoProtos) {
            ret.add(PBHelper.convert(infoProto));
        }
        return ret;
    } catch (ServiceException e) {
        throw PBHelper.getRemoteException(e);
    }
}
Also used : ListRulesInfoRequestProto(org.smartdata.common.protocol.AdminServerProto.ListRulesInfoRequestProto) ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) RuleInfoProto(org.smartdata.common.protocol.AdminServerProto.RuleInfoProto) RuleInfo(org.smartdata.common.rule.RuleInfo)

Example 18 with RuleInfo

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

the class RuleContainer method getRuleInfo.

public RuleInfo getRuleInfo() {
    lockRead();
    RuleInfo ret = ruleInfo.newCopy();
    unlockRead();
    return ret;
}
Also used : RuleInfo(org.smartdata.common.rule.RuleInfo)

Example 19 with RuleInfo

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

Example 20 with RuleInfo

use of org.smartdata.common.rule.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 | cachefile";
    // 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();
    Assert.assertTrue(allRules.size() == 2 * nRules);
    for (RuleInfo info : allRules) {
        System.out.println(info);
    }
}
Also used : RuleInfo(org.smartdata.common.rule.RuleInfo) Test(org.junit.Test)

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