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