use of io.kestra.core.exceptions.InternalException in project kestra by kestra-io.
the class MultipleCondition method test.
/**
* This conditions will only validate previously calculated value on
* {@link FlowService#multipleFlowTrigger(Stream, Flow, Execution, MultipleConditionStorageInterface)}} and save on {@link MultipleConditionStorageInterface}
* by the executor.
* The real validation is done here.
*/
@Override
public boolean test(ConditionContext conditionContext) throws InternalException {
Logger logger = conditionContext.getRunContext().logger();
MultipleConditionStorageInterface multipleConditionStorage = conditionContext.getMultipleConditionStorage();
Objects.requireNonNull(multipleConditionStorage);
Optional<MultipleConditionWindow> triggerExecutionWindow = multipleConditionStorage.get(conditionContext.getFlow(), this.getId());
Map<String, Boolean> results = conditions.keySet().stream().map(condition -> new AbstractMap.SimpleEntry<>(condition, (triggerExecutionWindow.isPresent() && triggerExecutionWindow.get().getResults() != null && triggerExecutionWindow.get().getResults().containsKey(condition) && triggerExecutionWindow.get().getResults().get(condition)))).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
long validatedCount = results.entrySet().stream().filter(Map.Entry::getValue).count();
boolean result = conditions.size() == validatedCount;
if (result && logger.isDebugEnabled()) {
logger.debug("[namespace: {}] [flow: {}] Multiple conditions validated !", conditionContext.getFlow().getNamespace(), conditionContext.getFlow().getId());
} else if (logger.isTraceEnabled()) {
logger.trace("[namespace: {}] [flow: {}] Multiple conditions failed ({}/{}) with '{}'", conditionContext.getFlow().getNamespace(), conditionContext.getFlow().getId(), validatedCount, conditions.size(), results);
}
return result;
}
use of io.kestra.core.exceptions.InternalException in project kestra by kestra-io.
the class ExecutorService method handleChildNext.
private Executor handleChildNext(Executor executor) throws InternalException {
if (executor.getExecution().getTaskRunList() == null) {
return executor;
}
List<TaskRun> running = executor.getExecution().getTaskRunList().stream().filter(taskRun -> taskRun.getState().isRunning()).collect(Collectors.toList());
// Remove functionnal style to avoid (class io.kestra.core.exceptions.IllegalVariableEvaluationException cannot be cast to class java.lang.RuntimeException'
ArrayList<TaskRun> result = new ArrayList<>();
for (TaskRun taskRun : running) {
result.addAll(this.childNextsTaskRun(executor, taskRun));
}
if (result.size() == 0) {
return executor;
}
return executor.withTaskRun(result, "handleChildNext");
}
use of io.kestra.core.exceptions.InternalException in project kestra by kestra-io.
the class FlowController method updateTask.
/**
* @param namespace flow namespace
* @param id flow id to update
* @param taskId taskId id to update
* @return flow updated
*/
@Patch(uri = "{namespace}/{id}/{taskId}", produces = MediaType.TEXT_JSON)
@ExecuteOn(TaskExecutors.IO)
public HttpResponse<Flow> updateTask(String namespace, String id, String taskId, @Valid @Body Task task) throws ConstraintViolationException {
Optional<Flow> existingFlow = flowRepository.findById(namespace, id);
if (existingFlow.isEmpty()) {
return HttpResponse.status(HttpStatus.NOT_FOUND);
}
if (!taskId.equals(task.getId())) {
throw new IllegalArgumentException("Invalid taskId, previous '" + taskId + "' & current '" + task.getId() + "'");
}
Flow flow = existingFlow.get();
try {
Flow newValue = flow.updateTask(taskId, task);
return HttpResponse.ok(flowRepository.update(newValue, flow));
} catch (InternalException e) {
return HttpResponse.status(HttpStatus.NOT_FOUND);
}
}
use of io.kestra.core.exceptions.InternalException in project kestra by kestra-io.
the class FlowJoinerTransformer method transform.
@Override
public Executor transform(String key, Executor executor) {
Flow flow;
try {
// pooling of new flow can be delayed on ExecutorStore, we maybe need to wait that the flow is updated
flow = Await.until(() -> flowExecutorInterface.findByExecution(executor.getExecution()).orElse(null), Duration.ofMillis(100), Duration.ofMinutes(5));
} catch (TimeoutException e) {
return executor.withException(new Exception("Unable to find flow with namespace: '" + executor.getExecution().getNamespace() + "'" + ", id: '" + executor.getExecution().getFlowId() + "', " + "revision '" + executor.getExecution().getFlowRevision() + "'"), "joinFlow");
}
if (!withDefaults) {
return executor.withFlow(flow);
}
try {
flow = Template.injectTemplate(flow, executor.getExecution(), (namespace, id) -> this.templateExecutorInterface.findById(namespace, id).orElse(null));
} catch (InternalException e) {
log.warn("Failed to inject template", e);
}
Flow flowWithDefaults = taskDefaultService.injectDefaults(flow, executor.getExecution());
return executor.withFlow(flowWithDefaults);
}
Aggregations