Skip to content

Commit 115b153

Browse files
authored
Merge branch 'main' into issue-477
2 parents 0d5f5bb + a59fe58 commit 115b153

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1728
-480
lines changed

Diff for: api/src/main/resources/schema/workflow.yaml

+27-3
Original file line numberDiff line numberDiff line change
@@ -777,19 +777,22 @@ $defs:
777777
errors:
778778
type: object
779779
title: CatchErrors
780-
description: The configuration of a concept used to catch errors.
780+
properties:
781+
with:
782+
$ref: '#/$defs/errorFilter'
783+
description: static error filter
781784
as:
782785
type: string
783786
title: CatchAs
784787
description: The name of the runtime expression variable to save the error as. Defaults to 'error'.
785788
when:
786789
type: string
787790
title: CatchWhen
788-
description: A runtime expression used to determine whether or not to catch the filtered error.
791+
description: A runtime expression used to determine whether to catch the filtered error.
789792
exceptWhen:
790793
type: string
791794
title: CatchExceptWhen
792-
description: A runtime expression used to determine whether or not to catch the filtered error.
795+
description: A runtime expression used to determine whether not to catch the filtered error.
793796
retry:
794797
oneOf:
795798
- $ref: '#/$defs/retryPolicy'
@@ -1152,6 +1155,27 @@ $defs:
11521155
title: ErrorDetails
11531156
description: A human-readable explanation specific to this occurrence of the error.
11541157
required: [ type, status ]
1158+
errorFilter:
1159+
type: object
1160+
title: ErrorFilter
1161+
description: Error filtering base on static values. For error filtering on dynamic values, use catch.when property
1162+
minProperties: 1
1163+
properties:
1164+
type:
1165+
type: string
1166+
description: if present, means this value should be used for filtering
1167+
status:
1168+
type: integer
1169+
description: if present, means this value should be used for filtering
1170+
instance:
1171+
type: string
1172+
description: if present, means this value should be used for filtering
1173+
title:
1174+
type: string
1175+
description: if present, means this value should be used for filtering
1176+
details:
1177+
type: string
1178+
description: if present, means this value should be used for filtering
11551179
uriTemplate:
11561180
title: UriTemplate
11571181
anyOf:

Diff for: impl/core/pom.xml

