Search in sources :

Example 61 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class DistributedHerder method taskConfigs.

@Override
public void taskConfigs(final String connName, final Callback<List<TaskInfo>> callback) {
    log.trace("Submitting get task configuration request {}", connName);
    addRequest(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (checkRebalanceNeeded(callback))
                return null;
            if (!configState.contains(connName)) {
                callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), null);
            } else {
                List<TaskInfo> result = new ArrayList<>();
                for (int i = 0; i < configState.taskCount(connName); i++) {
                    ConnectorTaskId id = new ConnectorTaskId(connName, i);
                    result.add(new TaskInfo(id, configState.taskConfig(id)));
                }
                callback.onCompletion(null, result);
            }
            return null;
        }
    }, forwardErrorCallback(callback));
}
Also used : TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) WakeupException(org.apache.kafka.common.errors.WakeupException) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) NoSuchElementException(java.util.NoSuchElementException) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 62 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class DistributedHerder method halt.

// public for testing
public void halt() {
    synchronized (this) {
        // Clean up any connectors and tasks that are still running.
        log.info("Stopping connectors and tasks that are still assigned to this worker.");
        List<Callable<Void>> callables = new ArrayList<>();
        for (String connectorName : new ArrayList<>(worker.connectorNames())) {
            callables.add(getConnectorStoppingCallable(connectorName));
        }
        for (ConnectorTaskId taskId : new ArrayList<>(worker.taskIds())) {
            callables.add(getTaskStoppingCallable(taskId));
        }
        startAndStop(callables);
        member.stop();
        // Explicitly fail any outstanding requests so they actually get a response and get an
        // understandable reason for their failure.
        HerderRequest request = requests.pollFirst();
        while (request != null) {
            request.callback().onCompletion(new ConnectException("Worker is shutting down"), null);
            request = requests.pollFirst();
        }
        stopServices();
    }
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 63 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class DistributedHerder method startWork.

private void startWork() {
    // Start assigned connectors and tasks
    log.info("Starting connectors and tasks using config offset {}", assignment.offset());
    List<Callable<Void>> callables = new ArrayList<>();
    for (String connectorName : assignment.connectors()) {
        callables.add(getConnectorStartingCallable(connectorName));
    }
    for (ConnectorTaskId taskId : assignment.tasks()) {
        callables.add(getTaskStartingCallable(taskId));
    }
    startAndStop(callables);
    log.info("Finished starting connectors and tasks");
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable)

Example 64 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResource method restartTask.

@POST
@Path("/{connector}/tasks/{task}/restart")
public void restartTask(@PathParam("connector") final String connector, @PathParam("task") final Integer task, @QueryParam("forward") final Boolean forward) throws Throwable {
    FutureCallback<Void> cb = new FutureCallback<>();
    ConnectorTaskId taskId = new ConnectorTaskId(connector, task);
    herder.restartTask(taskId, cb);
    completeOrForwardRequest(cb, "/connectors/" + connector + "/tasks/" + task + "/restart", "POST", null, forward);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 65 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class MemoryConfigBackingStore method taskConfigListAsMap.

private static Map<ConnectorTaskId, Map<String, String>> taskConfigListAsMap(String connector, List<Map<String, String>> configs) {
    int index = 0;
    Map<ConnectorTaskId, Map<String, String>> result = new TreeMap<>();
    for (Map<String, String> taskConfigMap : configs) {
        result.put(new ConnectorTaskId(connector, index++), taskConfigMap);
    }
    return result;
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)111 Test (org.junit.Test)59 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)45 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 Map (java.util.Map)18 FutureCallback (org.apache.kafka.connect.util.FutureCallback)16 ConnectException (org.apache.kafka.connect.errors.ConnectException)15 Callback (org.apache.kafka.connect.util.Callback)15 Connector (org.apache.kafka.connect.connector.Connector)13 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)12 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)12 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)12 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)11 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)11 SourceConnector (org.apache.kafka.connect.source.SourceConnector)11 Herder (org.apache.kafka.connect.runtime.Herder)10 List (java.util.List)9 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)9 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)8