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

Commit a5f3188

Browse files
authored
Merge pull request #3787 from wildMythicWest/main
Introducing a Noop task to allow for switch decision cases to have "no" tasks
2 parents 5ed77fb + 3492e6e commit a5f3188

File tree

5 files changed

+178
-1
lines changed

5 files changed

+178
-1
lines changed

common/src/main/java/com/netflix/conductor/common/metadata/tasks/TaskType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public enum TaskType {
4040
TERMINATE,
4141
KAFKA_PUBLISH,
4242
JSON_JQ_TRANSFORM,
43-
SET_VARIABLE;
43+
SET_VARIABLE,
44+
NOOP;
4445

4546
/**
4647
* TaskType constants representing each of the possible enumeration values. Motivation: to not
@@ -69,6 +70,7 @@ public enum TaskType {
6970
public static final String TASK_TYPE_JSON_JQ_TRANSFORM = "JSON_JQ_TRANSFORM";
7071
public static final String TASK_TYPE_SET_VARIABLE = "SET_VARIABLE";
7172
public static final String TASK_TYPE_FORK = "FORK";
73+
public static final String TASK_TYPE_NOOP = "NOOP";
7274

7375
private static final Set<String> BUILT_IN_TASKS = new HashSet<>();
7476

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2023 Netflix, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.netflix.conductor.core.execution.mapper;
14+
15+
import java.util.List;
16+
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
import org.springframework.stereotype.Component;
20+
21+
import com.netflix.conductor.common.metadata.tasks.TaskType;
22+
import com.netflix.conductor.model.TaskModel;
23+
24+
import static com.netflix.conductor.common.metadata.tasks.TaskType.*;
25+
26+
@Component
27+
public class NoopTaskMapper implements TaskMapper {
28+
29+
public static final Logger logger = LoggerFactory.getLogger(NoopTaskMapper.class);
30+
31+
@Override
32+
public String getTaskType() {
33+
return TaskType.NOOP.name();
34+
}
35+
36+
@Override
37+
public List<TaskModel> getMappedTasks(TaskMapperContext taskMapperContext) {
38+
logger.debug("TaskMapperContext {} in NoopTaskMapper", taskMapperContext);
39+
40+
TaskModel task = taskMapperContext.createTaskModel();
41+
task.setTaskType(TASK_TYPE_NOOP);
42+
task.setStartTime(System.currentTimeMillis());
43+
task.setStatus(TaskModel.Status.IN_PROGRESS);
44+
return List.of(task);
45+
}
46+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2023 Netflix, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.netflix.conductor.core.execution.tasks;
14+
15+
import org.springframework.stereotype.Component;
16+
17+
import com.netflix.conductor.core.execution.WorkflowExecutor;
18+
import com.netflix.conductor.model.TaskModel;
19+
import com.netflix.conductor.model.WorkflowModel;
20+
21+
import static com.netflix.conductor.common.metadata.tasks.TaskType.TASK_TYPE_NOOP;
22+
23+
@Component(TASK_TYPE_NOOP)
24+
public class Noop extends WorkflowSystemTask {
25+
26+
public Noop() {
27+
super(TASK_TYPE_NOOP);
28+
}
29+
30+
@Override
31+
public boolean execute(
32+
WorkflowModel workflow, TaskModel task, WorkflowExecutor workflowExecutor) {
33+
task.setStatus(TaskModel.Status.COMPLETED);
34+
return true;
35+
}
36+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2023 Netflix, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.netflix.conductor.core.execution.mapper;
14+
15+
import java.util.List;
16+
17+
import org.junit.Assert;
18+
import org.junit.Test;
19+
20+
import com.netflix.conductor.common.metadata.tasks.TaskDef;
21+
import com.netflix.conductor.common.metadata.tasks.TaskType;
22+
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
23+
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;
24+
import com.netflix.conductor.core.utils.IDGenerator;
25+
import com.netflix.conductor.model.TaskModel;
26+
import com.netflix.conductor.model.WorkflowModel;
27+
28+
public class NoopTaskMapperTest {
29+
30+
@Test
31+
public void getMappedTasks() {
32+
33+
WorkflowTask workflowTask = new WorkflowTask();
34+
workflowTask.setType(TaskType.TASK_TYPE_NOOP);
35+
36+
String taskId = new IDGenerator().generate();
37+
38+
WorkflowDef workflowDef = new WorkflowDef();
39+
WorkflowModel workflow = new WorkflowModel();
40+
workflow.setWorkflowDefinition(workflowDef);
41+
42+
TaskMapperContext taskMapperContext =
43+
TaskMapperContext.newBuilder()
44+
.withWorkflowModel(workflow)
45+
.withTaskDefinition(new TaskDef())
46+
.withWorkflowTask(workflowTask)
47+
.withRetryCount(0)
48+
.withTaskId(taskId)
49+
.build();
50+
51+
List<TaskModel> mappedTasks = new NoopTaskMapper().getMappedTasks(taskMapperContext);
52+
53+
Assert.assertNotNull(mappedTasks);
54+
Assert.assertEquals(1, mappedTasks.size());
55+
Assert.assertEquals(TaskType.TASK_TYPE_NOOP, mappedTasks.get(0).getTaskType());
56+
}
57+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2023 Netflix, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.netflix.conductor.core.execution.tasks;
14+
15+
import org.junit.Test;
16+
17+
import com.netflix.conductor.core.execution.WorkflowExecutor;
18+
import com.netflix.conductor.model.TaskModel;
19+
import com.netflix.conductor.model.WorkflowModel;
20+
21+
import static org.junit.Assert.*;
22+
import static org.mockito.Mockito.*;
23+
24+
public class TestNoop {
25+
26+
private final WorkflowExecutor executor = mock(WorkflowExecutor.class);
27+
28+
@Test
29+
public void should_do_nothing() {
30+
WorkflowModel workflow = new WorkflowModel();
31+
Noop noopTask = new Noop();
32+
TaskModel task = new TaskModel();
33+
noopTask.execute(workflow, task, executor);
34+
assertEquals(TaskModel.Status.COMPLETED, task.getStatus());
35+
}
36+
}

0 commit comments

Comments
 (0)