use of org.smartdata.common.rule.RuleState in project SSM by Intel-bigdata.
the class RuleContainer method changeRuleState.
private boolean changeRuleState(RuleState newState, boolean updateDb) throws IOException {
RuleState oldState = ruleInfo.getState();
if (newState == null || oldState == newState) {
return false;
}
try {
switch(newState) {
case ACTIVE:
if (oldState == RuleState.DISABLED || oldState == RuleState.DRYRUN) {
ruleInfo.setState(newState);
if (updateDb && dbAdapter != null) {
dbAdapter.updateRuleInfo(ruleInfo.getId(), newState, 0, 0, 0);
}
return true;
}
break;
case DISABLED:
if (oldState == RuleState.ACTIVE || oldState == RuleState.DRYRUN) {
ruleInfo.setState(newState);
markWorkExit();
if (updateDb && dbAdapter != null) {
dbAdapter.updateRuleInfo(ruleInfo.getId(), newState, 0, 0, 0);
}
return true;
}
break;
case DELETED:
ruleInfo.setState(newState);
markWorkExit();
if (updateDb && dbAdapter != null) {
dbAdapter.updateRuleInfo(ruleInfo.getId(), newState, 0, 0, 0);
}
return true;
case FINISHED:
if (oldState == RuleState.ACTIVE || oldState == RuleState.DRYRUN) {
ruleInfo.setState(newState);
if (updateDb && dbAdapter != null) {
dbAdapter.updateRuleInfo(ruleInfo.getId(), newState, 0, 0, 0);
}
return true;
}
break;
}
} catch (SQLException e) {
throw new IOException(ruleInfo.toString(), e);
}
throw new IOException("Rule state transition " + oldState + " -> " + newState + // TODO: unsupported
" is not supported");
}
use of org.smartdata.common.rule.RuleState in project SSM by Intel-bigdata.
the class RuleQueryExecutor method run.
@Override
public void run() {
if (exited) {
exitSchedule();
}
long rid = ctx.getRuleId();
try {
long startCheckTime = System.currentTimeMillis();
if (ruleManager.isClosed()) {
exitSchedule();
}
RuleInfo info = ruleManager.getRuleInfo(rid);
RuleState state = info.getState();
if (exited || state == RuleState.DELETED || state == RuleState.FINISHED || state == RuleState.DISABLED) {
exitSchedule();
}
TimeBasedScheduleInfo scheduleInfo = tr.getTbScheduleInfo();
if (scheduleInfo.getEndTime() != TimeBasedScheduleInfo.FOR_EVER && // TODO: tricky here, time passed
startCheckTime - scheduleInfo.getEndTime() > 0) {
// TODO: special for scheduleInfo.isOneShot()
LOG.info("Rule " + ctx.getRuleId() + " exit rule executor due to time passed or finished");
ruleManager.updateRuleInfo(rid, RuleState.FINISHED, timeNow(), 0, 0);
exitSchedule();
}
List<String> files = executeFileRuleQuery();
long endCheckTime = System.currentTimeMillis();
int numCmdSubmitted = submitCommands(files, rid);
ruleManager.updateRuleInfo(rid, null, timeNow(), 1, numCmdSubmitted);
if (exited) {
exitSchedule();
}
//System.out.println(this + " -> " + System.currentTimeMillis());
long endProcessTime = System.currentTimeMillis();
if (endProcessTime - startCheckTime > 3000 || LOG.isDebugEnabled()) {
LOG.warn("Rule " + ctx.getRuleId() + " execution took " + (endProcessTime - startCheckTime) + "ms. QueryTime = " + (endCheckTime - startCheckTime) + "ms, SubmitTime = " + (endProcessTime - endCheckTime) + "ms.");
}
} catch (IOException e) {
LOG.error("Rule " + ctx.getRuleId() + " exception", e);
}
}
use of org.smartdata.common.rule.RuleState in project SSM by Intel-bigdata.
the class RuleContainer method doLaunchExecutor.
private RuleQueryExecutor doLaunchExecutor(RuleManager ruleManager) throws IOException {
RuleState state = ruleInfo.getState();
if (state == RuleState.ACTIVE || state == RuleState.DRYRUN) {
if (executor != null && !executor.isExited()) {
return null;
}
ExecutionContext ctx = new ExecutionContext();
ctx.setProperty(ExecutionContext.RULE_ID, ruleInfo.getId());
TranslationContext transCtx = new TranslationContext(ruleInfo.getId(), ruleInfo.getSubmitTime());
TranslateResult tr = executor != null ? executor.getTranslateResult() : ruleManager.doCheckRule(ruleInfo.getRuleText(), transCtx);
executor = new RuleQueryExecutor(ruleManager, ctx, tr, ruleManager.getDbAdapter());
return executor;
}
return null;
}
Aggregations