use of io.kestra.core.models.triggers.multipleflows.MultipleConditionStorageInterface 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.models.triggers.multipleflows.MultipleConditionStorageInterface in project kestra by kestra-io.
the class FlowTriggerWithExecutionTransformer method transform.
@Override
public List<Execution> transform(final ExecutorFlowTrigger value) {
MultipleConditionStorageInterface multipleConditionStorage = new KafkaMultipleConditionStorage(this.multipleStore);
// multiple conditions storage
kafkaFlowExecutor.findByExecution(value.getExecution()).ifPresent(flow -> {
flowService.multipleFlowTrigger(Stream.of(value.getFlowHavingTrigger()), flow, value.getExecution(), multipleConditionStorage).forEach(triggerExecutionWindow -> {
this.multipleStore.put(triggerExecutionWindow.uid(), triggerExecutionWindow);
});
});
List<Execution> triggeredExecutions = flowService.flowTriggerExecution(Stream.of(value.getFlowHavingTrigger()), value.getExecution(), multipleConditionStorage);
// Trigger is done, remove matching multiple condition
flowService.multipleFlowToDelete(Stream.of(value.getFlowHavingTrigger()), multipleConditionStorage).forEach(r -> this.multipleStore.delete(r.uid()));
return triggeredExecutions;
}
Aggregations