Skip to content

Commit

Permalink
refactor: migrate package plugin.core.debug to dynamic properties
Browse files Browse the repository at this point in the history
migrate Return task
migrate Echo task
migrate associated test using these tasks
  • Loading branch information
mgabelle committed Jan 13, 2025
1 parent 501a5d3 commit 6aef532
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 52 deletions.
18 changes: 7 additions & 11 deletions core/src/main/java/io/kestra/plugin/core/debug/Echo.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.kestra.plugin.core.debug;

import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.plugin.core.log.Log;
import io.micronaut.core.annotation.NonNull;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand All @@ -14,8 +13,9 @@
import io.kestra.core.runners.RunContext;
import org.slf4j.event.Level;

import jakarta.validation.constraints.NotBlank;

/**
* @deprecated
*/
@SuperBuilder
@ToString
@EqualsAndHashCode
Expand Down Expand Up @@ -46,19 +46,15 @@
)
@Deprecated
public class Echo extends Task implements RunnableTask<VoidOutput> {
@NonNull
@NotBlank
@PluginProperty(dynamic = true)
private String format;
private Property<String> format;

@Builder.Default
@PluginProperty
private Level level = Level.INFO;
private Property<Level> level = Property.of(Level.INFO);

@Override
public VoidOutput run(RunContext runContext) throws Exception {
Log log = Log.builder()
.level(this.level)
.level(runContext.render(this.level).as(Level.class).orElseThrow())
.message(this.format)
.build();
log.run(runContext);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/kestra/plugin/core/debug/Return.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.plugin.core.debug;

import io.kestra.core.models.annotations.Metric;
import io.kestra.core.models.property.Property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -51,16 +52,15 @@ public class Return extends Task implements RunnableTask<Return.Output> {
@Schema(
title = "The templated string to render."
)
@PluginProperty(dynamic = true)
private String format;
private Property<String> format;

@Override
public Return.Output run(RunContext runContext) throws Exception {
long start = System.nanoTime();

Logger logger = runContext.logger();

String render = runContext.render(format);
String render = runContext.render(format).as(String.class).orElse(null);
logger.debug(render);

long end = System.nanoTime();
Expand Down
5 changes: 3 additions & 2 deletions core/src/test/java/io/kestra/core/models/flows/FlowTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.core.models.flows;

import io.kestra.core.exceptions.InternalException;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.models.validations.ModelValidator;
import io.kestra.core.serializers.YamlParser;
Expand Down Expand Up @@ -114,13 +115,13 @@ void updateTask() throws InternalException {
Flow updated = flow.updateTask("1-2-2_return", Return.builder()
.id("1-2-2_return")
.type(Return.class.getName())
.format("{{task.id}}")
.format(new Property<>("{{task.id}}"))
.build()
);

Task findUpdated = updated.findTaskByTaskId("1-2-2_return");

assertThat(((Return) findUpdated).getFormat(), is("{{task.id}}"));
assertThat(((Return) findUpdated).getFormat().toString(), is("{{task.id}}"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import io.kestra.core.models.Label;
import io.kestra.core.models.property.Property;
import io.kestra.plugin.core.condition.Expression;
import io.kestra.core.models.flows.input.StringInput;
import io.kestra.core.models.listeners.Listener;
Expand All @@ -28,10 +29,10 @@ void source() throws JsonProcessingException {
Return.builder()
.id(IdUtils.create())
.type(Return.class.getName())
.format("123456789 \n123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n" +
.format(Property.of("123456789 \n123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n" +
"123456789 \n" +
"123456789 \n" +
"123456789 \n")
"123456789 \n"))
.build()
))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.kestra.core.models.executions.statistics.Flow;
import io.kestra.core.models.flows.FlowScope;
import io.kestra.core.models.flows.State;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.ResolvedTask;
import io.kestra.core.utils.IdUtils;
import io.kestra.core.utils.NamespaceUtils;
Expand Down Expand Up @@ -63,17 +64,17 @@ public static Execution.ExecutionBuilder builder(State.Type state, String flowId

List<TaskRun> taskRuns = Arrays.asList(
TaskRun.of(execution.build(), ResolvedTask.of(
Return.builder().id("first").type(Return.class.getName()).format("test").build())
Return.builder().id("first").type(Return.class.getName()).format(Property.of("test")).build())
)
.withState(State.Type.SUCCESS),
spyTaskRun(TaskRun.of(execution.build(), ResolvedTask.of(
Return.builder().id("second").type(Return.class.getName()).format("test").build())
Return.builder().id("second").type(Return.class.getName()).format(Property.of("test")).build())
)
.withState(state),
state
),
TaskRun.of(execution.build(), ResolvedTask.of(
Return.builder().id("third").type(Return.class.getName()).format("test").build())).withState(state)
Return.builder().id("third").type(Return.class.getName()).format(Property.of("test")).build())).withState(state)
);

if (flowId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.flows.*;
import io.kestra.core.models.flows.input.StringInput;
import io.kestra.core.models.property.Property;
import io.kestra.core.queues.QueueException;
import io.kestra.core.schedulers.AbstractSchedulerTest;
import io.kestra.core.serializers.JacksonMapper;
Expand Down Expand Up @@ -74,7 +75,7 @@ protected void init() throws IOException, URISyntaxException {
return Flow.builder()
.id(flowId)
.namespace("io.kestra.unittest")
.tasks(Collections.singletonList(Return.builder().id(taskId).type(Return.class.getName()).format("test").build()));
.tasks(Collections.singletonList(Return.builder().id(taskId).type(Return.class.getName()).format(Property.of("test")).build()));
}

@Test
Expand Down Expand Up @@ -141,7 +142,7 @@ protected void revision() throws JsonProcessingException {
Flow first = Flow.builder()
.id(flowId)
.namespace("io.kestra.unittest")
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.inputs(ImmutableList.of(StringInput.builder().type(Type.STRING).id("a").build()))
.build();
// create with repository
Expand Down Expand Up @@ -384,7 +385,7 @@ void updateConflict() {
.id(flowId)
.namespace("io.kestra.unittest")
.inputs(ImmutableList.of(StringInput.builder().type(Type.STRING).id("a").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.build();

Flow save = flowRepository.create(flow, flow.generateSource(), pluginDefaultService.injectDefaults(flow.withSource(flow.generateSource())));
Expand All @@ -396,7 +397,7 @@ void updateConflict() {
.id(IdUtils.create())
.namespace("io.kestra.unittest2")
.inputs(ImmutableList.of(StringInput.builder().type(Type.STRING).id("b").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.build();
;

Expand All @@ -422,7 +423,7 @@ void removeTrigger() throws TimeoutException, QueueException {
.id("sleep")
.type(AbstractSchedulerTest.UnitTest.class.getName())
.build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.build();

flow = flowRepository.create(flow, flow.generateSource(), pluginDefaultService.injectDefaults(flow.withSource(flow.generateSource())));
Expand All @@ -432,7 +433,7 @@ void removeTrigger() throws TimeoutException, QueueException {
Flow update = Flow.builder()
.id(flowId)
.namespace("io.kestra.unittest")
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.build();
;

Expand Down Expand Up @@ -460,7 +461,7 @@ void removeTriggerDelete() throws TimeoutException, QueueException {
.id("sleep")
.type(AbstractSchedulerTest.UnitTest.class.getName())
.build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.build();

Flow save = flowRepository.create(flow, flow.generateSource(), pluginDefaultService.injectDefaults(flow.withSource(flow.generateSource())));
Expand Down Expand Up @@ -533,7 +534,7 @@ protected void lastRevision() {
.tenantId(tenantId)
.id(flowId)
.namespace(namespace)
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()))
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()))
.inputs(ImmutableList.of(StringInput.builder().type(Type.STRING).id("a").build()))
.build();
// create with repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.events.CrudEvent;
import io.kestra.core.events.CrudEventType;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.templates.Template;
import io.kestra.plugin.core.debug.Return;
import io.kestra.core.utils.IdUtils;
Expand Down Expand Up @@ -41,7 +42,7 @@ protected void init() throws IOException, URISyntaxException {
return Template.builder()
.id(IdUtils.create())
.namespace(namespace == null ? "kestra.test" : namespace)
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format("test").build()));
.tasks(Collections.singletonList(Return.builder().id("test").type(Return.class.getName()).format(Property.of("test")).build()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.kestra.core.models.flows.Flow;
import io.kestra.core.models.flows.FlowWithSource;
import io.kestra.core.models.flows.State;
import io.kestra.core.models.property.Property;
import io.kestra.core.repositories.ExecutionRepositoryInterface;
import io.kestra.core.repositories.FlowRepositoryInterface;
import io.kestra.core.repositories.LogRepositoryInterface;
Expand Down Expand Up @@ -83,7 +84,7 @@ void restartSimpleRevision() throws Exception {
Return.builder()
.id("a")
.type(Return.class.getName())
.format("replace")
.format(Property.of("replace"))
.build()
),
JacksonMapper.ofYaml().writeValueAsString(flow),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.core.runners;

import io.kestra.core.models.flows.FlowWithSource;
import io.kestra.core.models.property.Property;
import io.kestra.core.services.PluginDefaultService;
import io.kestra.core.junit.annotations.KestraTest;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -35,7 +36,7 @@ protected static FlowWithSource create(String flowId, String taskId) {
.tasks(Collections.singletonList(Return.builder()
.id(taskId)
.type(Return.class.getName())
.format("test")
.format(Property.of("test"))
.build()))
.build();
return flow.withSource(flow.generateSource());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.kestra.core.models.executions.Execution;
import io.kestra.core.models.flows.Flow;
import io.kestra.core.models.flows.State;
import io.kestra.core.models.property.Property;
import io.kestra.core.queues.QueueException;
import io.kestra.core.queues.QueueFactoryInterface;
import io.kestra.core.queues.QueueInterface;
Expand Down Expand Up @@ -62,7 +63,7 @@ private Flow createFlow() {
.tasks(Collections.singletonList(Return.builder()
.id("test")
.type(Return.class.getName())
.format("{{ inputs.testInputs }}")
.format(new Property<>("{{ inputs.testInputs }}"))
.build()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.kestra.core.models.executions.ExecutionTrigger;
import io.kestra.core.models.flows.*;
import io.kestra.core.models.flows.input.StringInput;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.WorkerGroup;
import io.kestra.core.models.triggers.AbstractTrigger;
import io.kestra.core.models.triggers.PollingTriggerInterface;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected static FlowWithSource createFlow(List<AbstractTrigger> triggers, List<
.tasks(Collections.singletonList(Return.builder()
.id("test")
.type(Return.class.getName())
.format("{{ inputs.testInputs }}")
.format(new Property<>("{{ inputs.testInputs }}"))
.build()));

if (list != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.kestra.core.models.executions.LogEntry;
import io.kestra.core.models.flows.Flow;
import io.kestra.core.models.flows.FlowWithSource;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.triggers.AbstractTrigger;
import io.kestra.core.models.triggers.PollingTriggerInterface;
import io.kestra.core.models.triggers.TriggerContext;
Expand Down Expand Up @@ -66,7 +67,7 @@ public static FlowWithSource createFlow(Duration sleep) {
.tasks(Collections.singletonList(Return.builder()
.id("test")
.type(Return.class.getName())
.format("{{ inputs.testInputs }}")
.format(new Property<>("{{ inputs.testInputs }}"))
.build())
)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.kestra.core.models.flows.FlowWithSource;
import io.kestra.core.models.flows.Type;
import io.kestra.core.models.flows.input.StringInput;
import io.kestra.core.models.property.Property;
import io.kestra.core.repositories.FlowRepositoryInterface;
import io.kestra.plugin.core.debug.Echo;
import io.kestra.plugin.core.debug.Return;
Expand Down Expand Up @@ -42,7 +43,7 @@ private static Flow create(String tenantId, String flowId, String taskId, Intege
.tasks(Collections.singletonList(Return.builder()
.id(taskId)
.type(Return.class.getName())
.format("test")
.format(Property.of("test"))
.build()))
.build();
}
Expand Down Expand Up @@ -270,7 +271,7 @@ void propertyRenamingDeprecation() {
.tasks(Collections.singletonList(Echo.builder()
.id("taskId")
.type(Return.class.getName())
.format("test")
.format(Property.of("test"))
.build()))
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.core.services;

import io.kestra.core.models.flows.FlowWithSource;
import io.kestra.core.models.property.Property;
import io.kestra.plugin.core.condition.ExecutionFlow;
import io.kestra.plugin.core.condition.ExecutionStatus;
import io.kestra.plugin.core.condition.MultipleCondition;
Expand Down Expand Up @@ -242,7 +243,7 @@ private Return returnTask() {
return Return.builder()
.id("return")
.type(Return.class.getName())
.format("ok")
.format(Property.of("ok"))
.build();
}

Expand Down
Loading

0 comments on commit 6aef532

Please sign in to comment.