Search in sources :

Example 1 with AlreadyExistsException

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

the class ConnectorsResourceTest method testCreateConnectorExists.

@Test(expected = AlreadyExistsException.class)
public void testCreateConnectorExists() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackException(cb, new AlreadyExistsException("already exists"));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, body);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with AlreadyExistsException

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

the class DistributedHerder method putConnectorConfig.

@Override
public void putConnectorConfig(final String connName, final Map<String, String> config, final boolean allowReplace, final Callback<Created<ConnectorInfo>> callback) {
    log.trace("Submitting connector config write request {}", connName);
    addRequest(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            ConfigInfos validatedConfig = validateConnectorConfig(config);
            if (validatedConfig.errorCount() > 0) {
                callback.onCompletion(new BadRequestException("Connector configuration is invalid " + "(use the endpoint `/{connectorType}/config/validate` to get a full list of errors)"), null);
                return null;
            }
            log.trace("Handling connector config request {}", connName);
            if (!isLeader()) {
                callback.onCompletion(new NotLeaderException("Only the leader can set connector configs.", leaderUrl()), null);
                return null;
            }
            boolean exists = configState.contains(connName);
            if (!allowReplace && exists) {
                callback.onCompletion(new AlreadyExistsException("Connector " + connName + " already exists"), null);
                return null;
            }
            log.trace("Submitting connector config {} {} {}", connName, allowReplace, configState.connectors());
            configBackingStore.putConnectorConfig(connName, config);
            // Note that we use the updated connector config despite the fact that we don't have an updated
            // snapshot yet. The existing task info should still be accurate.
            ConnectorInfo info = new ConnectorInfo(connName, config, configState.tasks(connName));
            callback.onCompletion(null, new Created<>(!exists, info));
            return null;
        }
    }, forwardErrorCallback(callback));
}
Also used : AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) TimeoutException(java.util.concurrent.TimeoutException) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) WakeupException(org.apache.kafka.common.errors.WakeupException) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) NoSuchElementException(java.util.NoSuchElementException) ConnectException(org.apache.kafka.connect.errors.ConnectException) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos)

Example 3 with AlreadyExistsException

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

the class StandaloneHerder method putConnectorConfig.

@Override
public synchronized void putConnectorConfig(String connName, final Map<String, String> config, boolean allowReplace, final Callback<Created<ConnectorInfo>> callback) {
    try {
        ConfigInfos validatedConfig = validateConnectorConfig(config);
        if (validatedConfig.errorCount() > 0) {
            callback.onCompletion(new BadRequestException("Connector configuration is invalid " + "(use the endpoint `/{connectorType}/config/validate` to get a full list of errors)"), null);
            return;
        }
        boolean created = false;
        if (configState.contains(connName)) {
            if (!allowReplace) {
                callback.onCompletion(new AlreadyExistsException("Connector " + connName + " already exists"), null);
                return;
            }
            worker.stopConnector(connName);
        } else {
            created = true;
        }
        if (!startConnector(config)) {
            callback.onCompletion(new ConnectException("Failed to start connector: " + connName), null);
            return;
        }
        updateConnectorTasks(connName);
        callback.onCompletion(null, new Created<>(created, createConnectorInfo(connName)));
    } catch (ConnectException e) {
        callback.onCompletion(e, null);
    }
}
Also used : AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)3 ConnectException (org.apache.kafka.connect.errors.ConnectException)2 ConfigInfos (org.apache.kafka.connect.runtime.rest.entities.ConfigInfos)2 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)2 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)2 NoSuchElementException (java.util.NoSuchElementException)1 TimeoutException (java.util.concurrent.TimeoutException)1 WakeupException (org.apache.kafka.common.errors.WakeupException)1 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)1 Herder (org.apache.kafka.connect.runtime.Herder)1 CreateConnectorRequest (org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest)1 Callback (org.apache.kafka.connect.util.Callback)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1