-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support loading workflow definitions from database (#531)
* Support loading workflow definitions from database if nflow.definition.load=true is set * Make the stored workflow check interval configurable * Fix SkipAutoStartTest to fail if nflow tries to access the database Co-authored-by: Edvard Fonsell <edvard.fonsell@nitor.com>
- Loading branch information
Showing
19 changed files
with
408 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,5 +52,4 @@ public int compareTo(Signal o) { | |
return value.compareTo(o.value); | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...gine/src/main/java/io/nflow/engine/internal/workflow/StoredWorkflowDefinitionWrapper.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,44 @@ | ||
package io.nflow.engine.internal.workflow; | ||
|
||
import static io.nflow.engine.workflow.definition.WorkflowStateType.start; | ||
import static java.util.Collections.emptyMap; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
import java.util.Collection; | ||
|
||
import io.nflow.engine.workflow.curated.State; | ||
import io.nflow.engine.workflow.definition.WorkflowDefinition; | ||
import io.nflow.engine.workflow.definition.WorkflowSettings; | ||
import io.nflow.engine.workflow.definition.WorkflowState; | ||
import io.nflow.engine.workflow.definition.WorkflowStateType; | ||
|
||
public class StoredWorkflowDefinitionWrapper extends WorkflowDefinition { | ||
public StoredWorkflowDefinitionWrapper(StoredWorkflowDefinition stored) { | ||
super(stored.type, getInitialState(stored), getErrorState(stored), new WorkflowSettings.Builder().build(), emptyMap(), allStates(stored), false); | ||
setDescription(stored.description); | ||
} | ||
|
||
private static Collection<WorkflowState> allStates(StoredWorkflowDefinition stored) { | ||
return stored.states.stream().map(StoredWorkflowDefinitionWrapper::toState).collect(toList()); | ||
} | ||
|
||
private static WorkflowState getInitialState(StoredWorkflowDefinition stored) { | ||
return stored.states.stream() | ||
.filter(state -> start.name().equals((state.type))) | ||
.findFirst() | ||
.map(StoredWorkflowDefinitionWrapper::toState) | ||
.orElseThrow(() -> new IllegalStateException("Could not find initial state for " + stored)); | ||
} | ||
|
||
private static WorkflowState toState(StoredWorkflowDefinition.State state) { | ||
return new State(state.id, WorkflowStateType.valueOf(state.type), state.description); | ||
} | ||
|
||
private static WorkflowState getErrorState(StoredWorkflowDefinition stored) { | ||
return stored.states.stream() | ||
.filter(state -> stored.onError.equals((state.id))) | ||
.findFirst() | ||
.map(StoredWorkflowDefinitionWrapper::toState) | ||
.orElseThrow(() -> new IllegalStateException("Could not find error state for " + stored)); | ||
} | ||
} |
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
Oops, something went wrong.