Search in sources :

Example 6 with ProcessDefinition

use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.

the class ProcessDefinitionRefreshListener method onRefresh.

@Override
public void onRefresh(DSLContext ctx, RepositoryEntry repo, Path repoPath) throws Exception {
    ProcessDefinition pd = projectLoader.loadProject(repoPath, importsNormalizer.forProject(repo.getProjectId()), ImportsListener.NOP_LISTENER).projectDefinition();
    Set<String> pf = pd.publicFlows();
    if (pf == null || pf.isEmpty()) {
        // all flows are public when no public flows defined
        pf = new HashSet<>(pd.flows().keySet());
    }
    Set<String> entryPoints = pd.flows().keySet().stream().filter(pf::contains).collect(Collectors.toSet());
    List<String> profiles = new ArrayList<>(pd.profiles().keySet());
    Map<String, Object> meta = new HashMap<>();
    meta.put("entryPoints", emptyToNull(entryPoints));
    meta.put("profiles", emptyToNull(profiles));
    repositoryDao.updateMeta(ctx, repo.getId(), meta);
    log.info("onRefresh ['{}', '{}'] -> done ({})", repo.getId(), repoPath, entryPoints);
}
Also used : ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition)

Example 7 with ProcessDefinition

use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.

the class TriggerRefreshListener method onRefresh.

@Override
public void onRefresh(DSLContext ctx, RepositoryEntry repo, Path repoPath) throws Exception {
    if (repo.isTriggersDisabled()) {
        triggerManager.clearTriggers(repo.getProjectId(), repo.getId());
        return;
    }
    log.info("refresh ['{}'] -> triggers", repo.getId());
    ProjectLoader.Result result = projectLoader.loadProject(repoPath, importsNormalizer.forProject(repo.getProjectId()), ImportsListener.NOP_LISTENER);
    ProcessDefinition pd = result.projectDefinition();
    ProjectValidator.Result validationResult = ProjectValidator.validate(pd);
    if (!validationResult.isValid()) {
        throw new ValidationErrorsException(String.join("\n", validationResult.getErrors()));
    }
    triggerManager.refresh(repo.getProjectId(), repo.getId(), pd);
}
Also used : ProjectValidator(com.walmartlabs.concord.server.org.project.ProjectValidator) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) ProjectLoader(com.walmartlabs.concord.process.loader.ProjectLoader) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException)

Example 8 with ProcessDefinition

use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.

the class Lint method call.

@Override
public Integer call() throws Exception {
    if (!Files.isDirectory(targetDir)) {
        throw new IllegalArgumentException("Not a directory: " + targetDir);
    }
    ProjectLoader loader = new ProjectLoader(new NoopImportManager());
    ProcessDefinition pd = loader.loadProject(targetDir, new DummyImportsNormalizer(), verbose ? new CliImportsListener() : null).projectDefinition();
    List<LintResult> lintResults = new ArrayList<>();
    linters().forEach(l -> lintResults.addAll(l.apply(pd)));
    if (!lintResults.isEmpty()) {
        print(lintResults);
        println();
    }
    println("Found:");
    println("  imports: " + pd.imports().items().size());
    println("  profiles: " + pd.profiles().size());
    println("  flows: " + pd.flows().size());
    println("  forms: " + pd.forms().size());
    println("  triggers: " + pd.triggers().size());
    println("  (not counting dynamically imported resources)");
    println();
    printStats(lintResults);
    println();
    boolean hasErrors = hasErrors(lintResults);
    if (hasErrors) {
        println("@|red,bold INVALID|@");
    } else {
        println("@|green,bold VALID|@");
    }
    return hasErrors ? 10 : 0;
}
Also used : NoopImportManager(com.walmartlabs.concord.imports.NoopImportManager) ArrayList(java.util.ArrayList) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) CliImportsListener(com.walmartlabs.concord.cli.runner.CliImportsListener) ProjectLoader(com.walmartlabs.concord.process.loader.ProjectLoader)

Example 9 with ProcessDefinition

use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.

the class ProjectLoader method toResult.

