Search in sources :

Example 11 with ApiException

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

the class OutVariablesProjectIT 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);
        input.put("out", "x,y,z");
        start(input);
        fail("should fail");
    } catch (ApiException e) {
    }
}
Also used : ProjectsApi(com.walmartlabs.concord.client.ProjectsApi) ProjectEntry(com.walmartlabs.concord.client.ProjectEntry) HashMap(java.util.HashMap) ApiException(com.walmartlabs.concord.ApiException) Test(org.junit.jupiter.api.Test)

Example 12 with ApiException

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

the class EventRecordingExecutionListener method afterCommand.

@Override
public Result afterCommand(Runtime runtime, VM vm, State state, ThreadId threadId, Command cmd) {
    if (!eventConfiguration.recordEvents()) {
        return Result.CONTINUE;
    }
    if (!(cmd instanceof StepCommand)) {
        return Result.CONTINUE;
    }
    StepCommand<?> s = (StepCommand<?>) cmd;
    if (s.getStep() instanceof TaskCall || s.getStep() instanceof Expression) {
        return Result.CONTINUE;
    }
    ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
    Location loc = s.getStep().getLocation();
    Map<String, Object> m = new HashMap<>();
    m.put("processDefinitionId", ProcessDefinitionUtils.getCurrentFlowName(pd, s.getStep()));
    m.put("fileName", loc.fileName());
    m.put("line", loc.lineNum());
    m.put("column", loc.column());
    m.put("description", getDescription(s.getStep()));
    m.put("correlationId", s.getCorrelationId());
    ProcessEventRequest req = new ProcessEventRequest();
    // TODO constants
    req.setEventType("ELEMENT");
    req.setData(m);
    req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
    try {
        eventsApi.event(processInstanceId.getValue(), req);
    } catch (ApiException e) {
        log.warn("afterCommand [{}] -> error while sending an event to the server: {}", cmd, e.getMessage());
    }
    return Result.CONTINUE;
}
Also used : StepCommand(com.walmartlabs.concord.runtime.v2.runner.vm.StepCommand) ProcessEventRequest(com.walmartlabs.concord.client.ProcessEventRequest) HashMap(java.util.HashMap) ApiException(com.walmartlabs.concord.ApiException)

Example 13 with ApiException

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

the class TaskCallEventRecordingListener method send.

private void send(Map<String, Object> event) {
    ProcessEventRequest req = new ProcessEventRequest();
    // TODO should it be in the constants?
    req.setEventType("ELEMENT");
    req.setData(event);
    req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
    try {
        eventsApi.event(processInstanceId.getValue(), req);
    } catch (ApiException e) {
        log.warn("send [{}] -> error while sending an event to the server: {}", event, e.getMessage());
    }
}
Also used : ProcessEventRequest(com.walmartlabs.concord.client.ProcessEventRequest) ApiException(com.walmartlabs.concord.ApiException)

Example 14 with ApiException

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

the class SecretServiceImpl method encryptString.

@Override
public String encryptString(Context ctx, String instanceId, String orgName, String projectName, String value) throws Exception {
    ApiClientConfiguration cfg = ApiClientConfiguration.builder().sessionToken(ContextUtils.getSessionToken(ctx)).txId(UUID.fromString(instanceId)).build();
    ApiClient c = clientFactory.create(cfg);
    String path = "/api/v1/org/" + orgName + "/project/" + projectName + "/encrypt";
    Map<String, String> headerParams = new HashMap<>();
    headerParams.put("Content-Type", "text/plain;charset=UTF-8");
    ApiResponse<EncryptValueResponse> r = ClientUtils.postData(c, path, value, headerParams, EncryptValueResponse.class);
    if (r.getStatusCode() == 200 && r.getData().isOk()) {
        return r.getData().getData();
    }
    throw new ApiException("Error encrypting string. Status code:" + r.getStatusCode() + " Data: " + r.getData());
}
Also used : HashMap(java.util.HashMap) ApiClient(com.walmartlabs.concord.ApiClient) ApiException(com.walmartlabs.concord.ApiException)

Example 15 with ApiException

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

the class ConcordTaskCommon method getOutVars.

@SuppressWarnings("unchecked")
private Map<String, Object> getOutVars(String baseUrl, String apiKey, UUID processId) throws Exception {
    return withClient(baseUrl, apiKey, 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 Collections.emptyMap();
            }
            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)

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