Search in sources :

Example 16 with TaskClient

use of com.netflix.conductor.client.http.TaskClient in project conductor by Netflix.

the class TestJettyServer method getTaskClient.

public static TaskClient getTaskClient() {
    TaskClient taskClient = new TaskClient();
    taskClient.setRootURI(API_ROOT);
    return taskClient;
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient)

Example 17 with TaskClient

use of com.netflix.conductor.client.http.TaskClient in project conductor by Netflix.

the class TaskPollExecutorTest method testLargePayloadCanFailUpdateWithRetry.

@Test
public void testLargePayloadCanFailUpdateWithRetry() {
    Task task = testTask();
    Worker worker = mock(Worker.class);
    when(worker.getPollingInterval()).thenReturn(3000);
    when(worker.getTaskDefName()).thenReturn(TEST_TASK_DEF_NAME);
    when(worker.execute(any())).thenReturn(new TaskResult(task));
    TaskClient taskClient = Mockito.mock(TaskClient.class);
    when(taskClient.pollTask(any(), any(), any())).thenReturn(task);
    when(taskClient.ack(any(), any())).thenReturn(true);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        TaskResult result = (TaskResult) args[0];
        assertNull(result.getReasonForIncompletion());
        result.setReasonForIncompletion("some_reason");
        throw new ConductorClientException();
    }).when(taskClient).evaluateAndUploadLargePayload(any(TaskResult.class), any());
    TaskPollExecutor taskPollExecutor = new TaskPollExecutor(null, taskClient, 1, 3, new HashMap<>(), "test-worker-");
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        latch.countDown();
        return null;
    }).when(worker).onErrorUpdate(any());
    Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> taskPollExecutor.pollAndExecute(worker), 0, 1, TimeUnit.SECONDS);
    Uninterruptibles.awaitUninterruptibly(latch);
    // When evaluateAndUploadLargePayload fails indefinitely, task update shouldn't be called.
    verify(taskClient, times(0)).updateTask(any());
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) Task(com.netflix.conductor.common.metadata.tasks.Task) Worker(com.netflix.conductor.client.worker.Worker) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 18 with TaskClient

use of com.netflix.conductor.client.http.TaskClient in project conductor by Netflix.

the class TaskPollExecutorTest method testTaskPollException.

@Test
public void testTaskPollException() {
    Task task = testTask();
    Worker worker = mock(Worker.class);
    when(worker.getPollingInterval()).thenReturn(3000);
    when(worker.getTaskDefName()).thenReturn("test");
    when(worker.execute(any())).thenReturn(new TaskResult(task));
    TaskClient taskClient = Mockito.mock(TaskClient.class);
    when(taskClient.pollTask(any(), any(), any())).thenThrow(ConductorClientException.class).thenReturn(task);
    TaskPollExecutor taskPollExecutor = new TaskPollExecutor(null, taskClient, 1, 1, new HashMap<>(), "test-worker-");
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        TaskResult result = (TaskResult) args[0];
        assertEquals(IN_PROGRESS, result.getStatus());
        assertEquals(task.getTaskId(), result.getTaskId());
        latch.countDown();
        return null;
    }).when(taskClient).updateTask(any());
    Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> taskPollExecutor.pollAndExecute(worker), 0, 1, TimeUnit.SECONDS);
    Uninterruptibles.awaitUninterruptibly(latch);
    verify(taskClient).updateTask(any());
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) Task(com.netflix.conductor.common.metadata.tasks.Task) Worker(com.netflix.conductor.client.worker.Worker) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) ConductorClientException(com.netflix.conductor.client.exceptions.ConductorClientException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 19 with TaskClient

use of com.netflix.conductor.client.http.TaskClient in project conductor by Netflix.

the class TaskPollExecutorTest method testTaskPollDomain.

@Test
public void testTaskPollDomain() {
    TaskClient taskClient = Mockito.mock(TaskClient.class);
    String testDomain = "foo";
    Map<String, String> taskToDomain = new HashMap<>();
    taskToDomain.put(TEST_TASK_DEF_NAME, testDomain);
    TaskPollExecutor taskPollExecutor = new TaskPollExecutor(null, taskClient, 1, 1, taskToDomain, "test-worker-");
    String workerName = "test-worker";
    Worker worker = mock(Worker.class);
    when(worker.getTaskDefName()).thenReturn(TEST_TASK_DEF_NAME);
    when(worker.getIdentity()).thenReturn(workerName);
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        latch.countDown();
        return null;
    }).when(taskClient).pollTask(TEST_TASK_DEF_NAME, workerName, testDomain);
    Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> taskPollExecutor.pollAndExecute(worker), 0, 1, TimeUnit.SECONDS);
    Uninterruptibles.awaitUninterruptibly(latch);
    verify(taskClient).pollTask(TEST_TASK_DEF_NAME, workerName, testDomain);
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) HashMap(java.util.HashMap) Worker(com.netflix.conductor.client.worker.Worker) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 20 with TaskClient

use of com.netflix.conductor.client.http.TaskClient in project conductor by Netflix.

the class Main method main.

public static void main(String[] args) {
    TaskClient taskClient = new TaskClient();
    // Point this to the server API
    taskClient.setRootURI("http://localhost:8080/api/");
    // number of threads used to execute workers.  To avoid starvation, should be same or more than number of workers
    int threadCount = 2;
    Worker worker1 = new SampleWorker("task_1");
    Worker worker2 = new SampleWorker("task_5");
    // Create TaskRunnerConfigurer
    TaskRunnerConfigurer configurer = new TaskRunnerConfigurer.Builder(taskClient, Arrays.asList(worker1, worker2)).withThreadCount(threadCount).build();
    // Start the polling and execution of tasks
    configurer.init();
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) Worker(com.netflix.conductor.client.worker.Worker) TaskRunnerConfigurer(com.netflix.conductor.client.automator.TaskRunnerConfigurer)

Aggregations

TaskClient (com.netflix.conductor.client.http.TaskClient)20 Worker (com.netflix.conductor.client.worker.Worker)16 Test (org.junit.Test)14 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)12 Task (com.netflix.conductor.common.metadata.tasks.Task)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 Injector (com.google.inject.Injector)3 BootstrapModule (com.netflix.conductor.bootstrap.BootstrapModule)3 MetadataClient (com.netflix.conductor.client.http.MetadataClient)3 WorkflowClient (com.netflix.conductor.client.http.WorkflowClient)3 EmbeddedElasticSearchProvider (com.netflix.conductor.elasticsearch.EmbeddedElasticSearchProvider)3 JettyServer (com.netflix.conductor.jetty.server.JettyServer)3 BeforeClass (org.junit.BeforeClass)3 ConductorClientException (com.netflix.conductor.client.exceptions.ConductorClientException)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)1 TaskRunnerConfigurer (com.netflix.conductor.client.automator.TaskRunnerConfigurer)1 MetricsContainer (com.netflix.conductor.client.telemetry.MetricsContainer)1 MetricsContainer.getPollTimer (com.netflix.conductor.client.telemetry.MetricsContainer.getPollTimer)1