Search in sources :

Example 1 with ConnectorDescription

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

the class ClientTest method shouldSendSessionVariablesWithDescribeConnector.

@Test
public void shouldSendSessionVariablesWithDescribeConnector() throws Exception {
    // Given:
    javaClient.define("a", "a");
    final ConnectorDescription entity = new ConnectorDescription("describe connector;", "connectorClass", new ConnectorStateInfo("name", new ConnectorState("state", "worker", "msg"), Collections.emptyList(), SOURCE_TYPE), Collections.emptyList(), Collections.singletonList("topic"), Collections.emptyList());
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When:
    javaClient.describeConnector("name").get();
    // Then:
    assertThat(testEndpoints.getLastSessionVariables(), is(new JsonObject().put("a", "a")));
}
Also used : ConnectorState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) JsonObject(io.vertx.core.json.JsonObject) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with ConnectorDescription

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

the class ClientTest method shouldFailToDescribeConnectorViaExecuteStatement.

@Test
public void shouldFailToDescribeConnectorViaExecuteStatement() {
    // Given
    final ConnectorDescription entity = new ConnectorDescription("describe connector;", "connectorClass", new ConnectorStateInfo("name", new ConnectorState("state", "worker", "msg"), Collections.emptyList(), SOURCE_TYPE), Collections.emptyList(), Collections.singletonList("topic"), Collections.emptyList());
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.executeStatement("describe connector;").get());
    // Then
    assertThat(e.getCause(), instanceOf(KsqlClientException.class));
    assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
    assertThat(e.getCause().getMessage(), containsString("Use the describeConnector() method instead"));
}
Also used : ConnectorState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) 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 ConnectorDescription

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

the class DescribeConnectorExecutor method execute.

@SuppressWarnings("OptionalGetWithoutIsPresent")
public StatementExecutorResponse execute(final ConfiguredStatement<DescribeConnector> configuredStatement, final SessionProperties sessionProperties, final KsqlExecutionContext ksqlExecutionContext, final ServiceContext serviceContext) {
    final String connectorName = configuredStatement.getStatement().getConnectorName();
    final ConnectResponse<ConnectorStateInfo> statusResponse = serviceContext.getConnectClient().status(connectorName);
    if (statusResponse.error().isPresent()) {
        return StatementExecutorResponse.handled(connectErrorHandler.handle(configuredStatement, statusResponse));
    }
    final ConnectResponse<ConnectorInfo> infoResponse = serviceContext.getConnectClient().describe(connectorName);
    if (infoResponse.error().isPresent()) {
        return StatementExecutorResponse.handled(connectErrorHandler.handle(configuredStatement, infoResponse));
    }
    final ConnectorStateInfo status = statusResponse.datum().get();
    final ConnectorInfo info = infoResponse.datum().get();
    final Optional<Connector> connector = connectorFactory.apply(info);
    final List<KsqlWarning> warnings;
    final List<String> topics;
    if (connector.isPresent()) {
        // Small optimization. If a connector's info is not found in the response, don't query for
        // active topics with the given connectorName
        final ConnectResponse<Map<String, Map<String, List<String>>>> topicsResponse = serviceContext.getConnectClient().topics(connectorName);
        // server logs.
        if (topicsResponse.error().isPresent() && topicsResponse.httpCode() == HttpStatus.SC_NOT_FOUND) {
            topics = ImmutableList.of();
            warnings = ImmutableList.of();
            LOG.warn("Could not list related topics due to error: " + topicsResponse.error().get());
        } else if (topicsResponse.error().isPresent()) {
            topics = ImmutableList.of();
            warnings = ImmutableList.of(new KsqlWarning("Could not list related topics due to error: " + topicsResponse.error().get()));
        } else {
            topics = topicsResponse.datum().get().get(connectorName).getOrDefault(TOPICS_KEY, ImmutableList.of());
            warnings = ImmutableList.of();
        }
    } else {
        topics = ImmutableList.of();
        warnings = ImmutableList.of();
    }
    final List<SourceDescription> sources;
    if (connector.isPresent()) {
        sources = ksqlExecutionContext.getMetaStore().getAllDataSources().values().stream().filter(source -> topics.contains(source.getKafkaTopicName())).map(source -> SourceDescriptionFactory.create(source, false, ImmutableList.of(), ImmutableList.of(), Optional.empty(), ImmutableList.of(), ImmutableList.of(), ksqlExecutionContext.metricCollectors())).collect(Collectors.toList());
    } else {
        sources = ImmutableList.of();
    }
    final ConnectorDescription description = new ConnectorDescription(configuredStatement.getStatementText(), info.config().get(ConnectorConfig.CONNECTOR_CLASS_CONFIG), status, sources, topics, warnings);
    return StatementExecutorResponse.handled(Optional.of(description));
}
Also used : Connectors(io.confluent.ksql.connect.supported.Connectors) SessionProperties(io.confluent.ksql.rest.SessionProperties) ServiceContext(io.confluent.ksql.services.ServiceContext) LoggerFactory(org.slf4j.LoggerFactory) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) Function(java.util.function.Function) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) DescribeConnector(io.confluent.ksql.parser.tree.DescribeConnector) Logger(org.slf4j.Logger) Connector(io.confluent.ksql.connect.Connector) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Collectors(java.util.stream.Collectors) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) ConnectResponse(io.confluent.ksql.services.ConnectClient.ConnectResponse) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HttpStatus(org.apache.hc.core5.http.HttpStatus) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) DescribeConnector(io.confluent.ksql.parser.tree.DescribeConnector) Connector(io.confluent.ksql.connect.Connector) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Map(java.util.Map) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 4 with ConnectorDescription

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

