Search in sources :

Example 31 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class ProcessMetadataProcessor method process.

public void process(UUID instanceId, Variables variables) {
    Map<String, Object> meta = filter(variables.asMap());
    if (meta.isEmpty() || !changed(currentProcessMeta, meta)) {
        return;
    }
    currentProcessMeta = meta;
    ProcessApi client = new ProcessApi(apiClientFactory.create(ApiClientConfiguration.builder().sessionToken(ContextUtils.getSessionToken(variables)).txId(instanceId).build()));
    try {
        ClientUtils.withRetry(RETRY_COUNT, RETRY_INTERVAL, () -> {
            client.updateMetadata(instanceId, meta);
            return null;
        });
    } catch (ApiException e) {
        throw new RuntimeException(e);
    }
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) ApiException(com.walmartlabs.concord.ApiException)

Example 32 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class FilePermissionsIT method test.

@Test
public void test() throws Exception {
    Path src = Paths.get(FilePermissionsIT.class.getResource("filePerm").toURI());
    Path tmpDir = createTempDir();
    IOUtils.copy(src, tmpDir);
    Path testFile = tmpDir.resolve("test.sh");
    Set<PosixFilePermission> permissions = new HashSet<>(Files.getPosixFilePermissions(testFile));
    permissions.add(PosixFilePermission.OWNER_EXECUTE);
    Files.setPosixFilePermissions(testFile, permissions);
    ByteArrayOutputStream payload = new ByteArrayOutputStream();
    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(payload)) {
        IOUtils.zip(zip, tmpDir);
    }
    // ---
    ProcessApi processApi = new ProcessApi(getApiClient());
    StartProcessResponse spr = start(payload.toByteArray());
    assertNotNull(spr.getInstanceId());
    ProcessEntry pir = waitForCompletion(processApi, spr.getInstanceId());
    byte[] ab = getLog(pir.getLogFileName());
    assertLog(".*Hello!.*", ab);
}
Also used : Path(java.nio.file.Path) ProcessApi(com.walmartlabs.concord.client.ProcessApi) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 33 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class ForceSuspendIT method testTask.

@Test
public void testTask() throws Exception {
    String eventName = "ev_" + randomString();
    byte[] payload = archive(ForceSuspendIT.class.getResource("suspendTask").toURI());
    Map<String, Object> input = new HashMap<>();
    input.put("archive", payload);
    input.put("arguments.eventName", eventName);
    Map<String, Object> cfg = new HashMap<>();
    cfg.put("dependencies", new String[] { "mvn://com.walmartlabs.concord.it.tasks:suspend-test:" + ITConstants.PROJECT_VERSION });
    input.put("request", cfg);
    StartProcessResponse spr = start(input);
    ProcessApi processApi = new ProcessApi(getApiClient());
    ProcessEntry pir = waitForStatus(processApi, spr.getInstanceId(), ProcessEntry.StatusEnum.SUSPENDED);
    byte[] ab = getLog(pir.getLogFileName());
    assertLog(".*Requesting suspend.*", ab);
    assertLog(".*Whoa!.*", 0, ab);
    // ---
    processApi.resume(pir.getInstanceId(), eventName, null, null);
    pir = waitForCompletion(processApi, spr.getInstanceId());
    ab = getLog(pir.getLogFileName());
    assertLog(".*Whoa!.*", ab);
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) HashMap(java.util.HashMap) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Example 34 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class AnsibleRetryIT method testSaveRetry.

@Test
public void testSaveRetry() throws Exception {
    URI uri = ProcessIT.class.getResource("ansibleSaveRetry").toURI();
    byte[] payload = archive(uri, ITConstants.DEPENDENCIES_DIR);
    // start the process
    ProcessApi processApi = new ProcessApi(getApiClient());
    StartProcessResponse spr = start(payload);
    // wait for completion
    ProcessEntry pir = waitForCompletion(processApi, spr.getInstanceId());
    assertEquals(ProcessEntry.StatusEnum.FAILED, pir.getStatus());
    // retrieve the retry file
    File r = processApi.downloadAttachment(pir.getInstanceId(), "hello.retry");
    assertNotNull(r);
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) URI(java.net.URI) File(java.io.File) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Example 35 with ProcessApi

use of com.walmartlabs.concord.client.ProcessApi in project concord by walmartlabs.

the class HttpTaskIT method testFollowRedirects.

@Test
public void testFollowRedirects() throws Exception {
    URI dir = HttpTaskIT.class.getResource("httpFollowRedirects").toURI();
    byte[] payload = archive(dir);
    Map<String, Object> input = new HashMap<>();
    input.put("archive", payload);
    input.put("arguments.authToken", mockHttpAuthToken);
    input.put("arguments.url", mockHttpBaseUrl + rule.getPort() + mockHttpPathFollowRedirects);
    StartProcessResponse spr = start(input);
    ProcessApi processApi = new ProcessApi(getApiClient());
    ProcessEntry pir = waitForCompletion(processApi, spr.getInstanceId());
    assertEquals(ProcessEntry.StatusEnum.FINISHED, pir.getStatus());
    byte[] ab = getLog(pir.getLogFileName());
    assertLog(".*Response status code: 302.*", ab);
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) HashMap(java.util.HashMap) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) URI(java.net.URI) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessApi (com.walmartlabs.concord.client.ProcessApi)58 ProcessEntry (com.walmartlabs.concord.client.ProcessEntry)55 StartProcessResponse (com.walmartlabs.concord.client.StartProcessResponse)54 Test (org.junit.jupiter.api.Test)54 HashMap (java.util.HashMap)34 URI (java.net.URI)23 File (java.io.File)4 Path (java.nio.file.Path)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 UUID (java.util.UUID)2 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)2 ConcordProcess (ca.ibodrov.concord.testcontainers.ConcordProcess)1 Payload (ca.ibodrov.concord.testcontainers.Payload)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiClient (com.walmartlabs.concord.ApiClient)1 ApiException (com.walmartlabs.concord.ApiException)1 FormListEntry (com.walmartlabs.concord.client.FormListEntry)1 FormSubmitResponse (com.walmartlabs.concord.client.FormSubmitResponse)1 ITUtils.randomString (com.walmartlabs.concord.it.common.ITUtils.randomString)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1