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);
}
});
}
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);
}
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) {
}
}
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");
}
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"));
}
Aggregations