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();
}
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));
}
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);
}
}
Aggregations