Search in sources :

Example 1 with DependencyEntity

use of com.walmartlabs.concord.dependencymanager.DependencyEntity in project concord by walmartlabs.

the class RunnerJobExecutor method resolveDeps.

private Collection<String> resolveDeps(RunnerJob job) throws Exception {
    job.getLog().info("Resolving process dependencies...");
    long t1 = System.currentTimeMillis();
    // combine the default dependencies and the process' dependencies
    Collection<URI> uris = Stream.concat(defaultDependencies.getDependencies().stream(), JobDependencies.get(job).stream()).collect(Collectors.toList());
    uris = rewriteDependencies(job, uris);
    Collection<DependencyEntity> deps = dependencyManager.resolve(uris, new ProgressListener() {

        @Override
        public void onRetry(int retryCount, int maxRetry, long interval, String cause) {
            job.getLog().warn("Error while downloading dependencies: {}", cause);
            job.getLog().info("Retrying in {}ms", interval);
        }

        @Override
        public void onTransferFailed(String error) {
            job.getLog().error(error);
        }
    });
    // check the resolved dependencies against the current policy
    validateDependencies(job, deps);
    // sort dependencies to maintain consistency in runner configurations
    Collection<String> paths = deps.stream().map(DependencyEntity::getPath).map(p -> p.toAbsolutePath().toString()).sorted().collect(Collectors.toList());
    long t2 = System.currentTimeMillis();
    if (job.isDebugMode()) {
        job.getLog().info("Dependency resolution took {}ms", (t2 - t1));
        logDependencies(job, paths);
    } else {
        logDependencies(job, uris);
    }
    return paths;
}
Also used : DependencyEntity(com.walmartlabs.concord.dependencymanager.DependencyEntity) ProgressListener(com.walmartlabs.concord.dependencymanager.ProgressListener) URI(java.net.URI)

Example 2 with DependencyEntity

use of com.walmartlabs.concord.dependencymanager.DependencyEntity in project concord by walmartlabs.

the class DependencyResolver method resolveDeps.

public Collection<String> resolveDeps(ProcessDefinition processDefinition) throws Exception {
    if (verbose) {
        System.out.println("Resolving process dependencies...");
    }
    long t1 = System.currentTimeMillis();
    // combine the default dependencies and the process' dependencies
    Collection<URI> uris = Stream.concat(defaultDependencies.stream(), normalizeUrls(processDefinition.configuration().dependencies()).stream()).collect(Collectors.toList());
    Collection<DependencyEntity> deps = dependencyManager.resolve(uris, new ProgressListener() {

        @Override
        public void onRetry(int retryCount, int maxRetry, long interval, String cause) {
            System.err.println("Error while downloading dependencies: " + cause);
            System.err.println("Retrying in " + interval + "ms");
        }

        @Override
        public void onTransferFailed(String error) {
            System.err.println("Transfer failed: " + error);
        }
    });
    // sort dependencies to maintain consistency in runner configurations
    Collection<String> paths = deps.stream().map(DependencyEntity::getPath).map(p -> p.toAbsolutePath().toString()).sorted().collect(Collectors.toList());
    long t2 = System.currentTimeMillis();
    if (verbose) {
        System.out.println("Dependency resolution took " + ((t2 - t1)) + "ms");
        logDependencies(paths);
    }
    return paths;
}
Also used : DependencyEntity(com.walmartlabs.concord.dependencymanager.DependencyEntity) ProgressListener(com.walmartlabs.concord.dependencymanager.ProgressListener)

Example 3 with DependencyEntity

use of com.walmartlabs.concord.dependencymanager.DependencyEntity in project concord by walmartlabs.

the class RunnerJobExecutor method validateDependencies.

