Search in sources :

Example 1 with ForkDepthRule

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

the class ForkPolicyProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    UUID parentInstanceId = payload.getHeader(Payload.PARENT_INSTANCE_ID);
    PolicyEngine policy = payload.getHeader(Payload.POLICY);
    if (policy == null) {
        return chain.process(payload);
    }
    logManager.info(processKey, "Applying fork policies...");
    CheckResult<ForkDepthRule, Integer> result;
    try {
        result = policy.getForkDepthPolicy().check(() -> forkDepthDao.getDepth(parentInstanceId));
    } catch (Exception e) {
        log.error("process -> error", e);
        throw new ProcessException(processKey, "Found fork policy check error", e);
    }
    if (!result.getDeny().isEmpty()) {
        logManager.error(processKey, buildErrorMessage(result.getDeny()));
        throw new ProcessException(processKey, "Found fork policy violations");
    }
    return chain.process(payload);
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ForkDepthRule(com.walmartlabs.concord.policyengine.ForkDepthRule) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Example 2 with ForkDepthRule

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

the class ForkPolicyProcessor method buildErrorMessage.

private String buildErrorMessage(List<CheckResult.Item<ForkDepthRule, Integer>> errors) {
    StringBuilder sb = new StringBuilder();
    for (CheckResult.Item<ForkDepthRule, Integer> e : errors) {
        ForkDepthRule r = e.getRule();
        String msg = r.getMsg() != null ? r.getMsg() : DEFAULT_POLICY_MESSAGE;
        int actualCount = e.getEntity();
        int limit = r.getMax();
        sb.append(MessageFormat.format(msg, actualCount, limit)).append(';');
    }
    return sb.toString();
}
Also used : CheckResult(com.walmartlabs.concord.policyengine.CheckResult) ForkDepthRule(com.walmartlabs.concord.policyengine.ForkDepthRule)

Aggregations

ForkDepthRule (com.walmartlabs.concord.policyengine.ForkDepthRule)2 CheckResult (com.walmartlabs.concord.policyengine.CheckResult)1 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 UUID (java.util.UUID)1