Search in sources :

Example 1 with QueryInfo

use of io.confluent.ksql.api.client.QueryInfo in project ksql by confluentinc.

the class DestroyMigrationsCommand method terminateQueryForTable.

private static void terminateQueryForTable(final Client ksqlClient, final SourceDescription tableDesc) {
    final List<QueryInfo> queries = tableDesc.writeQueries();
    if (queries.size() == 0) {
        LOGGER.info("Found 0 queries writing to the metadata table");
        return;
    }
    if (queries.size() > 1) {
        throw new MigrationException("Found multiple queries writing to the metadata table. Query IDs: " + queries.stream().map(QueryInfo::getId).collect(Collectors.joining("', '", "'", "'.")));
    }
    final String queryId = queries.get(0).getId();
    LOGGER.info("Found 1 query writing to the metadata table. Query ID: {}", queryId);
    LOGGER.info("Terminating query with ID: {}", queryId);
    try {
        ksqlClient.executeStatement("TERMINATE " + queryId + ";").get();
    } catch (InterruptedException | ExecutionException e) {
        throw new MigrationException(String.format("Failed to terminate query populating metadata table. Query ID: %s. Error: %s", queryId, e.getMessage()));
    }
}
Also used : MigrationException(io.confluent.ksql.tools.migrations.MigrationException) QueryInfo(io.confluent.ksql.api.client.QueryInfo) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

QueryInfo (io.confluent.ksql.api.client.QueryInfo)1 MigrationException (io.confluent.ksql.tools.migrations.MigrationException)1 ExecutionException (java.util.concurrent.ExecutionException)1