Skip to content

Commit b48162d

Browse files
authored
runtime-v2: fix the duration format when generating an effective yaml (#383)
1 parent 81c33fc commit b48162d

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

runtime/v2/model/src/main/java/com/walmartlabs/concord/runtime/v2/ProjectSerializerV2.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import java.io.IOException;
3232
import java.io.OutputStream;
33+
import java.time.Duration;
3334

3435
public class ProjectSerializerV2 {
3536

@@ -73,7 +74,8 @@ private static ObjectMapper createObjectMapper() {
7374
.addSerializer(TaskCall.class, new TaskCallStepSerializer())
7475
.addSerializer(Form.class, new FormDefinitionSerializer())
7576
.addSerializer(Trigger.class, new TriggerSerializer())
76-
.addSerializer(ProcessDefinition.class, new ProcessDefinitionSerializer());
77+
.addSerializer(ProcessDefinition.class, new ProcessDefinitionSerializer())
78+
.addSerializer(Duration.class, new DurationSerializer());
7779

7880
return new ObjectMapper(new YAMLFactory()
7981
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.walmartlabs.concord.runtime.v2.serializer;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2017 - 2020 Walmart Inc.
8+
* -----
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =====
21+
*/
22+
23+
import com.fasterxml.jackson.core.JsonGenerator;
24+
import com.fasterxml.jackson.databind.SerializerProvider;
25+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
26+
import com.walmartlabs.concord.runtime.v2.model.ProcessDefinition;
27+
28+
import java.io.IOException;
29+
import java.time.Duration;
30+
import java.util.Collections;
31+
import java.util.stream.Collectors;
32+
33+
import static com.walmartlabs.concord.runtime.v2.serializer.SerializerUtils.writeNotEmptyObjectField;
34+
35+
public class DurationSerializer extends StdSerializer<Duration> {
36+
37+
private static final long serialVersionUID = 1L;
38+
39+
public DurationSerializer() {
40+
this(null);
41+
}
42+
43+
public DurationSerializer(Class<Duration> t) {
44+
super(t);
45+
}
46+
47+
@Override
48+
public void serialize(Duration value, JsonGenerator gen, SerializerProvider provider) throws IOException {
49+
if (value != null) {
50+
gen.writeString(value.toString());
51+
}
52+
}
53+
}

runtime/v2/model/src/test/java/com/walmartlabs/concord/project/runtime/v2/ProjectSerializerV2Test.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,22 @@
3636
import java.util.*;
3737

3838
import static org.junit.Assert.assertEquals;
39+
import static org.junit.Assert.assertTrue;
3940

4041
public class ProjectSerializerV2Test extends AbstractParserTest {
4142

4243
private final ProjectSerializerV2 serializer = new ProjectSerializerV2();
4344

45+
@Test
46+
public void testConfiguration() throws Exception {
47+
ProcessDefinitionConfiguration cfg = ProcessDefinitionConfiguration.builder()
48+
.processTimeout(Duration.parse("PT1H"))
49+
.build();
50+
51+
String result = toYaml(cfg);
52+
assertTrue(result.contains("processTimeout: \"PT1H\""));
53+
}
54+
4455
@Test
4556
public void testCheckpoint() throws Exception {
4657
String result = toYaml(new Checkpoint(location(), "checkpoint-1", simpleOptions()));

0 commit comments

Comments
 (0)