Search in sources :

Example 6 with ErrorEntity

use of io.confluent.ksql.rest.entity.ErrorEntity 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)

Example 7 with ErrorEntity

use of io.confluent.ksql.rest.entity.ErrorEntity in project ksql by confluentinc.

the class ConsoleTest method shouldPrintErrorEntityLongNonJson.

@Test
public void shouldPrintErrorEntityLongNonJson() {
    // Given:
    final KsqlEntity entity = new ErrorEntity("statementText", Strings.repeat("Not a JSON value! ", 10));
    // When:
    console.printKsqlEntityList(ImmutableList.of(entity));
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Aggregations

ErrorEntity (io.confluent.ksql.rest.entity.ErrorEntity)7 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)6 Test (org.junit.Test)6 CreateConnector (io.confluent.ksql.parser.tree.CreateConnector)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BaseApiTest (io.confluent.ksql.api.BaseApiTest)1 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 CreateConnectorEntity (io.confluent.ksql.rest.entity.CreateConnectorEntity)1 ConnectClient (io.confluent.ksql.services.ConnectClient)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)1