use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class WorkflowServiceTest method testSearchWorkflows.
@Test
public void testSearchWorkflows() {
Workflow workflow = new Workflow();
workflow.setCorrelationId("c123");
WorkflowSummary workflowSummary = new WorkflowSummary(workflow);
List<WorkflowSummary> listOfWorkflowSummary = new ArrayList<WorkflowSummary>() {
{
add(workflowSummary);
}
};
SearchResult<WorkflowSummary> searchResult = new SearchResult<WorkflowSummary>(100, listOfWorkflowSummary);
when(mockExecutionService.search("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
assertEquals(searchResult, workflowService.searchWorkflows(0, 100, "asc", "*", "*"));
when(mockExecutionService.search("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
assertEquals(searchResult, workflowService.searchWorkflows(0, 100, Collections.singletonList("asc"), "*", "*"));
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class WorkflowStatusPublisherIntegrationTest method testListenerOnCompletedWorkflow.
@Test
public void testListenerOnCompletedWorkflow() throws IOException, InterruptedException {
clearWorkflows();
WorkflowDef def = new WorkflowDef();
def.setName(LINEAR_WORKFLOW_T1_T2);
def.setDescription(def.getName());
def.setVersion(WORKFLOW_VERSION);
def.setSchemaVersion(2);
def.setWorkflowStatusListenerEnabled(true);
LinkedList<WorkflowTask> wftasks = new LinkedList<>();
WorkflowTask wft1 = new WorkflowTask();
wft1.setName("junit_task_1");
wft1.setTaskReferenceName("t1");
wftasks.add(wft1);
def.setTasks(wftasks);
metadataService.updateWorkflowDef(Collections.singletonList(def));
String id = startOrLoadWorkflowExecution(def.getName(), 1, "testWorkflowCompletedListener", new HashMap<>(), null, null);
List<Task> tasks = workflowExecutionService.getTasks("junit_task_1", null, 1);
tasks.get(0).setStatus(COMPLETED);
workflowExecutionService.updateTask(tasks.get(0));
checkIfWorkflowIsCompleted(id);
List<Message> callbackMessages = queueDAO.pollMessages(CALLBACK_QUEUE, 1, 200);
queueDAO.ack(CALLBACK_QUEUE, callbackMessages.get(0).getId());
WorkflowSummary payload = mapper.readValue(callbackMessages.get(0).getPayload(), WorkflowSummary.class);
assertEquals(id, callbackMessages.get(0).getId());
assertEquals(LINEAR_WORKFLOW_T1_T2, payload.getWorkflowType());
assertEquals("testWorkflowCompletedListener", payload.getCorrelationId());
assertEquals(Workflow.WorkflowStatus.COMPLETED, payload.getStatus());
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class AbstractHttpEndToEndTest method testAll.
@Test
public void testAll() throws Exception {
createAndRegisterTaskDefinitions("t", 5);
WorkflowDef def = new WorkflowDef();
def.setName("test");
def.setOwnerEmail(DEFAULT_EMAIL_ADDRESS);
WorkflowTask t0 = new WorkflowTask();
t0.setName("t0");
t0.setWorkflowTaskType(TaskType.SIMPLE);
t0.setTaskReferenceName("t0");
WorkflowTask t1 = new WorkflowTask();
t1.setName("t1");
t1.setWorkflowTaskType(TaskType.SIMPLE);
t1.setTaskReferenceName("t1");
def.getTasks().add(t0);
def.getTasks().add(t1);
metadataClient.registerWorkflowDef(def);
WorkflowDef workflowDefinitionFromSystem = metadataClient.getWorkflowDef(def.getName(), null);
assertNotNull(workflowDefinitionFromSystem);
assertEquals(def, workflowDefinitionFromSystem);
String correlationId = "test_corr_id";
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(def.getName()).withCorrelationId(correlationId).withPriority(50).withInput(new HashMap<>());
String workflowId = workflowClient.startWorkflow(startWorkflowRequest);
assertNotNull(workflowId);
Workflow workflow = workflowClient.getWorkflow(workflowId, false);
assertEquals(0, workflow.getTasks().size());
assertEquals(workflowId, workflow.getWorkflowId());
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
List<Workflow> workflowList = workflowClient.getWorkflows(def.getName(), correlationId, false, false);
assertEquals(1, workflowList.size());
assertEquals(workflowId, workflowList.get(0).getWorkflowId());
});
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(1, workflow.getTasks().size());
assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
assertEquals(workflowId, workflow.getWorkflowId());
int queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(0).getTaskType());
assertEquals(1, queueSize);
List<String> runningIds = workflowClient.getRunningWorkflow(def.getName(), def.getVersion());
assertNotNull(runningIds);
assertEquals(1, runningIds.size());
assertEquals(workflowId, runningIds.get(0));
List<Task> polled = taskClient.batchPollTasksByTaskType("non existing task", "test", 1, 100);
assertNotNull(polled);
assertEquals(0, polled.size());
polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
assertNotNull(polled);
assertEquals(1, polled.size());
assertEquals(t0.getName(), polled.get(0).getTaskDefName());
Task task = polled.get(0);
Boolean acked = taskClient.ack(task.getTaskId(), "test");
assertNotNull(acked);
assertTrue(acked);
task.getOutputData().put("key1", "value1");
task.setStatus(Status.COMPLETED);
taskClient.updateTask(new TaskResult(task));
polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
assertNotNull(polled);
assertTrue(polled.toString(), polled.isEmpty());
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(2, workflow.getTasks().size());
assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
assertEquals(t1.getTaskReferenceName(), workflow.getTasks().get(1).getReferenceTaskName());
assertEquals(Task.Status.COMPLETED, workflow.getTasks().get(0).getStatus());
assertEquals(Task.Status.SCHEDULED, workflow.getTasks().get(1).getStatus());
Task taskById = taskClient.getTaskDetails(task.getTaskId());
assertNotNull(taskById);
assertEquals(task.getTaskId(), taskById.getTaskId());
queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(1).getTaskType());
assertEquals(1, queueSize);
List<Task> getTasks = taskClient.getPendingTasksByType(t0.getName(), null, 1);
assertNotNull(getTasks);
// getTasks only gives pending tasks
assertEquals(0, getTasks.size());
getTasks = taskClient.getPendingTasksByType(t1.getName(), null, 1);
assertNotNull(getTasks);
assertEquals(1, getTasks.size());
Task pending = taskClient.getPendingTaskForWorkflow(workflowId, t1.getTaskReferenceName());
assertNotNull(pending);
assertEquals(t1.getTaskReferenceName(), pending.getReferenceTaskName());
assertEquals(workflowId, pending.getWorkflowInstanceId());
Thread.sleep(1000);
SearchResult<WorkflowSummary> searchResult = workflowClient.search("workflowType='" + def.getName() + "'");
assertNotNull(searchResult);
assertEquals(1, searchResult.getTotalHits());
assertEquals(workflow.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
assertNotNull(searchResultV2);
assertEquals(1, searchResultV2.getTotalHits());
assertEquals(workflow.getWorkflowId(), searchResultV2.getResults().get(0).getWorkflowId());
SearchResult<WorkflowSummary> searchResultAdvanced = workflowClient.search(0, 1, null, null, "workflowType='" + def.getName() + "'");
assertNotNull(searchResultAdvanced);
assertEquals(1, searchResultAdvanced.getTotalHits());
assertEquals(workflow.getWorkflowId(), searchResultAdvanced.getResults().get(0).getWorkflowId());
SearchResult<Workflow> searchResultV2Advanced = workflowClient.searchV2(0, 1, null, null, "workflowType='" + def.getName() + "'");
assertNotNull(searchResultV2Advanced);
assertEquals(1, searchResultV2Advanced.getTotalHits());
assertEquals(workflow.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
workflowClient.terminateWorkflow(workflowId, "terminate reason");
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.TERMINATED, workflow.getStatus());
workflowClient.restart(workflowId, false);
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(1, workflow.getTasks().size());
workflowClient.skipTaskFromWorkflow(workflowId, "t1");
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class ExecutionService method searchWorkflowByTasks.
public SearchResult<WorkflowSummary> searchWorkflowByTasks(String query, String freeText, int start, int size, List<String> sortOptions) {
SearchResult<TaskSummary> taskSummarySearchResult = searchTasks(query, freeText, start, size, sortOptions);
List<WorkflowSummary> workflowSummaries = taskSummarySearchResult.getResults().stream().parallel().map(taskSummary -> {
try {
String workflowId = taskSummary.getWorkflowId();
return new WorkflowSummary(executionDAOFacade.getWorkflowById(workflowId, false));
} catch (Exception e) {
logger.error("Error fetching workflow by id: {}", taskSummary.getWorkflowId(), e);
return null;
}
}).filter(Objects::nonNull).distinct().collect(Collectors.toList());
int missing = taskSummarySearchResult.getResults().size() - workflowSummaries.size();
long totalHits = taskSummarySearchResult.getTotalHits() - missing;
return new SearchResult<>(totalHits, workflowSummaries);
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class WorkflowServiceTest method testSearchWorkflowsByTasks.
@Test
public void testSearchWorkflowsByTasks() {
Workflow workflow = new Workflow();
workflow.setCorrelationId("c123");
WorkflowSummary workflowSummary = new WorkflowSummary(workflow);
List<WorkflowSummary> listOfWorkflowSummary = new ArrayList<WorkflowSummary>() {
{
add(workflowSummary);
}
};
SearchResult<WorkflowSummary> searchResult = new SearchResult<>(100, listOfWorkflowSummary);
when(mockExecutionService.searchWorkflowByTasks("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
assertEquals(searchResult, workflowService.searchWorkflowsByTasks(0, 100, "asc", "*", "*"));
when(mockExecutionService.searchWorkflowByTasks("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
assertEquals(searchResult, workflowService.searchWorkflowsByTasks(0, 100, Collections.singletonList("asc"), "*", "*"));
}
Aggregations