use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class TestQueueManager method test.
@Test
public void test() throws Exception {
Map<Status, ObservableQueue> queues = new HashMap<>();
queues.put(Status.COMPLETED, queue);
QueueManager qm = new QueueManager(queues, es, objectMapper);
qm.updateByTaskRefName("v_0", "t0", new HashMap<>(), Status.COMPLETED);
Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
assertTrue(updatedTasks.stream().anyMatch(task -> task.getTaskId().equals("t0")));
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class TestQueueManager method testWithTaskId.
@Test
public void testWithTaskId() throws Exception {
Map<Status, ObservableQueue> queues = new HashMap<>();
queues.put(Status.COMPLETED, queue);
QueueManager qm = new QueueManager(queues, es, objectMapper);
qm.updateByTaskId("v_2", "t2", new HashMap<>(), Status.COMPLETED);
Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
assertTrue(updatedTasks.stream().anyMatch(task -> task.getTaskId().equals("t2")));
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class QueueManager method queues.
public Map<Status, String> queues() {
Map<Status, String> size = new HashMap<>();
queues.entrySet().forEach(e -> {
ObservableQueue queue = e.getValue();
size.put(e.getKey(), queue.getURI());
});
return size;
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class QueueManager method startMonitor.
private void startMonitor(Status status, ObservableQueue queue) {
queue.observe().subscribe((Message msg) -> {
try {
logger.debug("Got message {}", msg.getPayload());
String payload = msg.getPayload();
JsonNode payloadJSON = objectMapper.readTree(payload);
String externalId = getValue("externalId", payloadJSON);
if (externalId == null || "".equals(externalId)) {
logger.error("No external Id found in the payload {}", payload);
queue.ack(Collections.singletonList(msg));
return;
}
JsonNode json = objectMapper.readTree(externalId);
String workflowId = getValue("workflowId", json);
String taskRefName = getValue("taskRefName", json);
String taskId = getValue("taskId", json);
if (workflowId == null || "".equals(workflowId)) {
// This is a bad message, we cannot process it
logger.error("No workflow id found in the message. {}", payload);
queue.ack(Collections.singletonList(msg));
return;
}
Workflow workflow = executionService.getExecutionStatus(workflowId, true);
Optional<Task> taskOptional;
if (StringUtils.isNotEmpty(taskId)) {
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskId().equals(taskId)).findFirst();
} else if (StringUtils.isEmpty(taskRefName)) {
logger.error("No taskRefName found in the message. If there is only one WAIT task, will mark it as completed. {}", payload);
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskType().equals(Wait.NAME)).findFirst();
} else {
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getReferenceTaskName().equals(taskRefName)).findFirst();
}
if (!taskOptional.isPresent()) {
logger.error("No matching tasks found to be marked as completed for workflow {}, taskRefName {}, taskId {}", workflowId, taskRefName, taskId);
queue.ack(Collections.singletonList(msg));
return;
}
Task task = taskOptional.get();
task.setStatus(status);
task.getOutputData().putAll(objectMapper.convertValue(payloadJSON, _mapType));
executionService.updateTask(task);
List<String> failures = queue.ack(Collections.singletonList(msg));
if (!failures.isEmpty()) {
logger.error("Not able to ack the messages {}", failures.toString());
}
} catch (JsonParseException e) {
logger.error("Bad message? : {} ", msg, e);
queue.ack(Collections.singletonList(msg));
} catch (ApplicationException e) {
if (e.getCode().equals(Code.NOT_FOUND)) {
logger.error("Workflow ID specified is not valid for this environment");
queue.ack(Collections.singletonList(msg));
}
logger.error("Error processing message: {}", msg, e);
} catch (Exception e) {
logger.error("Error processing message: {}", msg, e);
}
}, (Throwable t) -> {
logger.error(t.getMessage(), t);
});
logger.info("QueueListener::STARTED...listening for " + queue.getName());
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSubWorkflowTaskToDomainWildcard.
@Test
public void testSubWorkflowTaskToDomainWildcard() {
Map<String, String> taskToDomain = new HashMap<>();
taskToDomain.put("*", "unittest");
createSubWorkflow(taskToDomain);
metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
Map<String, Object> input = new HashMap<>();
input.put("param1", "param 1 value");
input.put("param3", "param 2 value");
input.put("wfName", LINEAR_WORKFLOW_T1_T2);
String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", input, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
Task task = workflowExecutionService.poll("junit_task_5", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertNotNull(workflow.getTasks());
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().get();
assertNotNull(task);
assertNotNull(task.getOutputData());
assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
assertNotNull(task.getInputData());
assertTrue(task.getInputData().containsKey("workflowInput"));
assertEquals(42, ((Map<String, Object>) task.getInputData().get("workflowInput")).get("param2"));
String subWorkflowId = task.getSubWorkflowId();
Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertNotNull(subWorkflow.getTasks());
assertEquals(workflowId, subWorkflow.getParentWorkflowId());
assertEquals(RUNNING, subWorkflow.getStatus());
task = workflowExecutionService.poll("junit_task_1", "test", "unittest");
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
task = workflowExecutionService.poll("junit_task_2", "test", "unittest");
assertEquals(subWorkflowId, task.getWorkflowInstanceId());
String uuid = UUID.randomUUID().toString();
task.getOutputData().put("uuid", uuid);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
assertNotNull(subWorkflow);
assertEquals(WorkflowStatus.COMPLETED, subWorkflow.getStatus());
assertNotNull(subWorkflow.getOutput());
assertTrue(subWorkflow.getOutput().containsKey("o1"));
assertTrue(subWorkflow.getOutput().containsKey("o2"));
assertEquals("sub workflow input param1", subWorkflow.getOutput().get("o1"));
assertEquals(uuid, subWorkflow.getOutput().get("o2"));
assertEquals(taskToDomain, subWorkflow.getTaskToDomain());
// Execute again to re-evaluate the Subworkflow task.
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
task = workflowExecutionService.poll("junit_task_6", "test");
assertNotNull(task);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
Aggregations