use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.
the class ValidationIT method testInvalidUsername.
@Test
public void testInvalidUsername() {
String longUsername = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
UsersApi usersApi = new UsersApi(getApiClient());
try {
usersApi.findByUsername("test@localhost");
fail("Should fail with a validation error");
} catch (ApiException e) {
assertInvalidRequest(e);
}
try {
usersApi.findByUsername("local\\test");
fail("Should fail with a validation error");
} catch (ApiException e) {
assertInvalidRequest(e);
}
try {
usersApi.findByUsername(longUsername);
fail("Should fail with a validation error");
} catch (ApiException e) {
assertInvalidRequest(e);
}
try {
usersApi.findByUsername("test#" + System.currentTimeMillis());
fail("Random valid username, should fail with 404");
} catch (ApiException e) {
assertInvalidRequest(e);
}
try {
usersApi.createOrUpdate(new CreateUserRequest().setUsername(longUsername).setType(CreateUserRequest.TypeEnum.LOCAL));
fail("Should fail with a validation error");
} catch (ApiException e) {
assertInvalidRequest(e);
}
}
use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.
the class ValidationIT method testProjectCreation.
@Test
public void testProjectCreation() throws Exception {
ProjectsApi projectsApi = new ProjectsApi(getApiClient());
try {
ProjectEntry req = new ProjectEntry().setName("@123_123");
projectsApi.createOrUpdate("Default", req);
fail("Should fail with a validation error");
} catch (ApiException e) {
assertInvalidRequest(e);
}
ProjectEntry req = new ProjectEntry().setName("aProperName@" + System.currentTimeMillis());
projectsApi.createOrUpdate("Default", req);
}
use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.
the class ExternalImportsIT method testExternalImportState.
@Test
public void testExternalImportState() throws Exception {
String repoUrl = initRepo("externalImportWithDir");
// prepare the payload
Path payloadDir = createPayload("externalImportMainStateTest", repoUrl);
byte[] payload = archive(payloadDir.toUri());
// start the process
ProcessApi processApi = new ProcessApi(getApiClient());
StartProcessResponse spr = start(payload);
assertNotNull(spr.getInstanceId());
waitForStatus(processApi, spr.getInstanceId(), ProcessEntry.StatusEnum.ENQUEUED);
try {
processApi.downloadStateFile(spr.getInstanceId(), "import_data/concord.yml");
fail("exception expected");
} catch (ApiException e) {
assertEquals(404, e.getCode());
}
processApi.kill(spr.getInstanceId());
}
use of com.walmartlabs.concord.ApiException in project concord by walmartlabs.
the class ProcessCountIT method test.
@Test
public void test() throws Exception {
Path tmpDir = createTempDir();
File src = new File(TriggersRefreshIT.class.getResource("processCount").toURI());
IOUtils.copy(src.toPath(), tmpDir);
Git repo = Git.init().setInitialBranch("master").setDirectory(tmpDir.toFile()).call();
repo.add().addFilepattern(".").call();
repo.commit().setMessage("import").call();
String gitUrl = tmpDir.toAbsolutePath().toString();
// ---
String orgName = "org_" + randomString();
OrganizationsApi orgApi = new OrganizationsApi(getApiClient());
orgApi.createOrUpdate(new OrganizationEntry().setName(orgName));
String projectName = "project_" + randomString();
String repoName = "repo_" + randomString();
System.out.println(">>>" + orgName + "/" + projectName);
ProjectsApi projectsApi = new ProjectsApi(getApiClient());
projectsApi.createOrUpdate(orgName, new ProjectEntry().setName(projectName).setRepositories(Collections.singletonMap(repoName, new RepositoryEntry().setBranch("master").setUrl(gitUrl))));
// ---
Map<String, Object> input = new HashMap<>();
input.put("org", orgName);
input.put("project", projectName);
input.put("repo", repoName);
StartProcessResponse spr = start(input);
// ---
ProcessApi processApi = new ProcessApi(getApiClient());
ProcessEntry pe = waitForCompletion(processApi, spr.getInstanceId());
assertEquals(ProcessEntry.StatusEnum.FINISHED, pe.getStatus());
byte[] ab = getLog(pe.getLogFileName());
assertLog(".*Hello!.*", ab);
// ---
ProcessV2Api processV2Api = new ProcessV2Api(getApiClient());
List<ProcessEntry> l = processV2Api.list(null, orgName, null, projectName, null, repoName, null, null, null, null, null, null, null, null, null);
assertEquals(1, l.size());
assertEquals(pe.getInstanceId(), l.get(0).getInstanceId());
// specifying an invalid repository name should return a 404 response
try {
processV2Api.list(null, orgName, null, projectName, null, repoName + randomString(), null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
assertEquals(404, e.getCode());
}
// ---
int i = processV2Api.count(null, orgName, null, projectName, null, repoName, null, null, null, null, null, null);
assertEquals(1, i);
// specifying an invalid repository name should return a 404 response
try {
processV2Api.count(null, orgName, null, projectName, null, repoName + randomString(), null, null, null, null, null, null);
} catch (ApiException e) {
assertEquals(404, e.getCode());
}
}
use of com.walmartlabs.concord.ApiException 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);
}
}
Aggregations