Search in sources :

Example 6 with RepositoryEntry

use of com.walmartlabs.concord.server.org.project.RepositoryEntry 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

RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)6 UUID (java.util.UUID)3 FetchResult (com.walmartlabs.concord.repository.FetchResult)1 Repository (com.walmartlabs.concord.repository.Repository)1 Snapshot (com.walmartlabs.concord.repository.Snapshot)1 AbstractDaoTest (com.walmartlabs.concord.server.AbstractDaoTest)1 ConcordObjectMapper (com.walmartlabs.concord.server.ConcordObjectMapper)1 GithubRepoInfo (com.walmartlabs.concord.server.events.github.GithubRepoInfo)1 ProjectDao (com.walmartlabs.concord.server.org.project.ProjectDao)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 RepositoryDao (com.walmartlabs.concord.server.org.project.RepositoryDao)1 SecretDao (com.walmartlabs.concord.server.org.secret.SecretDao)1 Payload (com.walmartlabs.concord.server.process.Payload)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1