use of io.confluent.ksql.connect.Connector 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));
}
use of io.confluent.ksql.connect.Connector in project ksql by confluentinc.
the class JdbcSourceTest method shouldCreateJdbcConnectorWithValidConfigsAndSMT.
@Test
public void shouldCreateJdbcConnectorWithValidConfigsAndSMT() {
// Given:
final Map<String, String> config = ImmutableMap.of(Connectors.CONNECTOR_CLASS, JdbcSource.JDBC_SOURCE_CLASS, "name", "foo", "transforms", "foobar,createKey", "transforms.createKey.type", "org.apache.kafka.connect.transforms.ExtractField$Key", "transforms.createKey.field", "key");
// When:
final Optional<Connector> maybeConnector = jdbcSource.fromConfigs(config);
// Then:
final Connector expected = new Connector("foo", DataSourceType.KTABLE, "key");
assertThat(maybeConnector, OptionalMatchers.of(is(expected)));
}
use of io.confluent.ksql.connect.Connector in project ksql by confluentinc.
the class JdbcSourceTest method shouldCreateJdbcConnectorWithValidConfigs.
@Test
public void shouldCreateJdbcConnectorWithValidConfigs() {
// Given:
final Map<String, String> config = ImmutableMap.of(Connectors.CONNECTOR_CLASS, JdbcSource.JDBC_SOURCE_CLASS, "name", "foo");
// When:
final Optional<Connector> maybeConnector = jdbcSource.fromConfigs(config);
// Then:
final Connector expected = new Connector("foo", DataSourceType.KTABLE, null);
assertThat(maybeConnector, OptionalMatchers.of(is(expected)));
}
Aggregations