use of io.confluent.ksql.rest.entity.CreateConnectorEntity in project ksql by confluentinc.
the class ClientTest method shouldCreateConnector.
@Test
public void shouldCreateConnector() throws Exception {
// Given
final CreateConnectorEntity entity = new CreateConnectorEntity("create connector;", new ConnectorInfo("name", Collections.emptyMap(), Collections.emptyList(), SOURCE_TYPE));
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When:
javaClient.createConnector("name", true, Collections.emptyMap()).get();
// Then:
assertThat(testEndpoints.getLastSql(), is("CREATE SOURCE CONNECTOR name WITH ();"));
}
use of io.confluent.ksql.rest.entity.CreateConnectorEntity in project ksql by confluentinc.
the class ClientTest method shouldFailToCreateConnectorViaExecuteStatement.
@Test
public void shouldFailToCreateConnectorViaExecuteStatement() {
// Given
final CreateConnectorEntity entity = new CreateConnectorEntity("create connector;", new ConnectorInfo("name", Collections.emptyMap(), Collections.emptyList(), SOURCE_TYPE));
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When
final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
ExecutionException.class, () -> javaClient.executeStatement("create connector;").get());
// Then
assertThat(e.getCause(), instanceOf(KsqlClientException.class));
assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_REQUEST_ACCEPTED_DOC));
assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
assertThat(e.getCause().getMessage(), containsString("Use the createConnector() method instead"));
}
use of io.confluent.ksql.rest.entity.CreateConnectorEntity in project ksql by confluentinc.
the class ClientTest method shouldSendSessionVariablesWithCreateConnector.
@Test
public void shouldSendSessionVariablesWithCreateConnector() throws Exception {
// Given
javaClient.define("a", "a");
final CreateConnectorEntity entity = new CreateConnectorEntity("create connector;", new ConnectorInfo("name", Collections.emptyMap(), Collections.emptyList(), SOURCE_TYPE));
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When:
javaClient.createConnector("name", true, Collections.emptyMap()).get();
// Then:
assertThat(testEndpoints.getLastSessionVariables(), is(new JsonObject().put("a", "a")));
}
use of io.confluent.ksql.rest.entity.CreateConnectorEntity in project ksql by confluentinc.
the class ConnectExecutor method execute.
public StatementExecutorResponse execute(final ConfiguredStatement<CreateConnector> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final CreateConnector createConnector = statement.getStatement();
final ConnectClient client = serviceContext.getConnectClient();
final List<String> errors = validate(createConnector, client);
if (!errors.isEmpty()) {
final String errorMessage = "Validation error: " + String.join("\n", errors);
return StatementExecutorResponse.handled(Optional.of(new ErrorEntity(statement.getStatementText(), errorMessage)));
}
final Optional<KsqlEntity> connectorsResponse = handleIfNotExists(statement, createConnector, client);
if (connectorsResponse.isPresent()) {
return StatementExecutorResponse.handled(connectorsResponse);
}
final ConnectResponse<ConnectorInfo> response = client.create(createConnector.getName(), buildConnectorConfig(createConnector));
if (response.datum().isPresent()) {
return StatementExecutorResponse.handled(Optional.of(new CreateConnectorEntity(statement.getStatementText(), response.datum().get())));
}
if (createConnector.ifNotExists()) {
final Optional<KsqlEntity> connectors = handleIfNotExists(statement, createConnector, client);
if (connectors.isPresent()) {
return StatementExecutorResponse.handled(connectors);
}
}
return StatementExecutorResponse.handled(connectErrorHandler.handle(statement, response));
}
Aggregations