Search in sources :

Example 1 with TemporaryPath

use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.

the class RunTest method run.

private static int run(String payload, Map<String, Object> extraVars) throws Exception {
    URI uri = RunTest.class.getResource(payload).toURI();
    Path source = Paths.get(uri);
    try (TemporaryPath dst = IOUtils.tempDir("cli-tests")) {
        IOUtils.copy(source, dst.path());
        App app = new App();
        CommandLine cmd = new CommandLine(app);
        List<String> args = new ArrayList<>();
        args.add("run");
        for (Map.Entry<String, Object> e : extraVars.entrySet()) {
            args.add("-e");
            args.add(e.getKey() + "=" + e.getValue());
        }
        args.add(dst.path().toString());
        return cmd.execute(args.toArray(new String[0]));
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) CommandLine(picocli.CommandLine) ArrayList(java.util.ArrayList) URI(java.net.URI) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) Map(java.util.Map)

Example 2 with TemporaryPath

use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.

the class AttachmentsUploader method upload.

public void upload(UUID instanceId, Path workDir) throws Exception {
    Path attachmentsDir = workDir.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME);
    if (!Files.exists(attachmentsDir)) {
        return;
    }
    try (TemporaryPath tmp = IOUtils.tempFile("attachments", ".zip")) {
        try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(Files.newOutputStream(tmp.path()))) {
            IOUtils.zip(zip, attachmentsDir);
        }
        String path = "/api/v1/process/" + instanceId + "/attachment";
        ClientUtils.withRetry(AgentConstants.API_CALL_MAX_RETRIES, AgentConstants.API_CALL_RETRY_DELAY, () -> {
            ClientUtils.postData(apiClient, path, tmp.path().toFile());
            return null;
        });
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath)

Example 3 with TemporaryPath

use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.

the class GitClientFetch2Test method testFetchByPrevCommit.

@Test
public void testFetchByPrevCommit() throws Exception {
    Path repo = GitUtils.createBareRepository(resourceToPath("/master"));
    RevCommit commit0 = GitUtils.addContent(repo, resourceToPath("/test5/0_concord.yml"));
    GitUtils.addContent(repo, resourceToPath("/test5/1_concord.yml"));
    try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
        // fetch master
        fetch(repo.toString(), "master", null, repoPath.path());
        assertContent(repoPath, "master.txt", "master");
        assertContent(repoPath, "0_concord.yml", "0-concord-content");
        assertContent(repoPath, "1_concord.yml", "1-concord-content");
        System.out.println("fetching prev commit");
        // fetch prev commitId
        fetch(repo.toString(), null, commit0.name(), repoPath.path());
        assertNoContent(repoPath, "1_concord.yml");
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.jupiter.api.Test)

Example 4 with TemporaryPath

use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.

the class GitClientFetch2Test method testFetchByBranchAndPrevCommit.

@Test
public void testFetchByBranchAndPrevCommit() throws Exception {
    Path repo = GitUtils.createBareRepository(resourceToPath("/master"));
    RevCommit commit0 = GitUtils.addContent(repo, resourceToPath("/test5/0_concord.yml"));
    GitUtils.addContent(repo, resourceToPath("/test5/1_concord.yml"));
    try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
        // fetch master
        fetch(repo.toString(), "master", null, repoPath.path());
        assertContent(repoPath, "master.txt", "master");
        assertContent(repoPath, "0_concord.yml", "0-concord-content");
        assertContent(repoPath, "1_concord.yml", "1-concord-content");
        // fetch master+prev commitId
        fetch(repo.toString(), "master", commit0.name(), repoPath.path());
        assertNoContent(repoPath, "1_concord.yml");
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.jupiter.api.Test)

Example 5 with TemporaryPath

use of com.walmartlabs.concord.common.TemporaryPath in project concord by walmartlabs.

the class GitClientFetch2Test method testReFetch.

@Test
public void testReFetch() throws Exception {
    Path repo = GitUtils.createBareRepository(resourceToPath("/master"));
    RevCommit commit0 = GitUtils.addContent(repo, resourceToPath("/test5/0_concord.yml"));
    GitUtils.addContent(repo, resourceToPath("/test5/1_concord.yml"));
    try (TemporaryPath repoPath = IOUtils.tempDir("git-client-test")) {
        // fetch master
        fetch(repo.toString(), "master", null, repoPath.path());
        assertContent(repoPath, "master.txt", "master");
        assertContent(repoPath, "0_concord.yml", "0-concord-content");
        assertContent(repoPath, "1_concord.yml", "1-concord-content");
        System.out.println("refetching");
        // refetch master
        fetch(repo.toString(), "master", null, repoPath.path());
        assertContent(repoPath, "1_concord.yml", "1-concord-content");
    }
}
Also used : Path(java.nio.file.Path) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.jupiter.api.Test)

Aggregations

TemporaryPath (com.walmartlabs.concord.common.TemporaryPath)20 Path (java.nio.file.Path)10 Test (org.junit.jupiter.api.Test)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)4 UUID (java.util.UUID)3 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)2 State (com.walmartlabs.concord.svm.State)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Git (org.eclipse.jgit.api.Git)2 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)2 Repository (com.walmartlabs.concord.repository.Repository)1 Secret (com.walmartlabs.concord.sdk.Secret)1 RepositoryUtils.assertRepository (com.walmartlabs.concord.server.org.project.RepositoryUtils.assertRepository)1 ProcessEntry (com.walmartlabs.concord.server.process.ProcessEntry)1 RepositoryRefreshListener (com.walmartlabs.concord.server.repository.listeners.RepositoryRefreshListener)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 URI (java.net.URI)1