Search in sources :

Example 11 with TaskClient

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

the class WorkflowTaskCoordinatorTests method testTaskException.

@Test
public void testTaskException() {
    Worker worker = Worker.create("test", task -> {
        throw new NoSuchMethodError();
    });
    TaskClient client = Mockito.mock(TaskClient.class);
    WorkflowTaskCoordinator coordinator = new WorkflowTaskCoordinator.Builder().withWorkers(worker).withThreadCount(1).withWorkerQueueSize(1).withSleepWhenRetry(100000).withUpdateRetryCount(1).withTaskClient(client).withWorkerNamePrefix("test-worker-").build();
    when(client.batchPollTasksInDomain(anyString(), isNull(), anyString(), anyInt(), anyInt())).thenReturn(ImmutableList.of(new Task()));
    when(client.ack(any(), any())).thenReturn(true);
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        assertEquals("test-worker-0", Thread.currentThread().getName());
        Object[] args = invocation.getArguments();
        TaskResult result = (TaskResult) args[0];
        assertEquals(TaskResult.Status.FAILED, result.getStatus());
        latch.countDown();
        return null;
    }).when(client).updateTask(any());
    coordinator.init();
    Uninterruptibles.awaitUninterruptibly(latch);
    Mockito.verify(client).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) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with TaskClient

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

the class WorkflowTaskCoordinator method init.

/**
 * Starts the polling.
 * Must be called after the constructor {@link #WorkflowTaskCoordinator(EurekaClient, TaskClient, int, int, int, int, Iterable, String)}
 * or the builder {@link Builder#build()} method
 */
public synchronized void init() {
    if (threadCount == -1) {
        threadCount = workers.size();
    }
    logger.info("Initialized the worker with {} threads", threadCount);
    MetricsContainer.incrementInitializationCount(this.getClass().getCanonicalName());
    this.workerQueue = new LinkedBlockingQueue<Runnable>(workerQueueSize);
    AtomicInteger count = new AtomicInteger(0);
    this.executorService = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, workerQueue, (runnable) -> {
        Thread thread = new Thread(runnable);
        thread.setName(workerNamePrefix + count.getAndIncrement());
        return thread;
    });
    this.scheduledExecutorService = Executors.newScheduledThreadPool(workers.size());
    workers.forEach(worker -> {
        scheduledExecutorService.scheduleWithFixedDelay(() -> pollForTask(worker), worker.getPollingInterval(), worker.getPollingInterval(), TimeUnit.MILLISECONDS);
    });
}
Also used : Arrays(java.util.Arrays) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LoggerFactory(org.slf4j.LoggerFactory) MetricsContainer(com.netflix.conductor.client.telemetry.MetricsContainer) PropertyFactory(com.netflix.conductor.client.worker.PropertyFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EurekaClient(com.netflix.discovery.EurekaClient) InstanceStatus(com.netflix.appinfo.InstanceInfo.InstanceStatus) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) PrintWriter(java.io.PrintWriter) TaskClient(com.netflix.conductor.client.http.TaskClient) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) Worker(com.netflix.conductor.client.worker.Worker) StringWriter(java.io.StringWriter) MetricsContainer.getPollTimer(com.netflix.conductor.client.telemetry.MetricsContainer.getPollTimer) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Optional(java.util.Optional) MetricsContainer.incrementTaskPollCount(com.netflix.conductor.client.telemetry.MetricsContainer.incrementTaskPollCount) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 13 with TaskClient

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

the class ExclusiveJoinEndToEndTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    TestEnvironment.setup();
    System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9205");
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "localhost:9305");
    System.setProperty(Configuration.EXECUTION_LOCK_ENABLED_PROPERTY_NAME, "false");
    Injector bootInjector = Guice.createInjector(new BootstrapModule());
    Injector serverInjector = Guice.createInjector(bootInjector.getInstance(ModulesProvider.class).get());
    search = serverInjector.getInstance(EmbeddedElasticSearchProvider.class).get().get();
    search.start();
    JettyServer server = new JettyServer(SERVER_PORT, false);
    server.start();
    String apiRoot = String.format("http://localhost:%d/api/", SERVER_PORT);
    taskClient = new TaskClient();
    taskClient.setRootURI(apiRoot);
    workflowClient = new WorkflowClient();
    workflowClient.setRootURI(apiRoot);
    metadataClient = new MetadataClient();
    metadataClient.setRootURI(apiRoot);
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) MetadataClient(com.netflix.conductor.client.http.MetadataClient) Injector(com.google.inject.Injector) JettyServer(com.netflix.conductor.jetty.server.JettyServer) WorkflowClient(com.netflix.conductor.client.http.WorkflowClient) EmbeddedElasticSearchProvider(com.netflix.conductor.elasticsearch.EmbeddedElasticSearchProvider) BootstrapModule(com.netflix.conductor.bootstrap.BootstrapModule) BeforeClass(org.junit.BeforeClass)

