Search in sources :

Example 6 with TaskSpec

use of org.apache.kafka.trogdor.task.TaskSpec in project kafka by apache.

the class WorkerManager method createWorker.

public KafkaFuture<String> createWorker(long workerId, String taskId, TaskSpec spec) throws Throwable {
    try (ShutdownManager.Reference ref = shutdownManager.takeReference()) {
        final Worker worker = stateChangeExecutor.submit(new CreateWorker(workerId, taskId, spec, time.milliseconds())).get();
        if (worker.doneFuture != null) {
            log.info("{}: Ignoring request to create worker {}, because there is already " + "a worker with that id.", nodeName, workerId);
            return worker.doneFuture;
        }
        worker.doneFuture = new KafkaFutureImpl<>();
        if (worker.spec.endMs() <= time.milliseconds()) {
            log.info("{}: Will not run worker {} as it has expired.", nodeName, worker);
            stateChangeExecutor.submit(new HandleWorkerHalting(worker, "worker expired", true));
            return worker.doneFuture;
        }
        KafkaFutureImpl<String> haltFuture = new KafkaFutureImpl<>();
        haltFuture.thenApply((KafkaFuture.BaseFunction<String, Void>) errorString -> {
            if (errorString == null)
                errorString = "";
            if (errorString.isEmpty()) {
                log.info("{}: Worker {} is halting.", nodeName, worker);
            } else {
                log.info("{}: Worker {} is halting with error {}", nodeName, worker, errorString);
            }
            stateChangeExecutor.submit(new HandleWorkerHalting(worker, errorString, false));
            return null;
        });
        try {
            worker.taskWorker.start(platform, worker.status, haltFuture);
        } catch (Exception e) {
            log.info("{}: Worker {} start() exception", nodeName, worker, e);
            stateChangeExecutor.submit(new HandleWorkerHalting(worker, "worker.start() exception: " + Utils.stackTrace(e), true));
        }
        stateChangeExecutor.submit(new FinishCreatingWorker(worker));
        return worker.doneFuture;
    } catch (ExecutionException e) {
        if (e.getCause() instanceof RequestConflictException) {
            log.info("{}: request conflict while creating worker {} for task {} with spec {}.", nodeName, workerId, taskId, spec);
        } else {
            log.info("{}: Error creating worker {} for task {} with spec {}", nodeName, workerId, taskId, spec, e);
        }
        throw e.getCause();
    }
}
Also used : WorkerState(org.apache.kafka.trogdor.rest.WorkerState) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) LoggerFactory(org.slf4j.LoggerFactory) KafkaException(org.apache.kafka.common.KafkaException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Platform(org.apache.kafka.trogdor.common.Platform) AgentWorkerStatusTracker(org.apache.kafka.trogdor.task.AgentWorkerStatusTracker) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Scheduler(org.apache.kafka.common.utils.Scheduler) ThreadUtils(org.apache.kafka.common.utils.ThreadUtils) ExecutorService(java.util.concurrent.ExecutorService) Utils(org.apache.kafka.common.utils.Utils) Logger(org.slf4j.Logger) Time(org.apache.kafka.common.utils.Time) KafkaFuture(org.apache.kafka.common.KafkaFuture) TaskSpec(org.apache.kafka.trogdor.task.TaskSpec) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) WorkerStarting(org.apache.kafka.trogdor.rest.WorkerStarting) TreeMap(java.util.TreeMap) RequestConflictException(org.apache.kafka.trogdor.rest.RequestConflictException) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerStopping(org.apache.kafka.trogdor.rest.WorkerStopping) TaskWorker(org.apache.kafka.trogdor.task.TaskWorker) KafkaFuture(org.apache.kafka.common.KafkaFuture) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) KafkaException(org.apache.kafka.common.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) RequestConflictException(org.apache.kafka.trogdor.rest.RequestConflictException) RequestConflictException(org.apache.kafka.trogdor.rest.RequestConflictException) TaskWorker(org.apache.kafka.trogdor.task.TaskWorker) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

TaskSpec (org.apache.kafka.trogdor.task.TaskSpec)6 ArrayList (java.util.ArrayList)3 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)3 Namespace (net.sourceforge.argparse4j.inf.Namespace)3 ZoneOffset (java.time.ZoneOffset)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 Subparser (net.sourceforge.argparse4j.inf.Subparser)2 Subparsers (net.sourceforge.argparse4j.inf.Subparsers)2 Platform (org.apache.kafka.trogdor.common.Platform)2 StringFormatter.dateString (org.apache.kafka.trogdor.common.StringFormatter.dateString)2 StringFormatter.durationString (org.apache.kafka.trogdor.common.StringFormatter.durationString)2 RequestConflictException (org.apache.kafka.trogdor.rest.RequestConflictException)2 UptimeResponse (org.apache.kafka.trogdor.rest.UptimeResponse)2 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)2 SampleTaskSpec (org.apache.kafka.trogdor.task.SampleTaskSpec)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1