Search in sources :

Example 1 with ProcessTimeoutRule

use of com.walmartlabs.concord.policyengine.ProcessTimeoutRule in project concord by walmartlabs.

the class ProcessTimeoutPolicyApplier method apply.

@Override
public void apply(Payload payload, PolicyEngine policy) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    if (cfg == null) {
        return;
    }
    Object processTimeout = cfg.get(Constants.Request.PROCESS_TIMEOUT);
    if (processTimeout == null) {
        return;
    }
    CheckResult<ProcessTimeoutRule, Object> result = policy.getProcessTimeoutPolicy().check(processTimeout);
    result.getDeny().forEach(i -> {
        policyDeny.inc();
        String msg = i.getRule().getMsg() != null ? i.getRule().getMsg() : DEFAULT_PROCESS_TIMEOUT_MSG;
        Object actualTimeout = i.getEntity();
        String limit = i.getRule().getMax();
        logManager.error(processKey, MessageFormat.format(msg, actualTimeout, limit));
    });
    if (!result.getDeny().isEmpty()) {
        throw new ProcessException(processKey, "'processTimeout' value policy violation");
    }
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessTimeoutRule(com.walmartlabs.concord.policyengine.ProcessTimeoutRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Aggregations

ProcessTimeoutRule (com.walmartlabs.concord.policyengine.ProcessTimeoutRule)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1