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);
}
}
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();
}
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();
}
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;
}
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;
}
Aggregations