Search in sources :

Example 21 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException 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 22 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class DistributedHerder method restartConnector.

@Override
public void restartConnector(final String connName, final Callback<Void> callback) {
    addRequest(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (checkRebalanceNeeded(callback))
                return null;
            if (!configState.connectors().contains(connName)) {
                callback.onCompletion(new NotFoundException("Unknown connector: " + connName), null);
                return null;
            }
            if (assignment.connectors().contains(connName)) {
                try {
                    worker.stopConnector(connName);
                    if (startConnector(connName))
                        callback.onCompletion(null, null);
                    else
                        callback.onCompletion(new ConnectException("Failed to start connector: " + connName), null);
                } catch (Throwable t) {
                    callback.onCompletion(t, null);
                }
            } else if (isLeader()) {
                callback.onCompletion(new NotAssignedException("Cannot restart connector since it is not assigned to this member", member.ownerUrl(connName)), null);
            } else {
                callback.onCompletion(new NotLeaderException("Cannot restart connector since it is not assigned to this member", leaderUrl()), null);
            }
            return null;
        }
    }, forwardErrorCallback(callback));
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException) 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) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 23 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class DistributedHerder method restartTask.

@Override
public void restartTask(final ConnectorTaskId id, final Callback<Void> callback) {
    addRequest(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (checkRebalanceNeeded(callback))
                return null;
            if (!configState.connectors().contains(id.connector())) {
                callback.onCompletion(new NotFoundException("Unknown connector: " + id.connector()), null);
                return null;
            }
            if (configState.taskConfig(id) == null) {
                callback.onCompletion(new NotFoundException("Unknown task: " + id), null);
                return null;
            }
            if (assignment.tasks().contains(id)) {
                try {
                    worker.stopAndAwaitTask(id);
                    if (startTask(id))
                        callback.onCompletion(null, null);
                    else
                        callback.onCompletion(new ConnectException("Failed to start task: " + id), null);
                } catch (Throwable t) {
                    callback.onCompletion(t, null);
                }
            } else if (isLeader()) {
                callback.onCompletion(new NotAssignedException("Cannot restart task since it is not assigned to this member", member.ownerUrl(id)), null);
            } else {
                callback.onCompletion(new NotLeaderException("Cannot restart task since it is not assigned to this member", leaderUrl()), null);
            }
            return null;
        }
    }, forwardErrorCallback(callback));
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException) 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) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 24 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerder method restartTask.

@Override
public synchronized void restartTask(ConnectorTaskId taskId, Callback<Void> cb) {
    if (!configState.contains(taskId.connector()))
        cb.onCompletion(new NotFoundException("Connector " + taskId.connector() + " not found", null), null);
    Map<String, String> taskConfigProps = configState.taskConfig(taskId);
    if (taskConfigProps == null)
        cb.onCompletion(new NotFoundException("Task " + taskId + " not found", null), null);
    Map<String, String> connConfigProps = configState.connectorConfig(taskId.connector());
    TargetState targetState = configState.targetState(taskId.connector());
    worker.stopAndAwaitTask(taskId);
    if (worker.startTask(taskId, connConfigProps, taskConfigProps, this, targetState))
        cb.onCompletion(null, null);
    else
        cb.onCompletion(new ConnectException("Failed to start task: " + taskId), null);
}
Also used : TargetState(org.apache.kafka.connect.runtime.TargetState) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 25 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerder method connectorInfo.

@Override
public synchronized void connectorInfo(String connName, Callback<ConnectorInfo> callback) {
    ConnectorInfo connectorInfo = createConnectorInfo(connName);
    if (connectorInfo == null) {
        callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), null);
        return;
    }
    callback.onCompletion(null, connectorInfo);
}
Also used : ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Aggregations

NotFoundException (org.apache.kafka.connect.errors.NotFoundException)48 Test (org.junit.Test)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 Callback (org.apache.kafka.connect.util.Callback)14 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)11 ConnectException (org.apache.kafka.connect.errors.ConnectException)9 ExecutionException (java.util.concurrent.ExecutionException)8 FutureCallback (org.apache.kafka.connect.util.FutureCallback)8 ArrayList (java.util.ArrayList)7 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)7 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)6 TaskInfo (org.apache.kafka.connect.runtime.rest.entities.TaskInfo)6 NoSuchElementException (java.util.NoSuchElementException)5 TimeoutException (java.util.concurrent.TimeoutException)5 WakeupException (org.apache.kafka.common.errors.WakeupException)5 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)5 RestartRequest (org.apache.kafka.connect.runtime.RestartRequest)5 Herder (org.apache.kafka.connect.runtime.Herder)4 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)4 Connector (org.apache.kafka.connect.connector.Connector)3