Search in sources :

Example 1 with Snapshot

use of com.walmartlabs.concord.repository.Snapshot in project concord by walmartlabs.

the class ProjectLoader method toResult.

private static Result toResult(com.walmartlabs.concord.project.ProjectLoader.Result r) {
    List<Snapshot> snapshots = r.getSnapshots();
    ProcessDefinition pd = new ProcessDefinitionV1(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) ProcessDefinitionV1(com.walmartlabs.concord.process.loader.v1.ProcessDefinitionV1)

Example 2 with Snapshot

use of com.walmartlabs.concord.repository.Snapshot in project concord by walmartlabs.

the class ProjectLoaderV2 method load.

public Result load(Path baseDir, ImportsNormalizer importsNormalizer, ImportsListener listener) throws Exception {
    YamlParserV2 parser = new YamlParserV2();
    // load the initial ProcessDefinition from the root concord.yml file
    // it will be used to determine whether we need to load other resources (e.g. imports)
    ProcessDefinition root = loadRoot(parser, baseDir);
    List<Snapshot> snapshots = Collections.emptyList();
    if (root != null) {
        Imports imports = importsNormalizer.normalize(root.imports());
        snapshots = importManager.process(imports, baseDir, listener);
    }
    List<Path> files = loadResources(baseDir, root != null ? root.resources() : Resources.builder().build());
    Collections.sort(files);
    List<ProcessDefinition> definitions = new ArrayList<>();
    for (Path p : files) {
        definitions.add(parser.parse(baseDir, p));
    }
    if (root != null) {
        definitions.add(root);
    }
    if (definitions.isEmpty()) {
        throw new IllegalStateException("Can't find any Concord process definition files in '" + baseDir + "'");
    }
    return new Result(snapshots, merge(definitions));
}
Also used : Snapshot(com.walmartlabs.concord.repository.Snapshot) YamlParserV2(com.walmartlabs.concord.runtime.v2.parser.YamlParserV2) Imports(com.walmartlabs.concord.imports.Imports)

Example 3 with Snapshot

use of com.walmartlabs.concord.repository.Snapshot in project concord by walmartlabs.

the class DefaultImportManager method process.

@Override
public List<Snapshot> process(Imports imports, Path dest, ImportsListener listener) throws Exception {
    if (listener == null) {
        listener = ImportsListener.NOP_LISTENER;
    }
    List<Snapshot> result = new ArrayList<>();
    List<Import> items = imports.items();
    if (items == null || items.isEmpty()) {
        return result;
    }
    listener.onStart(items);
    for (Import i : items) {
        listener.beforeImport(i);
        Snapshot s;
        try {
            s = assertProcessor(i.type()).process(i, dest);
        } catch (Exception e) {
            throw new ImportProcessingException(i, e);
        }
        listener.afterImport(i);
        result.add(s);
    }
    listener.onEnd(items);
    return result;
}
Also used : Snapshot(com.walmartlabs.concord.repository.Snapshot) ArrayList(java.util.ArrayList)

Example 4 with Snapshot

use of com.walmartlabs.concord.repository.Snapshot in project concord by walmartlabs.

the class ProjectLoader method loadProject.

/**
 * Loads the project definition using the supplied path. Processes the configured
 * imports, templates and extra directories with project files.
 *
 * @param workDir       the directory containing the project files. If {@code imports} are
 *                      configured, the directory will be used as a target for repository
 *                      checkouts.
 */
public Result loadProject(Path workDir, ImportsNormalizer importsNormalizer, ImportsListener listener) throws Exception {
    workDir = workDir.normalize().toAbsolutePath();
    ProjectDefinition initial = initialLoad(workDir);
    Resources resources = initial.getResources();
    Imports imports = importsNormalizer.normalize(initial.getImports());
    List<Snapshot> snapshots = importManager.process(imports, workDir, listener);
    ProjectDefinitionBuilder b = new ProjectDefinitionBuilder(parser);
    List<String> projectPaths = resources.getProjectFilePaths();
    if (projectPaths != null) {
        for (String n : projectPaths) {
            Path p = assertLocal(workDir, workDir.resolve(n));
            if (Files.exists(p)) {
                b.addProjects(p);
            }
        }
    }
    for (String n : Constants.Files.PROJECT_ROOT_FILE_NAMES) {
        Path p = assertLocal(workDir, workDir.resolve(n));
        if (Files.exists(p)) {
            b.addProjectFile(workDir, p);
            break;
        }
    }
    List<String> definitionPaths = resources.getDefinitionPaths();
    if (definitionPaths != null) {
        for (String n : definitionPaths) {
            Path p = assertLocal(workDir, workDir.resolve(n));
            if (Files.exists(p)) {
                b.addDefinitions(p);
            }
        }
    }
    List<String> profilesPaths = resources.getProfilesPaths();
    if (profilesPaths != null) {
        for (String n : profilesPaths) {
            Path p = assertLocal(workDir, workDir.resolve(n));
            if (Files.exists(p)) {
                b.addProfiles(p);
            }
        }
    }
    ProjectDefinition pd = b.build();
    // save the normalized imports, so the exact same workDir structure
    // can be re-created later (e.g. by the Agent)
    pd = new ProjectDefinition(pd, imports);
    return new Result(snapshots, pd);
}
Also used : Path(java.nio.file.Path) Snapshot(com.walmartlabs.concord.repository.Snapshot) Resources(com.walmartlabs.concord.project.model.Resources) Imports(com.walmartlabs.concord.imports.Imports) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) FileVisitResult(java.nio.file.FileVisitResult)

Example 5 with Snapshot

use of com.walmartlabs.concord.repository.Snapshot 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)

Aggregations

Snapshot (com.walmartlabs.concord.repository.Snapshot)8 Path (java.nio.file.Path)4 ProcessDefinition (com.walmartlabs.concord.process.loader.model.ProcessDefinition)3 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)3 Imports (com.walmartlabs.concord.imports.Imports)2 ProcessException (com.walmartlabs.concord.server.process.ProcessException)2 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)2 ImportProcessingException (com.walmartlabs.concord.imports.ImportProcessingException)1 ProjectLoader (com.walmartlabs.concord.process.loader.ProjectLoader)1 ProcessDefinitionV1 (com.walmartlabs.concord.process.loader.v1.ProcessDefinitionV1)1 ProcessDefinitionV2 (com.walmartlabs.concord.process.loader.v2.ProcessDefinitionV2)1 ProjectDefinition (com.walmartlabs.concord.project.model.ProjectDefinition)1 Resources (com.walmartlabs.concord.project.model.Resources)1 FetchResult (com.walmartlabs.concord.repository.FetchResult)1 Repository (com.walmartlabs.concord.repository.Repository)1 YamlParserV2 (com.walmartlabs.concord.runtime.v2.parser.YamlParserV2)1 RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)1 Payload (com.walmartlabs.concord.server.process.Payload)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 IOException (java.io.IOException)1