Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/jackson-setter-for-graph-clusters #2120

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public AbstractGraph(String uid) {
public String getLabel() {
return this.getUid();
}

public void updateUidWithChildren(String uid) {
this.uid = uid;
}

public void updateErrorWithChildren(boolean error) {
this.error = error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void addNode(AbstractGraph node) {

public void addNode(AbstractGraph node, boolean withClusterUidPrefix) {
if (withClusterUidPrefix) {
node.setUid(prefixedUid(node.uid));
node.updateUidWithChildren(prefixedUid(node.uid));
}
this.getGraph().addNode(node);
}
Expand Down Expand Up @@ -100,25 +100,23 @@ public Map<GraphCluster, List<AbstractGraph>> allNodesByParent() {

@Override
public String getUid() {
return "cluster_" + super.getUid();
return "cluster_" + super.getUid().replace("cluster_", "");
}

@Override
@JsonIgnore
public void setUid(String uid) {
public void updateUidWithChildren(String uid) {
graph.nodes().stream().filter(node ->
// filter other clusters' root & end to prevent setting uid multiple times
// this is because we need other clusters' root & end to have edges over them, but they are already managed by their own cluster
(!(node instanceof GraphClusterRoot) && !(node instanceof GraphClusterEnd))
|| node.equals(this.root) || node.equals(this.end))
.forEach(node -> node.setUid(uid + node.uid.substring(this.uid.length())));
.forEach(node -> node.updateUidWithChildren(uid + node.uid.substring(this.uid.length())));

super.setUid(uid);
super.updateUidWithChildren(uid);
}

@Override
@JsonIgnore
public void setError(boolean error) {
public void updateErrorWithChildren(boolean error) {
this.error = error;

this.taskNode.error = error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void replace() {
parentCluster.getGraph().removeNode(taskToReplace);

if (taskToReplace.isError()) {
clusterForReplacement.setError(true);
clusterForReplacement.updateErrorWithChildren(true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/kestra/core/utils/GraphUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private static void fillGraph(
graph.addNode(currentGraph);

if (relationType == RelationType.ERROR) {
currentGraph.setError(true);
currentGraph.updateErrorWithChildren(true);
if (isFirst) {
previous = graph.getRoot();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void allFlowable() throws IllegalVariableEvaluationException {
Flow flow = this.parse("flows/valids/all-flowable.yaml");
FlowGraph flowGraph = GraphUtils.flowGraph(flow, null);

assertThat(flowGraph.getNodes().size(), is(34));
assertThat(flowGraph.getEdges().size(), is(37));
assertThat(flowGraph.getClusters().size(), is(6));
assertThat(flowGraph.getNodes().size(), is(38));
assertThat(flowGraph.getEdges().size(), is(42));
assertThat(flowGraph.getClusters().size(), is(7));
}

@Test
Expand Down
7 changes: 7 additions & 0 deletions core/src/test/resources/flows/valids/all-flowable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ tasks:
- id: 1-each-2-1
type: io.kestra.core.tasks.debugs.Return
format: "{{task.id}} > {{taskrun.value}}"
errors:
- id: 1-each-seq-error
type: io.kestra.core.tasks.flows.Sequential
tasks:
- id: 1-each-seq-error-1
type: io.kestra.core.tasks.debugs.Return
format: "error {{task.id}} > {{taskrun.value}}"


# Simple task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ void graph() {
FlowGraph result = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/flows/io.kestra" +
".tests/all-flowable/graph"), FlowGraph.class);

assertThat(result.getNodes().size(), is(34));
assertThat(result.getEdges().size(), is(37));
assertThat(result.getClusters().size(), is(6));
assertThat(result.getNodes().size(), is(38));
assertThat(result.getEdges().size(), is(42));
assertThat(result.getClusters().size(), is(7));
assertThat(result.getClusters().stream().map(FlowGraph.Cluster::getCluster).toList(), Matchers.everyItem(
Matchers.hasProperty("uid", Matchers.not(Matchers.startsWith("cluster_cluster_")))
));
}

@Test
Expand Down