Search in sources :

Example 6 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class FormServiceV2 method resume.

private void resume(ProcessKey processKey, String eventName, String formName, Map<String, Object> req) {
    Payload payload;
    try {
        payload = payloadManager.createResumePayload(processKey, eventName, req);
    } catch (IOException e) {
        throw new RuntimeException("Error while creating a payload for: " + processKey, e);
    }
    // remove the form when the process resumes
    Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
    payload = payload.putHeader(Payload.RESUME_HOOKS, Collections.singletonList(() -> formManager.delete(workDir, formName)));
    processManager.resume(payload);
}
Also used : Path(java.nio.file.Path) Payload(com.walmartlabs.concord.server.process.Payload) IOException(java.io.IOException)

Example 7 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class PayloadStoreProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    // remove things that shouldn't be in the serialized payload
    Map<String, Object> headers = payload.getHeaders().entrySet().stream().filter(e -> !(e.getValue() instanceof Path)).filter(e -> !EXCLUDED_HEADERS.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    String serializedHeaders = serialize(headers);
    stateManager.tx(tx -> {
        stateManager.insert(tx, processKey, "_initial/payload.json", serializedHeaders.getBytes());
        stateManager.importPath(tx, processKey, "_initial/attachments/", payload.getHeader(Payload.BASE_DIR), (path, basicFileAttributes) -> payload.getAttachments().containsValue(path));
    });
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) Payload(com.walmartlabs.concord.server.process.Payload) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) Arrays(java.util.Arrays) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Collectors(java.util.stream.Collectors) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) Inject(javax.inject.Inject) HashSet(java.util.HashSet) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Map(java.util.Map) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) Named(javax.inject.Named) Path(java.nio.file.Path) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Map(java.util.Map) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 8 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class RepositoryProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, final Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    UUID projectId = payload.getHeader(Payload.PROJECT_ID);
    RepositoryEntry repo = getRepositoryEntry(payload);
    if (projectId == null || repo == null) {
        return chain.process(payload);
    }
    logManager.info(processKey, "Copying the repository's data: {} @ {}:{}, path: {}", repo.getUrl(), repo.getBranch() != null ? repo.getBranch() : "*", repo.getCommitId() != null ? repo.getCommitId() : "head", repo.getPath() != null ? repo.getPath() : "/");
    Path dst = payload.getHeader(Payload.WORKSPACE_DIR);
    Payload newPayload = repositoryManager.withLock(repo.getUrl(), () -> {
        try {
            Repository repository = payload.getHeader(Payload.REPOSITORY);
            if (repository == null) {
                repository = repositoryManager.fetch(projectId, repo, true);
            }
            Snapshot snapshot = repository.export(dst);
            CommitInfo ci = null;
            if (repository.fetchResult() != null) {
                FetchResult r = Objects.requireNonNull(repository.fetchResult());
                ci = new CommitInfo(r.head(), r.branchOrTag(), r.author(), r.message());
            }
            RepositoryInfo i = new RepositoryInfo(repo.getId(), repo.getName(), repo.getUrl(), repo.getPath(), repo.getBranch(), repo.getCommitId(), ci);
            return payload.putHeader(REPOSITORY_INFO_KEY, i).putHeader(Payload.REPOSITORY, repository).putHeader(Payload.REPOSITORY_SNAPSHOT, Collections.singletonList(snapshot));
        } catch (Exception e) {
            log.error("process -> repository error", e);
            logManager.error(processKey, "Error while processing a repository: " + repo.getUrl(), e);
            throw new ProcessException(processKey, "Error while processing a repository: " + repo.getUrl(), e);
        }
    });
    return chain.process(newPayload);
}
Also used : Path(java.nio.file.Path) Snapshot(com.walmartlabs.concord.repository.Snapshot) Repository(com.walmartlabs.concord.repository.Repository) ProcessException(com.walmartlabs.concord.server.process.ProcessException) FetchResult(com.walmartlabs.concord.repository.FetchResult) Payload(com.walmartlabs.concord.server.process.Payload) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) UUID(java.util.UUID) ProcessException(com.walmartlabs.concord.server.process.ProcessException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Aggregations

Payload (com.walmartlabs.concord.server.process.Payload)8 Path (java.nio.file.Path)6 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)5 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)2 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)2 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)2 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)2 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Test (org.junit.jupiter.api.Test)2 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 PolicyEngineRules (com.walmartlabs.concord.policyengine.PolicyEngineRules)1 FetchResult (com.walmartlabs.concord.repository.FetchResult)1