Skip to content

Commit 4e8300e

Browse files
authored
Merge pull request #113 from tsurdilo/stateexectimeoutup
Updating state exec timeout
2 parents 5296f6e + 7283175 commit 4e8300e

File tree

6 files changed

+156
-7
lines changed

6 files changed

+156
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.api.deserializers;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.databind.DeserializationContext;
20+
import com.fasterxml.jackson.databind.JsonNode;
21+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
22+
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
23+
import io.serverlessworkflow.api.timeouts.StateExecTimeout;
24+
25+
import java.io.IOException;
26+
27+
public class StateExecTimeoutDeserializer extends StdDeserializer<StateExecTimeout> {
28+
29+
private static final long serialVersionUID = 510l;
30+
31+
@SuppressWarnings("unused")
32+
private WorkflowPropertySource context;
33+
34+
public StateExecTimeoutDeserializer() {
35+
this(StateExecTimeout.class);
36+
}
37+
38+
public StateExecTimeoutDeserializer(Class<?> vc) {
39+
super(vc);
40+
}
41+
42+
public StateExecTimeoutDeserializer(WorkflowPropertySource context) {
43+
this(StateExecTimeout.class);
44+
this.context = context;
45+
}
46+
47+
@Override
48+
public StateExecTimeout deserialize(JsonParser jp,
49+
DeserializationContext ctxt) throws IOException {
50+
51+
JsonNode node = jp.getCodec().readTree(jp);
52+
53+
StateExecTimeout stateExecTimeout = new StateExecTimeout();
54+
55+
if (!node.isObject()) {
56+
stateExecTimeout.setTotal(node.asText());
57+
stateExecTimeout.setSingle(null);
58+
return stateExecTimeout;
59+
} else {
60+
if (node.get("single") != null) {
61+
stateExecTimeout.setSingle(node.get("single").asText());
62+
}
63+
64+
if (node.get("total") != null) {
65+
stateExecTimeout.setTotal(node.get("total").asText());
66+
}
67+
68+
return stateExecTimeout;
69+
}
70+
}
71+
}

api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.serverlessworkflow.api.states.DefaultState;
3636
import io.serverlessworkflow.api.states.OperationState;
3737
import io.serverlessworkflow.api.states.ParallelState;
38+
import io.serverlessworkflow.api.timeouts.StateExecTimeout;
3839
import io.serverlessworkflow.api.transitions.Transition;
3940
import io.serverlessworkflow.api.workflow.*;
4041

@@ -77,6 +78,7 @@ private void addDefaultSerializers() {
7778
addSerializer(new ScheduleSerializer());
7879
addSerializer(new SubFlowRefSerializer());
7980
addSerializer(new AuthDefinitionSerializer());
81+
addSerializer(new StateExecTimeoutSerializer());
8082
addSerializer(extensionSerializer);
8183
}
8284

@@ -109,6 +111,7 @@ private void addDefaultDeserializers() {
109111
addDeserializer(Schedule.class, new ScheduleDeserializer(workflowPropertySource));
110112
addDeserializer(DataInputSchema.class, new DataInputSchemaDeserializer(workflowPropertySource));
111113
addDeserializer(AuthDefinition.class, new AuthDefinitionDeserializer(workflowPropertySource));
114+
addDeserializer(StateExecTimeout.class, new StateExecTimeoutDeserializer(workflowPropertySource));
112115
}
113116

