Search in sources :

Example 6 with ApiException

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);
    }
}
Also used : UsersApi(com.walmartlabs.concord.client.UsersApi) CreateUserRequest(com.walmartlabs.concord.client.CreateUserRequest) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 7 with ApiException

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);
}
Also used : ProjectsApi(com.walmartlabs.concord.client.ProjectsApi) ProjectEntry(com.walmartlabs.concord.client.ProjectEntry) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 8 with ApiException

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());
}
Also used : Path(java.nio.file.Path) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 9 with ApiException

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());
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) Git(org.eclipse.jgit.api.Git) File(java.io.File) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 10 with ApiException

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);
    }
}
Also used : ProcessApi(com.walmartlabs.concord.client.ProcessApi) ApiException(com.walmartlabs.concord.ApiException)

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