Search in sources :

Example 1 with RuleInfo

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

the class ClientSmartProtocolServerSideTranslatorPB method listRulesInfo.

@Override
public ListRulesInfoResponseProto listRulesInfo(RpcController controller, ListRulesInfoRequestProto req) throws ServiceException {
    try {
        List<RuleInfo> infos = server.listRulesInfo();
        List<RuleInfoProto> infoProtos = new ArrayList<>();
        for (RuleInfo info : infos) {
            infoProtos.add(PBHelper.convert(info));
        }
        return ListRulesInfoResponseProto.newBuilder().addAllRulesInfo(infoProtos).build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) RuleInfoProto(org.smartdata.common.protocol.AdminServerProto.RuleInfoProto) IOException(java.io.IOException) RuleInfo(org.smartdata.common.rule.RuleInfo)

Example 2 with RuleInfo

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

the class TestDruid method test.

@Test
public void test() throws Exception {
    InputStream in = getClass().getClassLoader().getResourceAsStream("druid-template.xml");
    Properties p = new Properties();
    p.loadFromXML(in);
    String dbFile = TestDBUtil.getUniqueEmptySqliteDBFile();
    String url = Util.SQLITE_URL_PREFIX + dbFile;
    p.setProperty("url", url);
    DruidPool druidPool = new DruidPool(p);
    DBAdapter adapter = new DBAdapter(druidPool);
    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);
    Assert.assertTrue(adapter.insertNewRule(info1));
    RuleInfo info1_1 = adapter.getRuleInfo(info1.getId());
    Assert.assertTrue(info1.equals(info1_1));
    long now = System.currentTimeMillis();
    adapter.updateRuleInfo(info1.getId(), RuleState.DELETED, now, 1, 1);
    RuleInfo info1_2 = adapter.getRuleInfo(info1.getId());
    Assert.assertTrue(info1_2.getLastCheckTime() == now);
    druidPool.close();
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) InputStream(java.io.InputStream) Properties(java.util.Properties) RuleInfo(org.smartdata.common.rule.RuleInfo) DruidPool(org.smartdata.server.metastore.DruidPool) Test(org.junit.Test)

Example 3 with RuleInfo

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

the class RuleManager method submitRule.

/**
   * Submit a rule to RuleManger.
   * @param rule
   * @param initState
   * @return
   * @throws IOException
   */
public long submitRule(String rule, RuleState initState) throws IOException {
    LOG.error("Received Rule -> [" + rule + "]");
    if (initState != RuleState.ACTIVE && initState != RuleState.DISABLED && initState != RuleState.DRYRUN) {
        throw new IOException("Invalid initState = " + initState + ", it MUST be one of [" + RuleState.ACTIVE + ", " + RuleState.DRYRUN + ", " + RuleState.DISABLED + "]");
    }
    TranslateResult tr = doCheckRule(rule, null);
    RuleInfo.Builder builder = RuleInfo.newBuilder();
    builder.setRuleText(rule).setState(initState);
    RuleInfo ruleInfo = builder.build();
    try {
        dbAdapter.insertNewRule(ruleInfo);
    } catch (SQLException e) {
        throw new IOException("RuleText = " + rule, e);
    }
    RuleContainer container = new RuleContainer(ruleInfo, dbAdapter);
    mapRules.put(ruleInfo.getId(), container);
    submitRuleToScheduler(container.launchExecutor(this));
    return ruleInfo.getId();
}
Also used : SQLException(java.sql.SQLException) TranslateResult(org.smartdata.server.rule.parser.TranslateResult) IOException(java.io.IOException) RuleInfo(org.smartdata.common.rule.RuleInfo)

Example 4 with RuleInfo

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

the class RuleManager method init.

/**
   * Init RuleManager, this includes:
   *    1. Load related data from local storage or HDFS
   *    2. Initial
   * @throws IOException
   */
public boolean init(DBAdapter dbAdapter) throws IOException {
    LOG.info("Initializing ...");
    this.dbAdapter = dbAdapter;
    // Load rules table
    List<RuleInfo> rules = null;
    try {
        rules = dbAdapter.getRuleInfo();
    } catch (SQLException e) {
        LOG.error("Can not load rules from database:\n" + e.getMessage());
    }
    for (RuleInfo rule : rules) {
        mapRules.put(rule.getId(), new RuleContainer(rule, dbAdapter));
    }
    LOG.info("Initialized. Totally " + rules.size() + " rules loaded from DataBase.");
    if (LOG.isDebugEnabled()) {
        for (RuleInfo info : rules) {
            LOG.debug("\t" + info);
        }
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) RuleInfo(org.smartdata.common.rule.RuleInfo)

Example 5 with RuleInfo

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

the class RuleManager method start.

/**
   * Start services
   */
public boolean start() throws IOException {
    LOG.info("Starting ...");
    // after StateManager be ready
    int numLaunched = 0;
    // Submit runnable rules to scheduler
    for (RuleContainer container : mapRules.values()) {
        RuleInfo rule = container.getRuleInfoRef();
        if (rule.getState() == RuleState.ACTIVE || rule.getState() == RuleState.DRYRUN) {
            boolean sub = submitRuleToScheduler(container.launchExecutor(this));
            numLaunched += sub ? 1 : 0;
        }
    }
    LOG.info("Started. " + numLaunched + " rules launched for execution.");
    return true;
}
Also used : RuleInfo(org.smartdata.common.rule.RuleInfo)

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