private static Result toResult(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2.Result r) {
    List<Snapshot> snapshots = r.getSnapshots();
    ProcessDefinition pd = new ProcessDefinitionV2(r.getProjectDefinition());
    return new Result() {

        @Override
        public List<Snapshot> snapshots() {
            return snapshots;
        }

        @Override
        public ProcessDefinition projectDefinition() {
            return pd;
        }
    };
}
Also used : Snapshot(com.walmartlabs.concord.repository.Snapshot) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) ProcessDefinitionV2(com.walmartlabs.concord.process.loader.v2.ProcessDefinitionV2)

Example 10 with ProcessDefinition

use of com.walmartlabs.concord.process.loader.model.ProcessDefinition in project concord by walmartlabs.

the class ProcessDefinitionProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
    if (workDir == null) {
        return chain.process(payload);
    }
    UUID projectId = payload.getHeader(Payload.PROJECT_ID);
    try {
        String runtime = getRuntimeType(payload);
        ProjectLoader.Result result = projectLoader.loadProject(workDir, runtime, importsNormalizer.forProject(projectId), new ProcessImportsListener(processKey));
        List<Snapshot> snapshots = result.snapshots();
        payload = PayloadUtils.addSnapshots(payload, snapshots);
        ProcessDefinition pd = result.projectDefinition();
        int depsCount = pd.configuration().dependencies().size();
        if (depsCount > MAX_DEPENDENCIES_COUNT) {
            String msg = String.format("Too many dependencies. Current: %d, maximum allowed: %d", depsCount, MAX_DEPENDENCIES_COUNT);
            throw new ConcordApplicationException(msg, Response.Status.BAD_REQUEST);
        }
        payload = payload.putHeader(Payload.PROJECT_DEFINITION, pd).putHeader(Payload.RUNTIME, pd.runtime()).putHeader(Payload.IMPORTS, pd.imports()).putHeader(Payload.DEPENDENCIES, pd.configuration().dependencies());
        // save the runtime type in the process configuration
        Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION, Collections.emptyMap());
        // make mutable
        cfg = new HashMap<>(cfg);
        cfg.put(Constants.Request.RUNTIME_KEY, runtime);
        payload = payload.putHeader(Payload.CONFIGURATION, cfg);
    } catch (ImportProcessingException e) {
        throw new ProcessException(processKey, "Error while processing import " + e.getImport() + ". Error: " + e.getMessage(), e);
    } catch (Exception e) {
        log.warn("process -> ({}) project loading error: {}", workDir, e.getMessage());
        throw new ProcessException(processKey, "Error while loading the project, check the syntax. " + e.getMessage(), e);
    }
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) ImportProcessingException(com.walmartlabs.concord.imports.ImportProcessingException) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProjectLoader(com.walmartlabs.concord.process.loader.ProjectLoader) ProcessException(com.walmartlabs.concord.server.process.ProcessException) IOException(java.io.IOException) ImportProcessingException(com.walmartlabs.concord.imports.ImportProcessingException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) Snapshot(com.walmartlabs.concord.repository.Snapshot) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException)

Aggregations

ProcessDefinition (com.walmartlabs.concord.process.loader.model.ProcessDefinition)12 ProjectLoader (com.walmartlabs.concord.process.loader.ProjectLoader)4 Snapshot (com.walmartlabs.concord.repository.Snapshot)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 Repository (com.walmartlabs.concord.repository.Repository)2 ProcessException (com.walmartlabs.concord.server.process.ProcessException)2 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)2 CliImportsListener (com.walmartlabs.concord.cli.runner.CliImportsListener)1 ImportProcessingException (com.walmartlabs.concord.imports.ImportProcessingException)1 NoopImportManager (com.walmartlabs.concord.imports.NoopImportManager)1 Options (com.walmartlabs.concord.process.loader.model.Options)1 Profile (com.walmartlabs.concord.process.loader.model.Profile)1 ProcessDefinitionV1 (com.walmartlabs.concord.process.loader.v1.ProcessDefinitionV1)1 ProcessDefinitionV2 (com.walmartlabs.concord.process.loader.v2.ProcessDefinitionV2)1 ProjectValidator (com.walmartlabs.concord.server.org.project.ProjectValidator)1 RepositoryUtils.assertRepository (com.walmartlabs.concord.server.org.project.RepositoryUtils.assertRepository)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1