Search in sources :

Example 1 with ProcessEventsApi

use of com.walmartlabs.concord.client.ProcessEventsApi in project concord by walmartlabs.

the class FlowEventsIT method test.

@Test
public void test() throws Exception {
    Payload payload = new Payload().archive(resource("flowEvents"));
    ConcordProcess proc = concord.processes().start(payload);
    expectStatus(proc, ProcessEntry.StatusEnum.FINISHED);
    // ---
    ProcessEventsApi processEventsApi = new ProcessEventsApi(concord.apiClient());
    List<ProcessEventEntry> events = processEventsApi.list(proc.instanceId(), "ELEMENT", null, null, null, null, null, null);
    assertNotNull(events);
    // ---
    // expression:
    // - ${log.info('BOO')}
    assertEvent(events, 0, new EventData().pre().correlationId().location(9, 7, "concord.yml").flow("default").name("log").description("Task: log"));
    assertEvent(events, 1, new EventData().post().duration().correlationId().location(9, 7, "concord.yml").flow("default").name("log").description("Task: log"));
    // task full form:
    // - task: log
    // in:
    // msg: "test"
    // pre
    assertEvent(events, 2, new EventData().pre().correlationId().location(12, 7, "concord.yml").flow("default").name("log").description("Task: log"));
    // post
    assertEvent(events, 3, new EventData().post().duration().correlationId().location(12, 7, "concord.yml").flow("default").name("log").description("Task: log"));
    // script:
    // - script: js
    assertEvent(events, 4, new EventData().correlationId().location(17, 7, "concord.yml").flow("default").description("Script: js"));
    // if
    // - if: ${1 == 1}
    assertEvent(events, 5, new EventData().correlationId().location(22, 7, "concord.yml").flow("default").description("Check: ${1 == 1}"));
    // - log: "It's true!"
    // pre
    assertEvent(events, 6, new EventData().pre().correlationId().location(24, 11, "concord.yml").flow("default").name("log").description("Task: log"));
    // post
    assertEvent(events, 7, new EventData().post().correlationId().duration().location(24, 11, "concord.yml").flow("default").name("log").description("Task: log"));
    // - switch: ${myVar}
    assertEvent(events, 8, new EventData().correlationId().location(26, 7, "concord.yml").flow("default").description("Switch: ${myVar}"));
    // - log: "It's red!"
    // pre
    assertEvent(events, 9, new EventData().pre().correlationId().location(28, 11, "concord.yml").flow("default").name("log").description("Task: log"));
    // post
    assertEvent(events, 10, new EventData().post().correlationId().duration().location(28, 11, "concord.yml").flow("default").name("log").description("Task: log"));
    // set variables
    assertEvent(events, 11, new EventData().correlationId().location(30, 7, "concord.yml").flow("default").description("Set variables"));
    // flow call
    assertEvent(events, 12, new EventData().correlationId().location(33, 7, "concord.yml").flow("default").description("Flow call: returnFlow"));
    // return
    assertEvent(events, 13, new EventData().correlationId().location(38, 7, "concord.yml").flow("returnFlow").description("Return"));
    // flow call
    assertEvent(events, 14, new EventData().correlationId().location(35, 7, "concord.yml").flow("default").description("Flow call: exitFlow"));
    // exit
    assertEvent(events, 15, new EventData().correlationId().location(41, 7, "concord.yml").flow("exitFlow").description("Exit"));
}
Also used : ConcordProcess(ca.ibodrov.concord.testcontainers.ConcordProcess) Payload(ca.ibodrov.concord.testcontainers.Payload) ProcessEventsApi(com.walmartlabs.concord.client.ProcessEventsApi) ProcessEventEntry(com.walmartlabs.concord.client.ProcessEventEntry) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessEventsApi

use of com.walmartlabs.concord.client.ProcessEventsApi in project concord by walmartlabs.

the class AnsibleTask method run.

