Search in sources :

Example 1 with ConnectorList

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

the class ClientTest method shouldFailToListConnectorsViaExecuteStatement.

@Test
public void shouldFailToListConnectorsViaExecuteStatement() {
    // Given
    final ConnectorList entity = new ConnectorList("list connectors;", Collections.emptyList(), Collections.emptyList());
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.executeStatement("list connectors;").get());
    // Then
    assertThat(e.getCause(), instanceOf(KsqlClientException.class));
    assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
    assertThat(e.getCause().getMessage(), containsString("Use the listConnectors() method instead"));
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) 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 2 with ConnectorList

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

the class ClientTest method shouldListConnectors.

@Test
public void shouldListConnectors() throws Exception {
    // Given:
    final ConnectorList entity = new ConnectorList("list connectors;", Collections.emptyList(), Collections.singletonList(new SimpleConnectorInfo("name", SOURCE_TYPE, "class", "state")));
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When:
    final List<io.confluent.ksql.api.client.ConnectorInfo> connectors = javaClient.listConnectors().get();
    // Then:
    assertThat(connectors.size(), is(1));
    assertThat(connectors.get(0).state(), is("state"));
    assertThat(connectors.get(0).name(), is("name"));
    assertThat(connectors.get(0).type(), is(new ConnectorTypeImpl("SOURCE")));
}
Also used : SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConnectorTypeImpl(io.confluent.ksql.api.client.impl.ConnectorTypeImpl) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 3 with ConnectorList

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

the class ListConnectorsExecutor method execute.

@SuppressWarnings("OptionalGetWithoutIsPresent")
public StatementExecutorResponse execute(final ConfiguredStatement<ListConnectors> configuredStatement, final SessionProperties sessionProperties, final KsqlExecutionContext ksqlExecutionContext, final ServiceContext serviceContext) {
    final ConnectClient connectClient = serviceContext.getConnectClient();
    final ConnectResponse<List<String>> connectors = serviceContext.getConnectClient().connectors();
    if (connectors.error().isPresent()) {
        return StatementExecutorResponse.handled(connectErrorHandler.handle(configuredStatement, connectors));
    }
    final List<SimpleConnectorInfo> infos = new ArrayList<>();
    final List<KsqlWarning> warnings = new ArrayList<>();
    final Scope scope = configuredStatement.getStatement().getScope();
    for (final String name : connectors.datum().get()) {
        final ConnectResponse<ConnectorInfo> response = connectClient.describe(name);
        if (response.datum().filter(i -> inScope(i.type(), scope)).isPresent()) {
            final ConnectResponse<ConnectorStateInfo> status = connectClient.status(name);
            infos.add(fromConnectorInfoResponse(name, response, status));
        } else if (response.error().isPresent()) {
            if (scope == Scope.ALL) {
                infos.add(new SimpleConnectorInfo(name, ConnectorType.UNKNOWN, null, null));
            }
            warnings.add(new KsqlWarning(String.format("Could not describe connector %s: %s", name, response.error().get())));
        }
    }
    return StatementExecutorResponse.handled(Optional.of(new ConnectorList(configuredStatement.getStatementText(), warnings, infos)));
}
Also used : SessionProperties(io.confluent.ksql.rest.SessionProperties) Scope(io.confluent.ksql.parser.tree.ListConnectors.Scope) ConnectClient(io.confluent.ksql.services.ConnectClient) ServiceContext(io.confluent.ksql.services.ServiceContext) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) ArrayList(java.util.ArrayList) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) State(org.apache.kafka.connect.runtime.AbstractStatus.State) ConnectResponse(io.confluent.ksql.services.ConnectClient.ConnectResponse) Optional(java.util.Optional) ListConnectors(io.confluent.ksql.parser.tree.ListConnectors) AbstractState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.AbstractState) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ArrayList(java.util.ArrayList) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) Scope(io.confluent.ksql.parser.tree.ListConnectors.Scope) ConnectClient(io.confluent.ksql.services.ConnectClient) ArrayList(java.util.ArrayList) List(java.util.List) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)

Example 4 with ConnectorList

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

the class MigrationsTest method assertConnectorCount.

private static void assertConnectorCount(final int count) {
    final List<KsqlEntity> entities = assertThatEventually(() -> makeKsqlRequest("LIST CONNECTORS;"), hasSize(1));
    assertThat(entities.get(0), instanceOf(ConnectorList.class));
    ConnectorList entity = (ConnectorList) entities.get(0);
    assertThat(entity.getConnectors().size(), is(count));
}
Also used : ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity)

Example 5 with ConnectorList

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

the class ConsoleTest method shouldPrintConnectorsList.

@Test
public void shouldPrintConnectorsList() {
    // Given:
    final KsqlEntityList entities = new KsqlEntityList(ImmutableList.of(new ConnectorList("statement", ImmutableList.of(), ImmutableList.of(new SimpleConnectorInfo("foo", ConnectorType.SOURCE, "clazz", "STATUS"), new SimpleConnectorInfo("bar", null, null, null)))));
    // When:
    console.printKsqlEntityList(entities);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

ConnectorList (io.confluent.ksql.rest.entity.ConnectorList)11 Test (org.junit.Test)9 SimpleConnectorInfo (io.confluent.ksql.rest.entity.SimpleConnectorInfo)6 ListConnectors (io.confluent.ksql.parser.tree.ListConnectors)5 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)5 KsqlConfig (io.confluent.ksql.util.KsqlConfig)4 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)3 IntegrationTest (io.confluent.common.utils.IntegrationTest)2 BaseApiTest (io.confluent.ksql.api.BaseApiTest)2 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)2 KsqlWarning (io.confluent.ksql.rest.entity.KsqlWarning)2 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)2 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)1 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)1 ConnectorTypeImpl (io.confluent.ksql.api.client.impl.ConnectorTypeImpl)1 KsqlApiException (io.confluent.ksql.api.server.KsqlApiException)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 Scope (io.confluent.ksql.parser.tree.ListConnectors.Scope)1