Search in sources :

Example 1 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.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 ProcessDefinition

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

the class ProcessHandlersProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    Set<String> handlers = new HashSet<>();
    ProcessDefinition pd = payload.getHeader(Payload.PROJECT_DEFINITION);
    if (pd == null) {
        return chain.process(payload);
    }
    Collection<String> profiles = payload.getHeader(Payload.ACTIVE_PROFILES);
    update(payload, pd, profiles, handlers, Constants.Flows.ON_FAILURE_FLOW, Constants.Request.DISABLE_ON_FAILURE_KEY);
    update(payload, pd, profiles, handlers, Constants.Flows.ON_CANCEL_FLOW, Constants.Request.DISABLE_ON_CANCEL_KEY);
    update(payload, pd, profiles, handlers, Constants.Flows.ON_TIMEOUT_FLOW, Constants.Request.DISABLE_ON_TIMEOUT_KEY);
    payload = payload.putHeader(Payload.PROCESS_HANDLERS, handlers);
    return chain.process(payload);
}
Also used : ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) HashSet(java.util.HashSet)

Example 3 with ProcessDefinition

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

the class EffectiveProcessDefinitionProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessDefinition pd = payload.getHeader(Payload.PROJECT_DEFINITION);
    if (pd == null) {
        return chain.process(payload);
    }
    Options opts = Options.builder().instanceId(payload.getProcessKey().getInstanceId()).parentInstanceId(payload.getHeader(Payload.PARENT_INSTANCE_ID)).configuration(sanitizeConfiguration(payload.getHeader(Payload.CONFIGURATION, Collections.emptyMap()))).activeProfiles(payload.getHeader(Payload.ACTIVE_PROFILES, Collections.emptyList())).build();
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        pd.serialize(opts, out);
        byte[] bytes = out.toByteArray();
        if (bytes.length == 0) {
            return chain.process(payload);
        }
        stateManager.tx(tx -> {
            stateManager.deleteFile(tx, payload.getProcessKey(), EFFECTIVE_YAML_PATH);
            stateManager.insert(tx, payload.getProcessKey(), EFFECTIVE_YAML_PATH, bytes);
        });
    } catch (Exception e) {
        log.warn("process ['{}'] -> error: {}", payload.getProcessKey(), e.getMessage());
        throw new ProcessException(payload.getProcessKey(), "Error while processing effective concord.yml: " + e.getMessage(), e);
    }
    return chain.process(payload);
}
Also used : Options(com.walmartlabs.concord.process.loader.model.Options) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Example 4 with ProcessDefinition

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

the class ConfigurationProcessor method getProfileCfg.

private static Map<String, Object> getProfileCfg(Payload payload, List<String> activeProfiles) {
    if (activeProfiles == null) {
        activeProfiles = Collections.emptyList();
    }
    ProcessDefinition pd = payload.getHeader(Payload.PROJECT_DEFINITION);
    if (pd == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> m = ProcessDefinitionUtils.getVariables(pd, activeProfiles);
    return m != null ? m : Collections.emptyMap();
}
Also used : ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition)

Example 5 with ProcessDefinition

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

the class TriggerResource method refresh.

private void refresh(RepositoryEntry repo) {
    ProcessDefinition pd;
    try {
        pd = repositoryManager.withLock(repo.getUrl(), () -> {
            Repository repository = repositoryManager.fetch(repo.getProjectId(), repo);
            ProjectLoader.Result result = projectLoader.loadProject(repository.path(), importsNormalizerFactory.forProject(repo.getProjectId()), ImportsListener.NOP_LISTENER);
            return result.projectDefinition();
        });
        ProjectValidator.Result result = ProjectValidator.validate(pd);
        if (!result.isValid()) {
            throw new ValidationErrorsException(String.join("\n", result.getErrors()));
        }
    } catch (Exception e) {
        log.error("refresh ['{}'] -> project load error", repo.getId(), e);
        throw new ConcordApplicationException("Refresh failed (repository ID: " + repo.getId() + "): " + e.getMessage(), e);
    }
    triggerManager.refresh(repo.getProjectId(), repo.getId(), pd);
}
Also used : Repository(com.walmartlabs.concord.repository.Repository) RepositoryUtils.assertRepository(com.walmartlabs.concord.server.org.project.RepositoryUtils.assertRepository) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessDefinition(com.walmartlabs.concord.process.loader.model.ProcessDefinition) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) 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