Example 14 with TaskClient

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

the class ESRestClientHttpEndToEndTest method setup.

@BeforeClass
public static void setup() throws Exception {
    TestEnvironment.setup();
    System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9203");
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "http://localhost:9203");
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_INDEX_BATCH_SIZE_PROPERTY_NAME, "1");
    Injector bootInjector = Guice.createInjector(new BootstrapModule());
    Injector serverInjector = Guice.createInjector(bootInjector.getInstance(ModulesProvider.class).get());
    search = serverInjector.getInstance(EmbeddedElasticSearchProvider.class).get().get();
    search.start();
    search.waitForGreenCluster();
    SystemPropertiesElasticSearchConfiguration configuration = new SystemPropertiesElasticSearchConfiguration();
    ElasticSearchRestClientProvider restClientProvider = new ElasticSearchRestClientProvider(configuration);
    elasticSearchAdminClient = restClientProvider.get();
    JettyServer server = new JettyServer(SERVER_PORT, false);
    server.start();
    apiRoot = String.format("http://localhost:%d/api/", SERVER_PORT);
    taskClient = new TaskClient();
    taskClient.setRootURI(apiRoot);
    workflowClient = new WorkflowClient();
    workflowClient.setRootURI(apiRoot);
    metadataClient = new MetadataClient();
    metadataClient.setRootURI(apiRoot);
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) MetadataClient(com.netflix.conductor.client.http.MetadataClient) Injector(com.google.inject.Injector) SystemPropertiesElasticSearchConfiguration(com.netflix.conductor.elasticsearch.SystemPropertiesElasticSearchConfiguration) JettyServer(com.netflix.conductor.jetty.server.JettyServer) WorkflowClient(com.netflix.conductor.client.http.WorkflowClient) EmbeddedElasticSearchProvider(com.netflix.conductor.elasticsearch.EmbeddedElasticSearchProvider) BootstrapModule(com.netflix.conductor.bootstrap.BootstrapModule) ElasticSearchRestClientProvider(com.netflix.conductor.elasticsearch.ElasticSearchRestClientProvider) BeforeClass(org.junit.BeforeClass)

Example 15 with TaskClient

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

the class HttpEndToEndTest method setup.

@BeforeClass
public static void setup() throws Exception {
    TestEnvironment.setup();
    System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9201");
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "localhost:9301");
    System.setProperty(Configuration.EXECUTION_LOCK_ENABLED_PROPERTY_NAME, "false");
    Injector bootInjector = Guice.createInjector(new BootstrapModule());
    Injector serverInjector = Guice.createInjector(bootInjector.getInstance(ModulesProvider.class).get());
    search = serverInjector.getInstance(EmbeddedElasticSearchProvider.class).get().get();
    search.start();
    JettyServer server = new JettyServer(SERVER_PORT, false);
    server.start();
    apiRoot = String.format("http://localhost:%d/api/", SERVER_PORT);
    taskClient = new TaskClient();
    taskClient.setRootURI(apiRoot);
    workflowClient = new WorkflowClient();
    workflowClient.setRootURI(apiRoot);
    metadataClient = new MetadataClient();
    metadataClient.setRootURI(apiRoot);
}
Also used : TaskClient(com.netflix.conductor.client.http.TaskClient) MetadataClient(com.netflix.conductor.client.http.MetadataClient) Injector(com.google.inject.Injector) JettyServer(com.netflix.conductor.jetty.server.JettyServer) WorkflowClient(com.netflix.conductor.client.http.WorkflowClient) EmbeddedElasticSearchProvider(com.netflix.conductor.elasticsearch.EmbeddedElasticSearchProvider) BootstrapModule(com.netflix.conductor.bootstrap.BootstrapModule) BeforeClass(org.junit.BeforeClass)

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