114117
public ExtensionSerializer getExtensionSerializer() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.api.serializers;
17+
18+
import com.fasterxml.jackson.core.JsonGenerator;
19+
import com.fasterxml.jackson.databind.SerializerProvider;
20+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
21+
import io.serverlessworkflow.api.timeouts.StateExecTimeout;
22+
23+
import java.io.IOException;
24+
25+
public class StateExecTimeoutSerializer extends StdSerializer<StateExecTimeout> {
26+
27+
public StateExecTimeoutSerializer() {
28+
this(StateExecTimeout.class);
29+
}
30+
31+
protected StateExecTimeoutSerializer(Class<StateExecTimeout> t) {
32+
super(t);
33+
}
34+
35+
@Override
36+
public void serialize(StateExecTimeout stateExecTimeout,
37+
JsonGenerator gen,
38+
SerializerProvider provider) throws IOException {
39+
40+
if (stateExecTimeout != null) {
41+
if ((stateExecTimeout.getTotal() != null && stateExecTimeout.getTotal().isEmpty())
42+
&& (stateExecTimeout.getSingle() == null || stateExecTimeout.getSingle().isEmpty())) {
43+
gen.writeString(stateExecTimeout.getTotal());
44+
} else {
45+
gen.writeStartObject();
46+
47+
if (stateExecTimeout.getTotal() != null && stateExecTimeout.getTotal().length() > 0) {
48+
gen.writeStringField("total", stateExecTimeout.getTotal());
49+
}
50+
51+
if (stateExecTimeout.getSingle() != null && stateExecTimeout.getSingle().length() > 0) {
52+
gen.writeStringField("single", stateExecTimeout.getSingle());
53+
}
54+
55+
gen.writeEndObject();
56+
}
57+
}
58+
}
59+
}
60+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.timeouts.StateExecTimeout",
4+
"properties": {
5+
"single": {
6+
"type": "string",
7+
"description": "Single state execution timeout, not including retries (ISO 8601 duration format)",
8+
"minLength": 1
9+
},
10+
"total": {
11+
"type": "string",
12+
"description": "Total state execution timeout, including retries (ISO 8601 duration format)",
13+
"minLength": 1
14+
}
15+
},
16+
"required": [
17+
"total"
18+
]
19+
}

api/src/main/resources/schema/timeouts/timeoutsdef.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"$ref": "workflowexectimeout.json"
88
},
99
"stateExecTimeout": {
10-
"type": "string",
11-
"description": "State execution timeout duration (ISO 8601 duration format)",
12-
"minLength": 1
10+
"$ref": "stateexectimeout.json"
1311
},
1412
"actionExecTimeout": {
1513
"type": "string",

api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,15 @@ public void testTimeouts(String workflowLocation) {
575575
assertNotNull(firstState.getTimeouts());
576576
assertNotNull(firstState.getTimeouts().getStateExecTimeout());
577577
assertNotNull(firstState.getTimeouts().getEventTimeout());
578-
assertEquals("PT5M", firstState.getTimeouts().getStateExecTimeout());
578+
assertEquals("PT5M", firstState.getTimeouts().getStateExecTimeout().getTotal());
579579
assertEquals("PT2M", firstState.getTimeouts().getEventTimeout());
580580

581581

582582
assertTrue(workflow.getStates().get(1) instanceof ParallelState);
583583
ParallelState secondState = (ParallelState) workflow.getStates().get(1);
584584
assertNotNull(secondState.getTimeouts());
585585
assertNotNull(secondState.getTimeouts().getStateExecTimeout());
586-
assertEquals("PT5M", secondState.getTimeouts().getStateExecTimeout());
586+
assertEquals("PT5M", secondState.getTimeouts().getStateExecTimeout().getTotal());
587587

588588
assertNotNull(secondState.getBranches());
589589
assertEquals(2, secondState.getBranches().size());
@@ -658,7 +658,5 @@ public void testAuthOAuth(String workflowLocation) {
658658
assertEquals("clientCredentials", auth.getOauth().getGrantType().value());
659659
assertEquals("${ $SECRETS.clientid }", auth.getOauth().getClientId());
660660
assertEquals("${ $SECRETS.clientsecret }", auth.getOauth().getClientSecret());
661-
662-
System.out.println("****************\n\n " + Workflow.toJson(workflow));
663661
}
664662
}

0 commit comments

Comments
 (0)