Search in sources :

Example 31 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class DistributedHerder method deleteConnectorConfig.

@Override
public void deleteConnectorConfig(final String connName, final Callback<Created<ConnectorInfo>> callback) {
    addRequest(() -> {
        log.trace("Handling connector config request {}", connName);
        if (!isLeader()) {
            callback.onCompletion(new NotLeaderException("Only the leader can delete connector configs.", leaderUrl()), null);
            return null;
        }
        if (!configState.contains(connName)) {
            callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), null);
        } else {
            log.trace("Removing connector config {} {}", connName, configState.connectors());
            configBackingStore.removeConnectorConfig(connName);
            callback.onCompletion(null, new Created<>(false, null));
        }
        return null;
    }, forwardErrorCallback(callback));
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Example 32 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class DistributedHerder method restartConnector.

@Override
public HerderRequest restartConnector(final long delayMs, final String connName, final Callback<Void> callback) {
    return addRequest(delayMs, () -> {
        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.stopAndAwaitConnector(connName);
                startConnector(connName, callback);
            } 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("Only the leader can process restart requests.", leaderUrl()), null);
        }
        return null;
    }, forwardErrorCallback(callback));
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Example 33 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class DistributedHerder method restartConnectorAndTasks.

@Override
public void restartConnectorAndTasks(RestartRequest request, Callback<ConnectorStateInfo> callback) {
    final String connectorName = request.connectorName();
    addRequest(() -> {
        if (checkRebalanceNeeded(callback)) {
            return null;
        }
        if (!configState.connectors().contains(request.connectorName())) {
            callback.onCompletion(new NotFoundException("Unknown connector: " + connectorName), null);
            return null;
        }
        if (isLeader()) {
            // Write a restart request to the config backing store, to be executed asynchronously in tick()
            configBackingStore.putRestartRequest(request);
            // Compute and send the response that this was accepted
            Optional<RestartPlan> plan = buildRestartPlan(request);
            if (!plan.isPresent()) {
                callback.onCompletion(new NotFoundException("Status for connector " + connectorName + " not found", null), null);
            } else {
                callback.onCompletion(null, plan.get().restartConnectorStateInfo());
            }
        } else {
            callback.onCompletion(new NotLeaderException("Only the leader can process restart requests.", leaderUrl()), null);
        }
        return null;
    }, forwardErrorCallback(callback));
}
Also used : RestartPlan(org.apache.kafka.connect.runtime.RestartPlan) NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Example 34 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class DistributedHerder method connectorInfo.

@Override
public void connectorInfo(final String connName, final Callback<ConnectorInfo> callback) {
    log.trace("Submitting connector info request {}", connName);
    addRequest(() -> {
        if (checkRebalanceNeeded(callback))
            return null;
        if (!configState.contains(connName)) {
            callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), null);
        } else {
            callback.onCompletion(null, connectorInfo(connName));
        }
        return null;
    }, forwardErrorCallback(callback));
}
Also used : NotFoundException(org.apache.kafka.connect.errors.NotFoundException)

Example 35 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project kafka by apache.

the class DistributedHerder method putTaskConfigs.

@Override
public void putTaskConfigs(final String connName, final List<Map<String, String>> configs, final Callback<Void> callback, InternalRequestSignature requestSignature) {
    log.trace("Submitting put task configuration request {}", connName);
    if (internalRequestValidationEnabled()) {
        ConnectRestException requestValidationError = null;
        if (requestSignature == null) {
            requestValidationError = new BadRequestException("Internal request missing required signature");
        } else if (!keySignatureVerificationAlgorithms.contains(requestSignature.keyAlgorithm())) {
            requestValidationError = new BadRequestException(String.format("This worker does not support the '%s' key signing algorithm used by other workers. " + "This worker is currently configured to use: %s. " + "Check that all workers' configuration files permit the same set of signature algorithms, " + "and correct any misconfigured worker and restart it.", requestSignature.keyAlgorithm(), keySignatureVerificationAlgorithms));
        } else {
            if (!requestSignature.isValid(sessionKey)) {
                requestValidationError = new ConnectRestException(Response.Status.FORBIDDEN, "Internal request contained invalid signature.");
            }
        }
        if (requestValidationError != null) {
            callback.onCompletion(requestValidationError, null);
            return;
        }
    }
    addRequest(() -> {
        if (!isLeader())
            callback.onCompletion(new NotLeaderException("Only the leader may write task configurations.", leaderUrl()), null);
        else if (!configState.contains(connName))
            callback.onCompletion(new NotFoundException("Connector " + connName + " not found"), null);
        else {
            configBackingStore.putTaskConfigs(connName, configs);
            callback.onCompletion(null, null);
        }
        return null;
    }, forwardErrorCallback(callback));
}
Also used : ConnectRestException(org.apache.kafka.connect.runtime.rest.errors.ConnectRestException) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) 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