Search in sources :

Example 1 with CreateConnectorEntity

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 ();"));
}
Also used : CreateConnectorEntity(io.confluent.ksql.rest.entity.CreateConnectorEntity) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with CreateConnectorEntity

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"));
}
Also used : CreateConnectorEntity(io.confluent.ksql.rest.entity.CreateConnectorEntity) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) ExecutionException(java.util.concurrent.ExecutionException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.api.client.exception.KsqlException) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 3 with CreateConnectorEntity

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")));
}
Also used : CreateConnectorEntity(io.confluent.ksql.rest.entity.CreateConnectorEntity) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) JsonObject(io.vertx.core.json.JsonObject) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 4 with CreateConnectorEntity

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));
}
Also used : CreateConnectorEntity(io.confluent.ksql.rest.entity.CreateConnectorEntity) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ConnectClient(io.confluent.ksql.services.ConnectClient) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) CreateConnector(io.confluent.ksql.parser.tree.CreateConnector) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity)

Aggregations

CreateConnectorEntity (io.confluent.ksql.rest.entity.CreateConnectorEntity)4 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)4 BaseApiTest (io.confluent.ksql.api.BaseApiTest)3 SimpleConnectorInfo (io.confluent.ksql.rest.entity.SimpleConnectorInfo)3 Test (org.junit.Test)3 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)1 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)1 KsqlApiException (io.confluent.ksql.api.server.KsqlApiException)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 CreateConnector (io.confluent.ksql.parser.tree.CreateConnector)1 ErrorEntity (io.confluent.ksql.rest.entity.ErrorEntity)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 ConnectClient (io.confluent.ksql.services.ConnectClient)1 JsonObject (io.vertx.core.json.JsonObject)1 ExecutionException (java.util.concurrent.ExecutionException)1