Search in sources :

Example 1 with KafkaFlowExecutor

use of io.kestra.runner.kafka.KafkaFlowExecutor in project kestra by kestra-io.

the class ExecutorFlowTrigger method topology.

public StreamsBuilder topology() {
    StreamsBuilder builder = new KafkaStreamsBuilder();
    // trigger
    builder.addStateStore(Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore(TRIGGER_MULTIPLE_STATE_STORE_NAME), Serdes.String(), JsonSerde.of(MultipleConditionWindow.class)));
    KStream<String, io.kestra.runner.kafka.streams.ExecutorFlowTrigger> stream = builder.stream(kafkaAdminService.getTopicName(io.kestra.runner.kafka.streams.ExecutorFlowTrigger.class), Consumed.with(Serdes.String(), JsonSerde.of(io.kestra.runner.kafka.streams.ExecutorFlowTrigger.class)).withName("KStream.ExecutorFlowTrigger")).filter((key, value) -> value != null, Named.as("ExecutorFlowTrigger.filterNotNull"));
    stream.transformValues(() -> new FlowTriggerWithExecutionTransformer(TRIGGER_MULTIPLE_STATE_STORE_NAME, kafkaFlowExecutor, flowService), Named.as("ExecutorFlowTrigger.transformToExecutionList"), TRIGGER_MULTIPLE_STATE_STORE_NAME).flatMap((key, value) -> value.stream().map(execution -> new KeyValue<>(execution.getId(), execution)).collect(Collectors.toList()), Named.as("ExecutorFlowTrigger.flapMapToExecution")).to(kafkaAdminService.getTopicName(Execution.class), Produced.with(Serdes.String(), JsonSerde.of(Execution.class)).withName("ExecutorFlowTrigger.toExecution"));
    stream.mapValues((readOnlyKey, value) -> (io.kestra.runner.kafka.streams.ExecutorFlowTrigger) null, Named.as("ExecutorFlowTrigger.executorFlowTriggerToNull")).to(kafkaAdminService.getTopicName(io.kestra.runner.kafka.streams.ExecutorFlowTrigger.class), Produced.with(Serdes.String(), JsonSerde.of(io.kestra.runner.kafka.streams.ExecutorFlowTrigger.class)).withName("ExecutorFlowTrigger.toExecutorFlowTrigger"));
    return builder;
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KafkaAdminService(io.kestra.runner.kafka.services.KafkaAdminService) Produced(org.apache.kafka.streams.kstream.Produced) Consumed(org.apache.kafka.streams.kstream.Consumed) KeyValue(org.apache.kafka.streams.KeyValue) Stores(org.apache.kafka.streams.state.Stores) Singleton(jakarta.inject.Singleton) KStream(org.apache.kafka.streams.kstream.KStream) Execution(io.kestra.core.models.executions.Execution) KafkaFlowExecutor(io.kestra.runner.kafka.KafkaFlowExecutor) JsonSerde(io.kestra.runner.kafka.serializers.JsonSerde) Collectors(java.util.stream.Collectors) MultipleConditionWindow(io.kestra.core.models.triggers.multipleflows.MultipleConditionWindow) FlowService(io.kestra.core.services.FlowService) FlowTriggerWithExecutionTransformer(io.kestra.runner.kafka.streams.FlowTriggerWithExecutionTransformer) Named(org.apache.kafka.streams.kstream.Named) Serdes(org.apache.kafka.common.serialization.Serdes) Inject(jakarta.inject.Inject) KafkaStreamsBuilder(io.kestra.runner.kafka.services.KafkaStreamsBuilder) KafkaQueueEnabled(io.kestra.runner.kafka.KafkaQueueEnabled) KeyValue(org.apache.kafka.streams.KeyValue) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KafkaStreamsBuilder(io.kestra.runner.kafka.services.KafkaStreamsBuilder) Execution(io.kestra.core.models.executions.Execution) FlowTriggerWithExecutionTransformer(io.kestra.runner.kafka.streams.FlowTriggerWithExecutionTransformer) KafkaStreamsBuilder(io.kestra.runner.kafka.services.KafkaStreamsBuilder)

Aggregations

Execution (io.kestra.core.models.executions.Execution)1 MultipleConditionWindow (io.kestra.core.models.triggers.multipleflows.MultipleConditionWindow)1 FlowService (io.kestra.core.services.FlowService)1 KafkaFlowExecutor (io.kestra.runner.kafka.KafkaFlowExecutor)1 KafkaQueueEnabled (io.kestra.runner.kafka.KafkaQueueEnabled)1 JsonSerde (io.kestra.runner.kafka.serializers.JsonSerde)1 KafkaAdminService (io.kestra.runner.kafka.services.KafkaAdminService)1 KafkaStreamsBuilder (io.kestra.runner.kafka.services.KafkaStreamsBuilder)1 FlowTriggerWithExecutionTransformer (io.kestra.runner.kafka.streams.FlowTriggerWithExecutionTransformer)1 Inject (jakarta.inject.Inject)1 Singleton (jakarta.inject.Singleton)1 Collectors (java.util.stream.Collectors)1 Serdes (org.apache.kafka.common.serialization.Serdes)1 KeyValue (org.apache.kafka.streams.KeyValue)1 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)1 Consumed (org.apache.kafka.streams.kstream.Consumed)1 KStream (org.apache.kafka.streams.kstream.KStream)1 Named (org.apache.kafka.streams.kstream.Named)1 Produced (org.apache.kafka.streams.kstream.Produced)1 Stores (org.apache.kafka.streams.state.Stores)1