Search in sources :

Example 1 with ApiException

use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.

the class ConcordTask method getOutVars.

@SuppressWarnings("unchecked")
private Map<String, Object> getOutVars(Context ctx, UUID processId) throws Exception {
    return withClient(ctx, client -> {
        ProcessApi api = new ProcessApi(client);
        File f = null;
        try {
            f = api.downloadAttachment(processId, "out.json");
            ObjectMapper om = new ObjectMapper();
            return om.readValue(f, Map.class);
        } catch (ApiException e) {
            if (e.getCode() == 404) {
                return null;
            }
            log.error("Error while reading the out variables", e);
            throw e;
        } finally {
            IOUtils.delete(f);
        }
    });
}
Also used : File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(com.walmartlabs.concord.ApiException)

Example 2 with ApiException

use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.

the class ClientUtils method withRetry.

public static <T> T withRetry(int retryCount, long retryInterval, Callable<T> c) throws ApiException {
    Exception exception = null;
    int tryCount = 0;
    while (!Thread.currentThread().isInterrupted() && tryCount < retryCount + 1) {
        try {
            return c.call();
        } catch (ApiException e) {
            exception = e;
            if (e.getCode() >= 400 && e.getCode() < 500) {
                break;
            }
            log.warn("call error: '{}'", getErrorMessage(e));
        } catch (Exception e) {
            exception = e;
            log.error("call error", e);
        }
        log.info("retry after {} sec", retryInterval / 1000);
        sleep(retryInterval);
        tryCount++;
    }
    if (exception instanceof ApiException) {
        throw (ApiException) exception;
    }
    throw new ApiException(exception);
}
Also used : ApiException(com.walmartlabs.concord.ApiException) IOException(java.io.IOException) ApiException(com.walmartlabs.concord.ApiException)

Example 3 with ApiException

use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.

the class RawPayloadProjectIT method testReject.

@Test
public void testReject() throws Exception {
    ProjectsApi projectsApi = new ProjectsApi(getApiClient());
    String orgName = "Default";
    String projectName = "project_" + System.currentTimeMillis();
    projectsApi.createOrUpdate(orgName, new ProjectEntry().setName(projectName));
    // ---
    byte[] payload = archive(ProcessIT.class.getResource("example").toURI());
    try {
        Map<String, Object> input = new HashMap<>();
        input.put("org", orgName);
        input.put("project", projectName);
        input.put("archive", payload);
        StartProcessResponse process = start(input);
        System.out.println("process: " + process);
        fail("should fail");
    } catch (ApiException e) {
    }
}
Also used : ProjectsApi(com.walmartlabs.concord.client.ProjectsApi) ProjectEntry(com.walmartlabs.concord.client.ProjectEntry) HashMap(java.util.HashMap) StartProcessResponse(com.walmartlabs.concord.client.StartProcessResponse) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 4 with ApiException

use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.

the class SecretIT method testBulkAccessUpdate.

@Test
public void testBulkAccessUpdate() throws Exception {
    String orgName = "org_" + randomString();
    OrganizationsApi orgApi = new OrganizationsApi(getApiClient());
    orgApi.createOrUpdate(new OrganizationEntry().setName(orgName));
    // ---
    String projectName = "project_" + randomString();
    ProjectsApi projectsApi = new ProjectsApi(getApiClient());
    projectsApi.createOrUpdate(orgName, new ProjectEntry().setName(projectName));
    // ---
    String secretName = "secret_" + randomString();
    generateKeyPair(orgName, projectName, secretName, false, null);
    SecretsApi secretsApi = new SecretsApi(getApiClient());
    TeamsApi teamsApi = new TeamsApi(getApiClient());
    // ---
    String teamName = "team_" + randomString();
    CreateTeamResponse teamResp = teamsApi.createOrUpdate(orgName, new TeamEntry().setName(teamName));
    // --- Typical one-or-more teams bulk access update
    List<ResourceAccessEntry> teams = new ArrayList<>(1);
    teams.add(new ResourceAccessEntry().setOrgName(orgName).setTeamId(teamResp.getId()).setTeamName(teamName).setLevel(ResourceAccessEntry.LevelEnum.OWNER));
    GenericOperationResult addTeamsResult = secretsApi.updateAccessLevel_0(orgName, secretName, teams);
    assertNotNull(addTeamsResult);
    assertTrue(addTeamsResult.isOk());
    List<ResourceAccessEntry> currentTeams = secretsApi.getAccessLevel(orgName, secretName);
    assertNotNull(currentTeams);
    assertEquals(1, currentTeams.size());
    // --- Empty teams list clears all
    GenericOperationResult clearTeamsResult = secretsApi.updateAccessLevel_0(orgName, secretName, Collections.emptyList());
    assertNotNull(clearTeamsResult);
    assertTrue(clearTeamsResult.isOk());
    try {
        secretsApi.updateAccessLevel_0(orgName, secretName, null);
    } catch (ApiException expected) {
        assertEquals(400, expected.getCode());
        assertTrue(expected.getResponseBody().contains("List of teams is null"));
    } catch (Exception e) {
        fail("Expected ApiException. Got " + e.getClass().toString());
    }
    // ---
    teamsApi.delete(orgName, teamName);
    secretsApi.delete(orgName, secretName);
    projectsApi.delete(orgName, projectName);
    orgApi.delete(orgName, "yes");
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) ApiException(com.walmartlabs.concord.ApiException) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 5 with ApiException

use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.

the class SecretIT method testUpdateNonUniqueName.

@Test
public void testUpdateNonUniqueName() throws Exception {
    String orgName1 = "org_" + randomString();
    String orgName2 = "org_" + randomString();
    OrganizationsApi orgApi = new OrganizationsApi(getApiClient());
    orgApi.createOrUpdate(new OrganizationEntry().setName(orgName1));
    orgApi.createOrUpdate(new OrganizationEntry().setName(orgName2));
    // ---
    String secretName = "secret_" + randomString();
    addUsernamePassword(orgName1, secretName, false, null, "test", "q1");
    addUsernamePassword(orgName2, secretName, false, null, "test", "q1");
    UpdateSecretRequest request = UpdateSecretRequest.builder().newOrgName(orgName2).build();
    SecretClient secretClient = new SecretClient(getApiClient());
    ApiException exception = Assertions.assertThrows(ApiException.class, () -> secretClient.updateSecret(orgName1, secretName, request));
    assertThat(exception.getMessage(), containsString("Secret already exists"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Aggregations

ApiException (com.walmartlabs.concord.ApiException)16 Test (org.junit.jupiter.api.Test)8 HashMap (java.util.HashMap)5 ProjectEntry (com.walmartlabs.concord.client.ProjectEntry)3 ProjectsApi (com.walmartlabs.concord.client.ProjectsApi)3 File (java.io.File)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)2 Path (java.nio.file.Path)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ResponseBody (com.squareup.okhttp.ResponseBody)1 ApiClient (com.walmartlabs.concord.ApiClient)1 CreateUserRequest (com.walmartlabs.concord.client.CreateUserRequest)1 ProcessApi (com.walmartlabs.concord.client.ProcessApi)1 StartProcessResponse (com.walmartlabs.concord.client.StartProcessResponse)1 UsersApi (com.walmartlabs.concord.client.UsersApi)1 StepCommand (com.walmartlabs.concord.runtime.v2.runner.vm.StepCommand)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Git (org.eclipse.jgit.api.Git)1