Search in sources :

Example 1 with RuleState

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");
}
Also used : RuleState(org.smartdata.common.rule.RuleState) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with RuleState

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);
    }
}
Also used : RuleState(org.smartdata.common.rule.RuleState) IOException(java.io.IOException) RuleInfo(org.smartdata.common.rule.RuleInfo) TimeBasedScheduleInfo(org.smartdata.server.rule.parser.TimeBasedScheduleInfo)

Example 3 with RuleState

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;
}
Also used : RuleState(org.smartdata.common.rule.RuleState) ExecutionContext(org.smartdata.server.metastore.ExecutionContext) TranslateResult(org.smartdata.server.rule.parser.TranslateResult) TranslationContext(org.smartdata.server.rule.parser.TranslationContext)

Aggregations

RuleState (org.smartdata.common.rule.RuleState)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)1 RuleInfo (org.smartdata.common.rule.RuleInfo)1 ExecutionContext (org.smartdata.server.metastore.ExecutionContext)1 TimeBasedScheduleInfo (org.smartdata.server.rule.parser.TimeBasedScheduleInfo)1 TranslateResult (org.smartdata.server.rule.parser.TranslateResult)1 TranslationContext (org.smartdata.server.rule.parser.TranslationContext)1