Search in sources :

Example 16 with PolicyEngine

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

the class ConcordExecutionContextTest method policyEngine.

private static PolicyEngine policyEngine() {
    ProtectedTasksPolicy protectedTasksPolicy = mock(ProtectedTasksPolicy.class);
    when(protectedTasksPolicy.isProtected(eq("task"))).thenReturn(true);
    PolicyEngine policyEngine = mock(PolicyEngine.class);
    when(policyEngine.getProtectedTasksPolicy()).thenReturn(protectedTasksPolicy);
    return policyEngine;
}
Also used : ProtectedTasksPolicy(com.walmartlabs.concord.policyengine.ProtectedTasksPolicy) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine)

Example 17 with PolicyEngine

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

the class PolicyProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    PolicyEngine policy = payload.getHeader(Payload.POLICY);
    if (policy == null) {
        return chain.process(payload);
    }
    logManager.info(processKey, "Applying policies...");
    try {
        // TODO merge check results
        for (PolicyApplier a : appliers) {
            a.apply(payload, policy);
        }
    } catch (ProcessException e) {
        throw e;
    } catch (Exception e) {
        logManager.error(processKey, "Error while applying policy '{}': {}", policy.policyNames(), e);
        throw new ProcessException(processKey, "Policy '" + policy.policyNames() + "' error", e);
    }
    return chain.process(payload);
}
Also used : PolicyApplier(com.walmartlabs.concord.server.process.pipelines.processors.policy.PolicyApplier) ProcessException(com.walmartlabs.concord.server.process.ProcessException) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Example 18 with PolicyEngine

use of com.walmartlabs.concord.policyengine.PolicyEngine 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)

Aggregations

PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)18 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 ProcessException (com.walmartlabs.concord.server.process.ProcessException)3 UUID (java.util.UUID)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 ExecutionException (com.walmartlabs.concord.agent.ExecutionException)2 PolicyEngineRules (com.walmartlabs.concord.policyengine.PolicyEngineRules)2 PolicyException (com.walmartlabs.concord.server.policy.PolicyException)2 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiClient (com.walmartlabs.concord.ApiClient)1 ProcessLog (com.walmartlabs.concord.agent.logging.ProcessLog)1 DependencyEntity (com.walmartlabs.concord.dependencymanager.DependencyEntity)1 AttachmentsRule (com.walmartlabs.concord.policyengine.AttachmentsRule)1 ConcurrentProcessRule (com.walmartlabs.concord.policyengine.ConcurrentProcessRule)1 DependencyRule (com.walmartlabs.concord.policyengine.DependencyRule)1 Dependency (com.walmartlabs.concord.policyengine.DependencyVersionsPolicy.Dependency)1 EntityRule (com.walmartlabs.concord.policyengine.EntityRule)1