public TaskResult.SimpleResult run(AnsibleContext context, PlaybookProcessRunner playbookProcessRunner) throws Exception {
    String playbook = assertString(context.args(), TaskParams.PLAYBOOK_KEY.getKey());
    log.info("Using a playbook: {}", playbook);
    AnsibleEnv env = new AnsibleEnv(context).parse(context.args());
    AnsibleConfig cfg = new AnsibleConfig(context).parse(context.args()).enrich(env);
    AnsibleCallbacks callbacks = AnsibleCallbacks.process(context, cfg).startEventSender(context.instanceId(), new ProcessEventsApi(apiClient)).enrich(env);
    AnsibleLibs.process(context, env);
    AnsibleLookup.process(context, cfg);
    PlaybookScriptBuilder b = new PlaybookScriptBuilder(context, playbook);
    AnsibleInventory.process(context, b);
    AnsibleVaultId.process(context, b);
    AnsibleRoles.process(context, cfg);
    GroupVarsProcessor groupVarsProcessor = new GroupVarsProcessor(secretService);
    groupVarsProcessor.process(context, playbook);
    OutVarsProcessor outVarsProcessor = new OutVarsProcessor();
    outVarsProcessor.prepare(context, env.get());
    AnsibleAuth auth = ansibleAuthFactory.create(context).enrich(env, context).enrich(b);
    cfg.write();
    env.write();
    boolean checkMode = getBoolean(context.args(), TaskParams.CHECK_KEY.getKey(), false);
    if (checkMode) {
        log.warn("Running in the check mode. No changes will be made.");
    }
    boolean syntaxCheck = getBoolean(context.args(), TaskParams.SYNTAX_CHECK_KEY.getKey(), false);
    if (syntaxCheck) {
        log.warn("Running in the syntax check mode. No changes will be made.");
    }
    Virtualenv virtualenv = Virtualenv.create(context);
    try {
        Path workDir = context.workDir();
        Path attachmentsPath = workDir.relativize(workDir.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME));
        b = b.withAttachmentsDir(attachmentsPath.toString()).withDebug(context.debug()).withTags(getListAsString(context.args(), TaskParams.TAGS_KEY)).withSkipTags(getListAsString(context.args(), TaskParams.SKIP_TAGS_KEY)).withExtraVars(getMap(context.args(), TaskParams.EXTRA_VARS_KEY.getKey(), null)).withExtraVarsFiles(getList(context.args(), TaskParams.EXTRA_VARS_FILES_KEY.getKey(), null)).withLimit(getLimit(context.args(), playbook)).withVerboseLevel(getVerboseLevel(context.args())).withCheck(checkMode).withSyntaxCheck(syntaxCheck).withEnv(env.get()).withVirtualenv(virtualenv);
        auth.prepare();
        int code = playbookProcessRunner.withDebug(context.debug()).run(b.buildArgs(), b.buildEnv());
        log.debug("execution -> done, code {}", code);
        updateAnsibleStats(workDir, code);
        updateAnsibleStatsV2(workDir, code);
        Map<String, Object> result = outVarsProcessor.process();
        boolean success = code == SUCCESS_EXIT_CODE;
        if (!success) {
            saveRetryFile(context.args(), workDir);
            log.warn("Playbook is finished with code {}", code);
        }
        return TaskResult.of(success).values(result).value("exitCode", code);
    } finally {
        callbacks.stopEventSender();
        auth.postProcess();
        groupVarsProcessor.postProcess();
        outVarsProcessor.postProcess();
        virtualenv.destroy();
    }
}
Also used : Path(java.nio.file.Path) ArgUtils.getListAsString(com.walmartlabs.concord.plugins.ansible.ArgUtils.getListAsString) ProcessEventsApi(com.walmartlabs.concord.client.ProcessEventsApi)

Example 3 with ProcessEventsApi

use of com.walmartlabs.concord.client.ProcessEventsApi in project concord by walmartlabs.

the class DefaultElementEventProcessor method process.

@Override
public void process(ElementEvent event, EventParamsBuilder builder, Predicate<AbstractElement> filter) throws ExecutionException {
    ProcessDefinition pd = processDefinitionProvider.getById(event.getProcessDefinitionId());
    if (pd == null) {
        throw new RuntimeException("Process definition not found: " + event.getProcessDefinitionId());
    }
    if (!(pd instanceof SourceAwareProcessDefinition)) {
        return;
    }
    Map<String, SourceMap> sourceMaps = ((SourceAwareProcessDefinition) pd).getSourceMaps();
    SourceMap source = sourceMaps.get(event.getElementId());
    if (source == null) {
        return;
    }
    AbstractElement element = ProcessDefinitionUtils.findElement(pd, event.getElementId());
    if (filter != null && !filter.test(element)) {
        return;
    }
    try {
        Map<String, Object> e = new HashMap<>();
        e.put("processDefinitionId", event.getProcessDefinitionId());
        e.put("elementId", event.getElementId());
        e.put("line", source.getLine());
        e.put("column", source.getColumn());
        e.put("description", source.getDescription());
        e.putAll(builder.build(element));
        ProcessEventRequest req = new ProcessEventRequest();
        // TODO should it be in the constants?
        req.setEventType("ELEMENT");
        req.setData(e);
        req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
        ProcessEventsApi client = new ProcessEventsApi(apiClientFactory.create(ApiClientConfiguration.builder().sessionToken(event.getSessionToken()).txId(UUID.fromString(event.getInstanceId())).build()));
        client.event(UUID.fromString(event.getInstanceId()), req);
    } catch (Exception e) {
        log.warn("process ['{}'] -> transfer error: {}", event.getInstanceId(), e.getMessage());
    }
}
Also used : AbstractElement(io.takari.bpm.model.AbstractElement) HashMap(java.util.HashMap) SourceAwareProcessDefinition(io.takari.bpm.model.SourceAwareProcessDefinition) ProcessDefinition(io.takari.bpm.model.ProcessDefinition) ExecutionException(io.takari.bpm.api.ExecutionException) ProcessEventRequest(com.walmartlabs.concord.client.ProcessEventRequest) SourceMap(io.takari.bpm.model.SourceMap) SourceAwareProcessDefinition(io.takari.bpm.model.SourceAwareProcessDefinition) ProcessEventsApi(com.walmartlabs.concord.client.ProcessEventsApi)

Aggregations

ProcessEventsApi (com.walmartlabs.concord.client.ProcessEventsApi)3 ConcordProcess (ca.ibodrov.concord.testcontainers.ConcordProcess)1 Payload (ca.ibodrov.concord.testcontainers.Payload)1 ProcessEventEntry (com.walmartlabs.concord.client.ProcessEventEntry)1 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)1 ArgUtils.getListAsString (com.walmartlabs.concord.plugins.ansible.ArgUtils.getListAsString)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 AbstractElement (io.takari.bpm.model.AbstractElement)1 ProcessDefinition (io.takari.bpm.model.ProcessDefinition)1 SourceAwareProcessDefinition (io.takari.bpm.model.SourceAwareProcessDefinition)1 SourceMap (io.takari.bpm.model.SourceMap)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1