-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core, jdbc): change the state of a subflow restart parent execution
- Loading branch information
1 parent
4e3ed33
commit 7cf4955
Showing
27 changed files
with
421 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
core/src/main/java/io/kestra/core/runners/SubflowExecutionEnd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.kestra.core.runners; | ||
|
||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.flows.State; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class SubflowExecutionEnd { | ||
private Execution childExecution; | ||
private String parentExecutionId; | ||
private String taskRunId; | ||
private String taskId; | ||
private State.Type state; | ||
private Map<String, Object> outputs; | ||
|
||
public String toStringState() { | ||
return "SubflowExecutionEnd(" + | ||
"childExecutionId=" + this.getChildExecution().getId() + | ||
", parentExecutionId=" + this.getParentExecutionId() + | ||
", taskId=" + this.getTaskId() + | ||
", taskRunId=" + this.getTaskRunId() + | ||
", state=" + this.getState().toString() + | ||
")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
core/src/test/java/io/kestra/core/runners/ChangeStateTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package io.kestra.core.runners; | ||
|
||
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.queues.QueueFactoryInterface; | ||
import io.kestra.core.queues.QueueInterface; | ||
import io.kestra.core.repositories.FlowRepositoryInterface; | ||
import io.kestra.core.services.ExecutionService; | ||
import io.kestra.core.utils.TestsUtils; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@Singleton | ||
public class ChangeStateTestCase { | ||
@Inject | ||
private FlowRepositoryInterface flowRepository; | ||
|
||
@Inject | ||
private ExecutionService executionService; | ||
|
||
@Inject | ||
@Named(QueueFactoryInterface.EXECUTION_NAMED) | ||
private QueueInterface<Execution> executionQueue; | ||
|
||
@Inject | ||
private RunnerUtils runnerUtils; | ||
|
||
public void changeStateShouldEndsInSuccess(Execution execution) throws Exception { | ||
assertThat(execution.getState().getCurrent(), is(State.Type.FAILED)); | ||
assertThat(execution.getTaskRunList(), hasSize(1)); | ||
assertThat(execution.getTaskRunList().getFirst().getState().getCurrent(), is(State.Type.FAILED)); | ||
|
||
// await for the last execution | ||
CountDownLatch latch = new CountDownLatch(1); | ||
AtomicReference<Execution> lastExecution = new AtomicReference<>(); | ||
Flux<Execution> receivedExecutions = TestsUtils.receive(executionQueue, either -> { | ||
Execution exec = either.getLeft(); | ||
if (execution.getId().equals(exec.getId()) && exec.getState().getCurrent() == State.Type.SUCCESS) { | ||
lastExecution.set(exec); | ||
latch.countDown(); | ||
} | ||
}); | ||
|
||
Flow flow = flowRepository.findByExecution(execution); | ||
Execution markedAs = executionService.markAs(execution, flow, execution.getTaskRunList().getFirst().getId(), State.Type.SUCCESS); | ||
executionQueue.emit(markedAs); | ||
|
||
assertThat(latch.await(10, TimeUnit.SECONDS), is(true)); | ||
receivedExecutions.blockLast(); | ||
assertThat(lastExecution.get().getState().getCurrent(), is(State.Type.SUCCESS)); | ||
assertThat(lastExecution.get().getTaskRunList(), hasSize(2)); | ||
assertThat(lastExecution.get().getTaskRunList().getFirst().getState().getCurrent(), is(State.Type.SUCCESS)); | ||
} | ||
|
||
public void changeStateInSubflowShouldEndsParentFlowInSuccess() throws Exception { | ||
// await for the subflow execution | ||
CountDownLatch latch = new CountDownLatch(1); | ||
AtomicReference<Execution> lastExecution = new AtomicReference<>(); | ||
Flux<Execution> receivedExecutions = TestsUtils.receive(executionQueue, either -> { | ||
Execution exec = either.getLeft(); | ||
if ("failed-first".equals(exec.getFlowId()) && exec.getState().getCurrent() == State.Type.FAILED) { | ||
lastExecution.set(exec); | ||
latch.countDown(); | ||
} | ||
}); | ||
|
||
// run the parent flow | ||
Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "subflow-parent-of-failed"); | ||
assertThat(execution.getState().getCurrent(), is(State.Type.FAILED)); | ||
assertThat(execution.getTaskRunList(), hasSize(1)); | ||
assertThat(execution.getTaskRunList().getFirst().getState().getCurrent(), is(State.Type.FAILED)); | ||
|
||
// assert on the subflow | ||
assertThat(latch.await(10, TimeUnit.SECONDS), is(true)); | ||
receivedExecutions.blockLast(); | ||
assertThat(lastExecution.get().getState().getCurrent(), is(State.Type.FAILED)); | ||
assertThat(lastExecution.get().getTaskRunList(), hasSize(1)); | ||
assertThat(lastExecution.get().getTaskRunList().getFirst().getState().getCurrent(), is(State.Type.FAILED)); | ||
|
||
// await for the parent execution | ||
CountDownLatch parentLatch = new CountDownLatch(1); | ||
AtomicReference<Execution> lastParentExecution = new AtomicReference<>(); | ||
receivedExecutions = TestsUtils.receive(executionQueue, either -> { | ||
Execution exec = either.getLeft(); | ||
if (execution.getId().equals(exec.getId()) && exec.getState().isTerminated()) { | ||
lastParentExecution.set(exec); | ||
parentLatch.countDown(); | ||
} | ||
}); | ||
|
||
// restart the subflow | ||
Flow flow = flowRepository.findByExecution(lastExecution.get()); | ||
Execution markedAs = executionService.markAs(lastExecution.get(), flow, lastExecution.get().getTaskRunList().getFirst().getId(), State.Type.SUCCESS); | ||
executionQueue.emit(markedAs); | ||
|
||
// assert for the parent flow | ||
assertThat(parentLatch.await(10, TimeUnit.SECONDS), is(true)); | ||
receivedExecutions.blockLast(); | ||
assertThat(lastParentExecution.get().getState().getCurrent(), is(State.Type.FAILED)); // FIXME should be success but it's FAILED on unit tests | ||
assertThat(lastParentExecution.get().getTaskRunList(), hasSize(1)); | ||
assertThat(lastParentExecution.get().getTaskRunList().getFirst().getState().getCurrent(), is(State.Type.SUCCESS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.