+11
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
<artifactId>serverlessworkflow-impl-core</artifactId>
99
<properties>
1010
<version.net.thisptr>1.1.0</version.net.thisptr>
11+
<version.com.github.f4b6a3>5.2.3</version.com.github.f4b6a3>
1112
</properties>
1213
<dependencies>
1314
<dependency>
1415
<groupId>io.serverlessworkflow</groupId>
1516
<artifactId>serverlessworkflow-api</artifactId>
1617
<version>7.0.0-SNAPSHOT</version>
1718
</dependency>
19+
<dependency>
20+
<groupId>com.github.f4b6a3</groupId>
21+
<artifactId>ulid-creator</artifactId>
22+
<version>${version.com.github.f4b6a3}</version>
23+
</dependency>
1824
<dependency>
1925
<groupId>com.networknt</groupId>
2026
<artifactId>json-schema-validator</artifactId>
@@ -44,5 +50,10 @@
4450
<artifactId>assertj-core</artifactId>
4551
<scope>test</scope>
4652
</dependency>
53+
<dependency>
54+
<groupId>ch.qos.logback</groupId>
55+
<artifactId>logback-classic</artifactId>
56+
<scope>test</scope>
57+
</dependency>
4758
</dependencies>
4859
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import java.util.concurrent.ExecutorService;
19+
import java.util.function.Supplier;
20+
21+
@FunctionalInterface
22+
public interface ExecutorServiceFactory extends Supplier<ExecutorService> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import java.util.function.BiFunction;
19+
20+
@FunctionalInterface
21+
public interface LongFilter extends BiFunction<WorkflowContext, TaskContext<?>, Long> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import java.util.ArrayDeque;
19+
import java.util.Deque;
20+
import java.util.stream.Collectors;
21+
22+
public class QueueWorkflowPosition implements WorkflowPosition {
23+
24+
private Deque<Object> queue;
25+
26+
QueueWorkflowPosition() {
27+
this(new ArrayDeque<>());
28+
}
29+
30+
private QueueWorkflowPosition(Deque<Object> list) {
31+
this.queue = list;
32+
}
33+
34+
public QueueWorkflowPosition copy() {
35+
return new QueueWorkflowPosition(new ArrayDeque<>(this.queue));
36+
}
37+
38+
@Override
39+
public WorkflowPosition addIndex(int index) {
40+
queue.add(index);
41+
return this;
42+
}
43+
44+
@Override
45+
public WorkflowPosition addProperty(String prop) {
46+
queue.add(prop);
47+
return this;
48+
}
49+
50+
@Override
51+
public String jsonPointer() {
52+
return queue.stream().map(Object::toString).collect(Collectors.joining("/"));
53+
}
54+
55+
@Override
56+
public String toString() {
57+
return "QueueWorkflowPosition [queue=" + queue + "]";
58+
}
59+
60+
@Override
61+
public WorkflowPosition back() {
62+
queue.removeLast();
63+
return this;
64+
}
65+
66+
@Override
67+
public Object last() {
68+
return queue.getLast();
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import io.serverlessworkflow.impl.expressions.RuntimeDescriptor;
19+
import java.util.function.Supplier;
20+
21+
@FunctionalInterface
22+
public interface RuntimeDescriptorFactory extends Supplier<RuntimeDescriptor> {}

Diff for: impl/core/src/main/java/io/serverlessworkflow/impl/DefaultWorkflowPosition.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/StringBufferWorkflowPosition.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
*/
1616
package io.serverlessworkflow.impl;
1717

18-
public class DefaultWorkflowPosition implements WorkflowPosition {
18+
public class StringBufferWorkflowPosition implements WorkflowPosition {
1919

20-
private StringBuilder sb = new StringBuilder("");
20+
private StringBuilder sb;
21+
22+
StringBufferWorkflowPosition() {
23+
this("");
24+
}
25+
26+
private StringBufferWorkflowPosition(String str) {
27+
this.sb = new StringBuilder(str);
28+
}
29+
30+
public StringBufferWorkflowPosition copy() {
31+
return new StringBufferWorkflowPosition(this.jsonPointer());
32+
}
2133

2234
@Override
2335
public WorkflowPosition addIndex(int index) {
@@ -38,7 +50,7 @@ public String jsonPointer() {
3850

3951
@Override
4052
public String toString() {
41-
return "DefaultWorkflowPosition [sb=" + sb + "]";
53+
return "StringBufferWorkflowPosition [sb=" + sb + "]";
4254
}
4355

4456
@Override
@@ -49,4 +61,10 @@ public WorkflowPosition back() {
4961
}
5062
return this;
5163
}
64+
65+
@Override
66+
public Object last() {
67+
int indexOf = sb.lastIndexOf("/");
68+
return indexOf != -1 ? jsonPointer().substring(indexOf + 1) : "";
69+
}
5270
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import java.util.function.BiFunction;
19+
20+
@FunctionalInterface
21+
public interface StringFilter extends BiFunction<WorkflowContext, TaskContext<?>, String> {}

Diff for: impl/core/src/main/java/io/serverlessworkflow/impl/TaskContext.java

+76-5
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,79 @@
1919
import io.serverlessworkflow.api.types.FlowDirective;
2020
import io.serverlessworkflow.api.types.FlowDirectiveEnum;
2121
import io.serverlessworkflow.api.types.TaskBase;
22+
import java.time.Instant;
23+
import java.util.HashMap;
24+
import java.util.Map;
2225

2326
public class TaskContext<T extends TaskBase> {
2427

2528
private final JsonNode rawInput;
2629
private final T task;
30+
private final WorkflowPosition position;
31+
private final Instant startedAt;
2732

2833
private JsonNode input;
2934
private JsonNode output;
3035
private JsonNode rawOutput;
3136
private FlowDirective flowDirective;
37+
private Map<String, Object> contextVariables;
38+
private Instant completedAt;
3239

33-
public TaskContext(JsonNode rawInput, T task) {
40+
public TaskContext(JsonNode input, WorkflowPosition position) {
41+
this(input, null, position, Instant.now(), input, input, input, null, new HashMap<>());
42+
}
43+
44+
public TaskContext(JsonNode input, TaskContext<?> taskContext, T task) {
45+
this(
46+
input,
47+
task,
48+
taskContext.position,
49+
Instant.now(),
50+
input,
51+
input,
52+
input,
53+
task.getThen(),
54+
new HashMap<>(taskContext.variables()));
55+
}
56+
57+
private TaskContext(
58+
JsonNode rawInput,
59+
T task,
60+
WorkflowPosition position,
61+
Instant startedAt,
62+
JsonNode input,
63+
JsonNode output,
64+
JsonNode rawOutput,
65+
FlowDirective flowDirective,
66+
Map<String, Object> contextVariables) {
3467
this.rawInput = rawInput;
35-
this.input = rawInput;
36-
this.rawOutput = rawInput;
37-
this.output = rawInput;
3868
this.task = task;
39-
this.flowDirective = task.getThen();
69+
this.position = position;
70+
this.startedAt = startedAt;
71+
this.input = input;
72+
this.output = output;
73+
this.rawOutput = rawOutput;
74+
this.flowDirective = flowDirective;
75+
this.contextVariables = contextVariables;
76+
}
77+
78+
public TaskContext<T> copy() {
79+
return new TaskContext<T>(
80+
rawInput,
81+
task,
82+
position.copy(),
83+
startedAt,
84+
input,
85+
output,
86+
rawOutput,
87+
flowDirective,
88+
new HashMap<>(contextVariables));
4089
}
4190

4291
public void input(JsonNode input) {
4392
this.input = input;
93+
this.rawOutput = input;
94+
this.output = input;
4495
}
4596

4697
public JsonNode input() {
@@ -81,4 +132,24 @@ public FlowDirective flowDirective() {
81132
? new FlowDirective().withFlowDirectiveEnum(FlowDirectiveEnum.CONTINUE)
82133
: flowDirective;
83134
}
135+
136+
public Map<String, Object> variables() {
137+
return contextVariables;
138+
}
139+
140+
public WorkflowPosition position() {
141+
return position;
142+
}
143+
144+
public Instant startedAt() {
145+
return startedAt;
146+
}
147+
148+
public void completedAt(Instant instant) {
149+
this.completedAt = instant;
150+
}
151+
152+
public Instant completedAt() {
153+
return completedAt;
154+
}
84155
}

0 commit comments

Comments
 (0)