Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Change WorkflowDef default schema version to 2 (#966)
Browse files Browse the repository at this point in the history
* change WorkflowDef default schema version to 2

* add a check for workflowDef schema version to be always 2

* change WorkflowDef default schema version to 2

* add a check for workflowDef schema version to be always 2

* updated test
  • Loading branch information
falu2010-netflix authored Jan 31, 2019
1 parent 6b1d2bc commit 8256ff3
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Optional;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
Expand Down Expand Up @@ -74,8 +75,9 @@ public class WorkflowDef extends Auditable {
private String failureWorkflow;

@ProtoField(id = 8)
@Min(value = 1, message = "workflowDef schemaVersion: ${validatedValue} should be >= {value}")
private int schemaVersion = 1;
@Min(value = 2, message = "workflowDef schemaVersion: {value} is only supported")
@Max(value = 2, message = "workflowDef schemaVersion: {value} is only supported")
private int schemaVersion = 2;

//By default a workflow is restartable
@ProtoField(id = 9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void test() {
@Test
public void testWorkflowDefConstraints() {
WorkflowDef workflowDef = new WorkflowDef();//name is null
workflowDef.setSchemaVersion(1);
workflowDef.setSchemaVersion(2);

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Expand All @@ -128,7 +128,7 @@ public void testWorkflowDefConstraints() {
@Test
public void testWorkflowDefConstraintsWithMultipleEnvVariable() {
WorkflowDef workflowDef = new WorkflowDef();//name is null
workflowDef.setSchemaVersion(1);
workflowDef.setSchemaVersion(2);
workflowDef.setName("test_env");

WorkflowTask workflowTask_1 = new WorkflowTask();
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testWorkflowDefConstraintsWithMultipleEnvVariable() {
@Test
public void testWorkflowDefConstraintsSingleEnvVariable() {
WorkflowDef workflowDef = new WorkflowDef();//name is null
workflowDef.setSchemaVersion(1);
workflowDef.setSchemaVersion(2);
workflowDef.setName("test_env");

WorkflowTask workflowTask_1 = new WorkflowTask();
Expand All @@ -194,7 +194,7 @@ public void testWorkflowDefConstraintsSingleEnvVariable() {
@Test
public void testWorkflowDefConstraintsDualEnvVariable() {
WorkflowDef workflowDef = new WorkflowDef();//name is null
workflowDef.setSchemaVersion(1);
workflowDef.setSchemaVersion(2);
workflowDef.setName("test_env");

WorkflowTask workflowTask_1 = new WorkflowTask();
Expand Down Expand Up @@ -223,7 +223,7 @@ public void testWorkflowDefConstraintsDualEnvVariable() {
@Test
public void testWorkflowDefConstraintsWithMapAsInputParam() {
WorkflowDef workflowDef = new WorkflowDef();//name is null
workflowDef.setSchemaVersion(1);
workflowDef.setSchemaVersion(2);
workflowDef.setName("test_env");

WorkflowTask workflowTask_1 = new WorkflowTask();
Expand Down Expand Up @@ -311,4 +311,33 @@ public void testWorkflowTaskInputParamValueInvalid() {

assertTrue(validationErrors.contains("key: blabla input parameter value: is null or empty"));
}

@Test
public void testWorkflowSchemaVersion1() {
WorkflowDef workflowDef = new WorkflowDef();//name is null
workflowDef.setSchemaVersion(3);
workflowDef.setName("test_env");

WorkflowTask workflowTask = new WorkflowTask();

workflowTask.setName("t1");
workflowTask.setWorkflowTaskType(TaskType.SIMPLE);
workflowTask.setTaskReferenceName("t1");

Map<String, Object> map = new HashMap<>();
map.put("blabla", "");
workflowTask.setInputParameters(map);

workflowDef.getTasks().add(workflowTask);

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
assertEquals(2, result.size());

List<String> validationErrors = new ArrayList<>();
result.forEach(e -> validationErrors.add(e.getMessage()));

assertTrue(validationErrors.contains("workflowDef schemaVersion: 2 is only supported"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public void setUp() {
parametersUtils = new ParametersUtils();

ip1 = new HashMap<>();
ip1.put("p1", "workflow.input.param1");
ip1.put("p2", "workflow.input.param2");
ip1.put("case", "workflow.input.case");
ip1.put("p1", "${workflow.input.param1}");
ip1.put("p2", "${workflow.input.param2}");
ip1.put("case", "${workflow.input.case}");

task1 = new WorkflowTask();
task1.setName("Test1");
Expand Down Expand Up @@ -152,8 +152,8 @@ public void getEvaluatedCaseValue() {
Workflow workflowInstance = new Workflow();
workflowInstance.setWorkflowDefinition(new WorkflowDef());
Map<String, Object> workflowInput = new HashMap<>();
workflowInput.put("p1", "workflow.input.param1");
workflowInput.put("p2", "workflow.input.param2");
workflowInput.put("param1", "test1");
workflowInput.put("param2", "test2");
workflowInput.put("case", "0");
workflowInstance.setInput(workflowInput);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testRegisterWorkflowDefInvalidName() {
public void testRegisterWorkflowDef() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("somename");
workflowDef.setSchemaVersion(5);
workflowDef.setSchemaVersion(2);
List<WorkflowTask> tasks = new ArrayList<>();
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setTaskReferenceName("hello");
Expand Down
Loading

0 comments on commit 8256ff3

Please sign in to comment.