Search in sources :

Example 6 with LoggingContext

use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.

the class Worker method stopTask.

private void stopTask(ConnectorTaskId taskId) {
    try (LoggingContext loggingContext = LoggingContext.forTask(taskId)) {
        WorkerTask task = tasks.get(taskId);
        if (task == null) {
            log.warn("Ignoring stop request for unowned task {}", taskId);
            return;
        }
        log.info("Stopping task {}", task.id());
        if (task instanceof WorkerSourceTask)
            sourceTaskOffsetCommitter.remove(task.id());
        ClassLoader savedLoader = plugins.currentThreadLoader();
        try {
            savedLoader = Plugins.compareAndSwapLoaders(task.loader());
            task.stop();
        } finally {
            Plugins.compareAndSwapLoaders(savedLoader);
        }
    }
}
Also used : LoggingContext(org.apache.kafka.connect.util.LoggingContext)

Example 7 with LoggingContext

use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.

the class WorkerTask method run.

@Override
public void run() {
    // Clear all MDC parameters, in case this thread is being reused
    LoggingContext.clear();
    try (LoggingContext loggingContext = LoggingContext.forTask(id())) {
        ClassLoader savedLoader = Plugins.compareAndSwapLoaders(loader);
        String savedName = Thread.currentThread().getName();
        try {
            Thread.currentThread().setName(THREAD_NAME_PREFIX + id);
            doRun();
            onShutdown();
        } catch (Throwable t) {
            onFailure(t);
            if (t instanceof Error)
                throw (Error) t;
        } finally {
            Thread.currentThread().setName(savedName);
            Plugins.compareAndSwapLoaders(savedLoader);
            shutdownLatch.countDown();
        }
    }
}
Also used : LoggingContext(org.apache.kafka.connect.util.LoggingContext)

Example 8 with LoggingContext

use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.

the class Worker method stopConnector.

/**
 * Stop a connector managed by this worker.
 *
 * @param connName the connector name.
 */
private void stopConnector(String connName) {
    try (LoggingContext loggingContext = LoggingContext.forConnector(connName)) {
        WorkerConnector workerConnector = connectors.get(connName);
        log.info("Stopping connector {}", connName);
        if (workerConnector == null) {
            log.warn("Ignoring stop request for unowned connector {}", connName);
            return;
        }
        ClassLoader savedLoader = plugins.currentThreadLoader();
        try {
            savedLoader = Plugins.compareAndSwapLoaders(workerConnector.loader());
            workerConnector.shutdown();
        } finally {
            Plugins.compareAndSwapLoaders(savedLoader);
        }
    }
}
Also used : LoggingContext(org.apache.kafka.connect.util.LoggingContext)

Example 9 with LoggingContext

use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.

the class WorkerConnector method run.

@Override
public void run() {
    // Clear all MDC parameters, in case this thread is being reused
    LoggingContext.clear();
    try (LoggingContext loggingContext = LoggingContext.forConnector(connName)) {
        ClassLoader savedLoader = Plugins.compareAndSwapLoaders(loader);
        String savedName = Thread.currentThread().getName();
        try {
            Thread.currentThread().setName(THREAD_NAME_PREFIX + connName);
            doRun();
        } finally {
            Thread.currentThread().setName(savedName);
            Plugins.compareAndSwapLoaders(savedLoader);
        }
    } finally {
        // In the rare case of an exception being thrown outside the doRun() method, or an
        // uncaught one being thrown from within it, mark the connector as shut down to avoid
        // unnecessarily blocking and eventually timing out during awaitShutdown
        shutdownLatch.countDown();
    }
}
Also used : LoggingContext(org.apache.kafka.connect.util.LoggingContext)

Example 10 with LoggingContext

use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.

the class SourceTaskOffsetCommitter method schedule.

public void schedule(final ConnectorTaskId id, final WorkerSourceTask workerTask) {
    long commitIntervalMs = config.getLong(WorkerConfig.OFFSET_COMMIT_INTERVAL_MS_CONFIG);
    ScheduledFuture<?> commitFuture = commitExecutorService.scheduleWithFixedDelay(() -> {
        try (LoggingContext loggingContext = LoggingContext.forOffsets(id)) {
            commit(workerTask);
        }
    }, commitIntervalMs, commitIntervalMs, TimeUnit.MILLISECONDS);
    committers.put(id, commitFuture);
}
Also used : LoggingContext(org.apache.kafka.connect.util.LoggingContext)

Aggregations

LoggingContext (org.apache.kafka.connect.util.LoggingContext)10 ConnectException (org.apache.kafka.connect.errors.ConnectException)3 Connector (org.apache.kafka.connect.connector.Connector)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Task (org.apache.kafka.connect.connector.Task)1 JsonConverter (org.apache.kafka.connect.json.JsonConverter)1 SinkTask (org.apache.kafka.connect.sink.SinkTask)1 SourceTask (org.apache.kafka.connect.source.SourceTask)1 CloseableOffsetStorageReader (org.apache.kafka.connect.storage.CloseableOffsetStorageReader)1 Converter (org.apache.kafka.connect.storage.Converter)1 HeaderConverter (org.apache.kafka.connect.storage.HeaderConverter)1 OffsetStorageReader (org.apache.kafka.connect.storage.OffsetStorageReader)1 OffsetStorageReaderImpl (org.apache.kafka.connect.storage.OffsetStorageReaderImpl)1