use of io.confluent.ksql.rest.entity.TerminateQueryEntity in project ksql by confluentinc.
the class TerminateQueryExecutorTest method shouldTerminateTransientQuery.
@Test
public void shouldTerminateTransientQuery() {
// Given:
final ConfiguredStatement<TerminateQuery> terminateTransient = (ConfiguredStatement<TerminateQuery>) engine.configure("TERMINATE TRANSIENT_QUERY;");
final TransientQueryMetadata transientQueryMetadata = givenTransientQuery("TRANSIENT_QUERY", RUNNING_QUERY_STATE);
final QueryId transientQueryId = transientQueryMetadata.getQueryId();
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getQuery(transientQueryId)).thenReturn(Optional.of(transientQueryMetadata));
// When:
final Optional<KsqlEntity> ksqlEntity = CUSTOM_EXECUTORS.terminateQuery().execute(terminateTransient, mock(SessionProperties.class), engine, this.engine.getServiceContext()).getEntity();
// Then:
assertThat(ksqlEntity, is(Optional.of(new TerminateQueryEntity(terminateTransient.getStatementText(), transientQueryId.toString(), true))));
}
use of io.confluent.ksql.rest.entity.TerminateQueryEntity in project ksql by confluentinc.
the class TerminateQueryExecutor method execute.
public static StatementExecutorResponse execute(final ConfiguredStatement<TerminateQuery> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final TerminateQuery terminateQuery = statement.getStatement();
// do default behaviour for TERMINATE ALL
if (!terminateQuery.getQueryId().isPresent()) {
return StatementExecutorResponse.notHandled();
}
final QueryId queryId = terminateQuery.getQueryId().get();
final RemoteHostExecutor remoteHostExecutor = RemoteHostExecutor.create(statement, sessionProperties, executionContext, serviceContext.getKsqlClient());
if (executionContext.getPersistentQuery(queryId).isPresent() || statement.getStatementText().equals(TerminateCluster.TERMINATE_CLUSTER_STATEMENT_TEXT)) {
// do default behaviour for terminating persistent queries
return StatementExecutorResponse.notHandled();
} else {
// propagate terminate query to other nodes
if (executionContext.getQuery(queryId).isPresent()) {
executionContext.getQuery(queryId).get().close();
} else {
final boolean wasTerminatedRemotely = remoteHostExecutor.fetchAllRemoteResults().getLeft().values().stream().map(TerminateQueryEntity.class::cast).map(TerminateQueryEntity::getWasTerminated).anyMatch(b -> b.equals(true));
if (!wasTerminatedRemotely) {
throw new KsqlException(String.format("Failed to terminate query with query ID: '%s'", queryId));
}
}
return StatementExecutorResponse.handled(Optional.of(new TerminateQueryEntity(statement.getStatementText(), queryId.toString(), true)));
}
}
use of io.confluent.ksql.rest.entity.TerminateQueryEntity in project ksql by confluentinc.
the class ConsoleTest method shouldPrintTerminateQuery.
@Test
public void shouldPrintTerminateQuery() {
// Given:
final KsqlEntity entity = new TerminateQueryEntity("statementText", "queryId", true);
// When:
console.printKsqlEntityList(ImmutableList.of(entity));
// Then:
final String output = terminal.getOutputString();
Approvals.verify(output, approvalOptions);
}
Aggregations