use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class TestElasticSearchRestDAOV7 method shouldIndexWorkflowAsync.
@Test
public void shouldIndexWorkflowAsync() throws Exception {
Workflow workflow = TestUtils.loadWorkflowSnapshot("workflow");
WorkflowSummary summary = new WorkflowSummary(workflow);
indexDAO.asyncIndexWorkflow(workflow).get();
assertWorkflowSummary(workflow.getWorkflowId(), summary);
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class AbstractGrpcEndToEndTest method testAll.
@Test
public void testAll() throws Exception {
assertNotNull(taskClient);
List<TaskDef> defs = new LinkedList<>();
for (int i = 0; i < 5; i++) {
TaskDef def = new TaskDef("t" + i, "task " + i, DEFAULT_EMAIL_ADDRESS, 3, 60, 60);
def.setTimeoutPolicy(TimeoutPolicy.RETRY);
defs.add(def);
}
metadataClient.registerTaskDefs(defs);
for (int i = 0; i < 5; i++) {
final String taskName = "t" + i;
TaskDef def = metadataClient.getTaskDef(taskName);
assertNotNull(def);
assertEquals(taskName, def.getName());
}
WorkflowDef def = createWorkflowDefinition("test");
WorkflowTask t0 = createWorkflowTask("t0");
WorkflowTask t1 = createWorkflowTask("t1");
def.getTasks().add(t0);
def.getTasks().add(t1);
metadataClient.registerWorkflowDef(def);
WorkflowDef found = metadataClient.getWorkflowDef(def.getName(), null);
assertNotNull(found);
assertEquals(def, found);
String correlationId = "test_corr_id";
StartWorkflowRequest startWf = new StartWorkflowRequest();
startWf.setName(def.getName());
startWf.setCorrelationId(correlationId);
String workflowId = workflowClient.startWorkflow(startWf);
assertNotNull(workflowId);
System.out.println("Started workflow id=" + workflowId);
Workflow wf = workflowClient.getWorkflow(workflowId, false);
assertEquals(0, wf.getTasks().size());
assertEquals(workflowId, wf.getWorkflowId());
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
assertEquals(1, wf.getTasks().size());
assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
assertEquals(workflowId, wf.getWorkflowId());
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());
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
assertEquals(2, wf.getTasks().size());
assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
assertEquals(t1.getTaskReferenceName(), wf.getTasks().get(1).getReferenceTaskName());
assertEquals(Status.COMPLETED, wf.getTasks().get(0).getStatus());
assertEquals(Status.SCHEDULED, wf.getTasks().get(1).getStatus());
Task taskById = taskClient.getTaskDetails(task.getTaskId());
assertNotNull(taskById);
assertEquals(task.getTaskId(), taskById.getTaskId());
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(wf.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
assertNotNull(searchResultV2);
assertEquals(1, searchResultV2.getTotalHits());
assertEquals(wf.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(wf.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(wf.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
workflowClient.terminateWorkflow(workflowId, "terminate reason");
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.TERMINATED, wf.getStatus());
workflowClient.restart(workflowId, false);
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
assertEquals(1, wf.getTasks().size());
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class WorkflowStatusPublisherIntegrationTest method testListenerOnTerminatedWorkflow.
@Test
public void testListenerOnTerminatedWorkflow() throws IOException {
String id = startOrLoadWorkflowExecution(LINEAR_WORKFLOW_T1_T2, 1, "testWorkflowTerminatedListener", new HashMap<>(), null, null);
workflowExecutor.terminateWorkflow(id, INCOMPLETION_REASON);
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("testWorkflowTerminatedListener", payload.getCorrelationId());
assertEquals(Workflow.WorkflowStatus.TERMINATED, payload.getStatus());
assertEquals(INCOMPLETION_REASON, payload.getReasonForIncompletion());
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class WorkflowClientTest method testSearchWithParams.
@Test
public void testSearchWithParams() {
ClientResponse clientResponse = mock(ClientResponse.class);
SearchResult<WorkflowSummary> workflowSearchResult = new SearchResult<>();
workflowSearchResult.setTotalHits(1);
WorkflowSummary workflowSummary = new WorkflowSummary(new Workflow());
workflowSearchResult.setResults(Collections.singletonList(workflowSummary));
when(clientResponse.getEntity(argThat((GenericType<SearchResult<WorkflowSummary>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(WorkflowSummary.class)))).thenReturn(workflowSearchResult);
when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search?start=0&size=10&sort=sort&freeText=text&query=my_complex_query"))))).thenReturn(clientResponse);
SearchResult<WorkflowSummary> searchResult = workflowClient.search(0, 10, "sort", "text", "my_complex_query");
assertEquals(1, searchResult.getTotalHits());
assertEquals(Collections.singletonList(workflowSummary), searchResult.getResults());
}
use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.
the class DynoQueueStatusPublisher method workflowToMessage.
private Message workflowToMessage(Workflow workflow) {
String jsonWfSummary;
WorkflowSummary summary = new WorkflowSummary(workflow);
try {
jsonWfSummary = objectMapper.writeValueAsString(summary);
} catch (JsonProcessingException e) {
LOGGER.error("Failed to convert WorkflowSummary: {} to String. Exception: {}", summary, e);
throw new RuntimeException(e);
}
return new Message(workflow.getWorkflowId(), jsonWfSummary, null);
}
Aggregations