use of com.walmartlabs.concord.client.ProcessEventRequest 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());
}
}
use of com.walmartlabs.concord.client.ProcessEventRequest 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;
}
use of com.walmartlabs.concord.client.ProcessEventRequest 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());
}
}
use of com.walmartlabs.concord.client.ProcessEventRequest in project concord by walmartlabs.
the class EventSender method doRun.
public void doRun() {
if (debug) {
log.info("run -> started...");
}
try (RandomAccessFile f = new RandomAccessFile(eventsFile.toFile(), "r")) {
Batch batch = new Batch(instanceId, eventsApi);
long t1 = System.currentTimeMillis();
while (true) {
String line = f.readLine();
if (line == null || line.isEmpty()) {
if (stop) {
// don't stop until we reach the end of the file
if (Files.size(eventsFile) <= f.getFilePointer()) {
break;
}
}
// wait for more data
sleep(NO_DATA_DELAY);
} else {
if (line.endsWith(EOL_MARKER)) {
String data = line.substring(0, line.length() - EOL_MARKER.length());
ProcessEventRequest req = objectMapper.readValue(data, ProcessEventRequest.class);
batch.add(req);
} else {
// partial line, re-read next time
f.seek(f.getFilePointer() - line.length());
}
}
long t2 = System.currentTimeMillis();
if (batch.size() >= MAX_BATCH_SIZE || t2 - t1 >= MAX_BATCH_AGE) {
flush(batch);
t1 = t2;
}
}
flush(batch);
} catch (IOException e) {
log.error("Error while reading the event file: {}", e.getMessage(), e);
}
if (debug) {
log.info("run -> stopped...");
}
}
Aggregations