use of io.confluent.ksql.services.ConnectClient 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)));
}
use of io.confluent.ksql.services.ConnectClient 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));
}
Aggregations