private void validateDependencies(RunnerJob job, Collection<DependencyEntity> resolvedDepEntities) throws ExecutionException {
    PolicyEngine policyEngine = job.getPolicyEngine();
    if (policyEngine == null) {
        return;
    }
    ProcessLog processLog = job.getLog();
    processLog.info("Checking the dependency policy...");
    CheckResult<DependencyRule, DependencyEntity> result = policyEngine.getDependencyPolicy().check(resolvedDepEntities);
    result.getWarn().forEach(d -> processLog.warn("Potentially restricted artifact '{}' (dependency policy: {})", d.getEntity(), d.getRule().getMsg()));
    result.getDeny().forEach(d -> processLog.warn("Artifact '{}' is forbidden by the dependency policy {}", d.getEntity(), d.getRule().getMsg()));
    if (!result.getDeny().isEmpty()) {
        throw new ExecutionException("Found restricted dependencies");
    }
}
Also used : DependencyEntity(com.walmartlabs.concord.dependencymanager.DependencyEntity) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) DependencyRule(com.walmartlabs.concord.policyengine.DependencyRule) ExecutionException(com.walmartlabs.concord.agent.ExecutionException) ProcessLog(com.walmartlabs.concord.agent.logging.ProcessLog)

Example 4 with DependencyEntity

use of com.walmartlabs.concord.dependencymanager.DependencyEntity in project concord by walmartlabs.

the class DependencyPolicyTest method testSingleDepAllowVersion.

@Test
public void testSingleDepAllowVersion() {
    DependencyRule allow = new DependencyRule(null, null, "com.walmartlabs.concord.plugins.basic", null, "0.5.0", "1.0.0");
    DependencyRule deny = new DependencyRule(null, null, "com.walmartlabs.concord.plugins.basic", null, null, null);
    PolicyRules<DependencyRule> rules = new PolicyRules<>(Collections.singletonList(allow), null, Collections.singletonList(deny));
    DependencyPolicy policy = new DependencyPolicy(rules);
    // ---
    DependencyEntity dep1 = buildDependency("com.walmartlabs.concord.plugins.basic", "ansible-tasks", "0.57.1-SNAPSHOT");
    assertAllow(policy, dep1);
    // ---
    DependencyEntity dep2 = buildDependency("com.walmartlabs.concord.plugins.basic", "ansible-tasks", "1.1.1-SNAPSHOT");
    assertDeny(policy, dep2);
    // ---
    DependencyEntity dep3 = buildDependency("com.walmartlabs.concord.plugins.basic", "ansible-tasks", "0.4.9");
    assertDeny(policy, dep3);
    // ---
    DependencyEntity dep4 = buildDependency("com.walmartlabs.concord.plugins.basic", "ansible-tasks", "1.0.1");
    assertDeny(policy, dep4);
}
Also used : DependencyEntity(com.walmartlabs.concord.dependencymanager.DependencyEntity) Test(org.junit.jupiter.api.Test)

Example 5 with DependencyEntity

use of com.walmartlabs.concord.dependencymanager.DependencyEntity in project concord by walmartlabs.

the class DependencyPolicyTest method testSingleDepAllow.

@Test
public void testSingleDepAllow() {
    DependencyRule di = new DependencyRule(null, null, "com.walmartlabs.concord.plugins.basic", null, null, null);
    PolicyRules<DependencyRule> rules = new PolicyRules<>(Collections.singletonList(di), null, null);
    DependencyPolicy policy = new DependencyPolicy(rules);
    DependencyEntity dependency = buildDependency("com.walmartlabs.concord.plugins.basic", "ansible-tasks", "0.57.1-SNAPSHOT");
    // ---
    assertAllow(policy, dependency);
}
Also used : DependencyEntity(com.walmartlabs.concord.dependencymanager.DependencyEntity) Test(org.junit.jupiter.api.Test)

Aggregations

DependencyEntity (com.walmartlabs.concord.dependencymanager.DependencyEntity)7 Test (org.junit.jupiter.api.Test)3 ProgressListener (com.walmartlabs.concord.dependencymanager.ProgressListener)2 ExecutionException (com.walmartlabs.concord.agent.ExecutionException)1 ProcessLog (com.walmartlabs.concord.agent.logging.ProcessLog)1 DependencyRule (com.walmartlabs.concord.policyengine.DependencyRule)1 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1