the class ConsoleTest method testPrintConnectorDescription.

@Test
public void testPrintConnectorDescription() {
    // Given:
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new ConnectorDescription("STATEMENT", "io.confluent.Connector", new ConnectorStateInfo("name", new ConnectorState("state", "worker", "msg"), ImmutableList.of(new TaskState(0, "task", "worker", "task_msg")), ConnectorType.SOURCE), ImmutableList.of(sourceDescription), ImmutableList.of("a-jdbc-topic"), ImmutableList.of())));
    // When:
    console.printKsqlEntityList(entityList);
    // Then:
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) ConnectorState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) Matchers.containsString(org.hamcrest.Matchers.containsString) TaskState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.TaskState) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) Test(org.junit.Test)

Example 5 with ConnectorDescription

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

the class DescribeConnectorExecutorTest method shouldWorkIfUnknownConnector.

@Test
public void shouldWorkIfUnknownConnector() {
    // Given:
    connectorFactory = info -> Optional.empty();
    executor = new DescribeConnectorExecutor(connectorFactory, new DefaultConnectServerErrors());
    // When:
    final Optional<KsqlEntity> entity = executor.execute(describeStatement, mock(SessionProperties.class), engine, serviceContext).getEntity();
    // Then:
    verify(connectClient).status("connector");
    verify(connectClient).describe("connector");
    assertThat("Expected a response", entity.isPresent());
    assertThat(entity.get(), instanceOf(ConnectorDescription.class));
    final ConnectorDescription description = (ConnectorDescription) entity.get();
    assertThat(description.getConnectorClass(), is(CONNECTOR_CLASS));
    assertThat(description.getStatus(), is(STATUS));
    assertThat(description.getSources(), empty());
}
Also used : ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) Test(org.junit.Test)

Aggregations

ConnectorDescription (io.confluent.ksql.rest.entity.ConnectorDescription)9 Test (org.junit.Test)8 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)5 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 ConnectorState (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState)4 BaseApiTest (io.confluent.ksql.api.BaseApiTest)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 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 Connector (io.confluent.ksql.connect.Connector)1 Connectors (io.confluent.ksql.connect.supported.Connectors)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 DescribeConnector (io.confluent.ksql.parser.tree.DescribeConnector)1 SessionProperties (io.confluent.ksql.rest.SessionProperties)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1