conductor icon indicating copy to clipboard operation
conductor copied to clipboard

Looks like a bug when using Task Domains

Open jvemugunta opened this issue 8 years ago • 4 comments

I think I am able to recreate the issue.

In the WorkflowServiceTest.java, I am failing with this test case

`@Test public void testSimpleWorkflowWithTaskSpecificDomain() throws Exception {

    clearWorkflows();
    createWorkflowDefForDomain();

    WorkflowDef found = metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2_SW, 1);
    assertNotNull(found);

    String correlationId = "unit_test_sw";
    Map<String, Object> input = new HashMap<String, Object>();
    String inputParam1 = "p1 value";
    input.put("param1", inputParam1);
    input.put("param2", "p2 value");
    Map<String, String> taskToDomain = new HashMap<String, String>();
    taskToDomain.put("junit_task_3", "domain1");
    taskToDomain.put("junit_task_2", "domain1");

    // Poll before so that a polling for this task is "active"
    // Task task = workflowExecutionService.poll("junit_task_3",
    // "task1.junit.worker", "domain1");
    // assertNull(task);
    // task = workflowExecutionService.poll("junit_task_2", "task1.junit.worker",
    // "domain1");
    // assertNull(task);

    String wfid = workflowExecutor.startWorkflow(LINEAR_WORKFLOW_T1_T2_SW, 1, correlationId, input, null,
            taskToDomain);
    System.out.println("testSimpleWorkflow.wfid=" + wfid);
    assertNotNull(wfid);
    Workflow wf = workflowExecutor.getWorkflow(wfid, false);
    assertNotNull(wf);

    Workflow es = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(es);
    assertEquals(es.getReasonForIncompletion(), WorkflowStatus.RUNNING, es.getStatus());

    es = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(es);
    assertEquals(WorkflowStatus.RUNNING, es.getStatus());
    assertEquals(1, es.getTasks().size()); // The very first task is the one that should be scheduled.

    // Check Size
    Map<String, Integer> sizes = workflowExecutionService
            .getTaskQueueSizes(Arrays.asList("domain1:junit_task_3", "junit_task_3"));
    assertEquals(sizes.get("domain1:junit_task_3").intValue(), 1);
    assertEquals(sizes.get("junit_task_3").intValue(), 0);

    // Polling for the first task should return the same task as before
    Task task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker");
    assertNull(task);
    task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker", "domain1");
    assertNotNull(task);

}`

`I have just commented the below lines in the test case and it failed

// Task task = workflowExecutionService.poll("junit_task_3", // "task1.junit.worker", "domain1"); // assertNull(task); // task = workflowExecutionService.poll("junit_task_2", "task1.junit.worker", // "domain1"); // assertNull(task); `

For domains to work, The conductor expects clients to poll the data first before the start of the workflow

It works if polling is done before the start of the wok flow as it adds the correct records in the queue_message table

select * from queue_message; +----+---------------------+---------------------+----------------------+--------------------------------------+--------+---------------------+---------+ | id | created_on | deliver_on | queue_name | message_id | popped | offset_time_seconds | payload | +----+---------------------+---------------------+----------------------+--------------------------------------+--------+---------------------+---------+ | 1 | 2018-06-21 19:49:25 | 2018-06-21 19:49:25 | domain1:junit_task_3 | 4e1224b5-7835-4bd1-a9a7-c3e439805d65 | 0 | 0 | NULL | | 2 | 2018-06-21 19:49:25 | 2018-06-21 19:49:55 | _deciderQueue | 4b0af800-5f28-4dc5-9cb1-2b27ec5b498d | 0 | 30 | NULL | +----+---------------------+---------------------+----------------------+--------------------------------------+--------+---------------------+---------+ if polling is NOT done before the start of the wok flow as it adds the incorrect records in the queue_message table

` select * from queue_message; +----+---------------------+---------------------+---------------+--------------------------------------+--------+---------------------+---------+ | id | created_on | deliver_on | queue_name | message_id | popped | offset_time_seconds | payload | +----+---------------------+---------------------+---------------+--------------------------------------+--------+---------------------+---------+ | 1 | 2018-06-21 19:42:53 | 2018-06-21 19:42:53 | junit_task_3 | 43cdd58e-156a-4b44-aaa5-28e2a68b165c | 0 | 0 | NULL | | 2 | 2018-06-21 19:42:53 | 2018-06-21 19:43:23 | _deciderQueue | b6e032f0-696a-48fa-950e-d624eb3cf2b4 | 0 | 30 | NULL | +----+---------------------+---------------------+---------------+--------------------------------------+--------+---------------------+---------+

`

jvemugunta avatar Jun 21 '18 20:06 jvemugunta

I am doing researching on how to fix the issue

jvemugunta avatar Jun 21 '18 20:06 jvemugunta

Working Scenario

This is the behavior I am seeing. I am using java client for my worker program if the workers sets a domain as a system property and is started before starting a workflow , the worker will polls for the task indefinitely and inserts/updates the poll_data table with the correct queue_name and domain name . Now, when a new workflow is started, the worker will get the task for further processing. All good

Failed Scenario

However, if we reverse the process, it won't work. In other words, If the workflow is started first followed by starting a worker , the worker never gets the task for further processing.

Worker Code ` import com.netflix.conductor.client.http.TaskClient; import com.netflix.conductor.client.task.WorkflowTaskCoordinator; import com.netflix.conductor.client.worker.Worker;

public class WorkerClient {

public static void main(String[] args) {

   System.setProperty("conductor.worker.T1.domain", "mydomain");
   
    TaskClient taskClient = new TaskClient();
    taskClient.setRootURI("http://localhost:8080/api/");

    int threadCount = 4;
    Worker worker1 = new DomainWorker("T1");
  
    WorkflowTaskCoordinator.Builder builder = new WorkflowTaskCoordinator.Builder();
    WorkflowTaskCoordinator coordinator = builder.withWorkers(worker1).withThreadCount(threadCount)
            .withTaskClient(taskClient).build();

    // Start for polling and execution of the tasks
    coordinator.init();

}

}

Start WorkFlow Code `

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' 'http://localhost:8080/api/workflow' -d ' { "name": "sample", "version": 1, "correlatonId": "corr1", "input": { "fileName": "f1" }, "taskToDomain": { "T1": "mydomain" } } '

Can someone advice if this is the expected behaviour

jvemugunta avatar Jun 22 '18 01:06 jvemugunta

Ya I also had the same observation due to how the code fetches active domains

gauravbrills avatar Aug 01 '18 03:08 gauravbrills

This must have been resolved in https://github.com/Netflix/conductor/pull/864

Please open another issue if you still have concerns.

kishorebanala avatar Feb 05 '19 01:02 kishorebanala