@Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof CommandStatus)) { return false; } final CommandStatus that = (CommandStatus) o; return getStatus() == that.getStatus() && Objects.equals(getMessage(), that.getMessage()); }
@GET @Path("/{type}/{entity}/{action}") public Response getStatus(@PathParam("type") final String type, @PathParam("entity") final String entity, @PathParam("action") final String action) { final CommandStatus.Status status = statuses.get(new CommandId(type, entity, action)); if (status == null) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok(new CommandStatus(status, "")).build(); } }
public static CommandStatuses fromFullStatuses(final Map<CommandId, CommandStatus> fullStatuses) { final Map<CommandId, CommandStatus.Status> statuses = fullStatuses.entrySet().stream().collect( Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getStatus()) ); return new CommandStatuses(statuses); } }
@Override public Table buildTable(final CommandStatusEntity entity) { return new Table.Builder() .withColumnHeaders("Message") .withRow(entity.getCommandStatus().getMessage().split("\n", 2)[0]) .build(); } }
@Override public boolean matches(final Object item) { return item instanceof CommandStatus && ((CommandStatus) item).getStatus().equals(status); }
@Override public int hashCode() { return Objects.hash(getStatus(), getMessage()); } }
@Test public void shoudlHandleTerminateRequestCorrectly() throws InterruptedException { // When: final Response response = ksqlResource.terminateCluster(VALID_TERMINATE_REQUEST); // Then: assertThat(response.getStatus(), equalTo(200)); assertThat(response.getEntity(), instanceOf(KsqlEntityList.class)); assertThat(((KsqlEntityList) response.getEntity()).size(), equalTo(1)); assertThat(((KsqlEntityList) response.getEntity()).get(0), instanceOf(CommandStatusEntity.class)); final CommandStatusEntity commandStatusEntity = (CommandStatusEntity) ((KsqlEntityList) response.getEntity()).get(0); assertThat(commandStatusEntity.getCommandStatus().getStatus(), equalTo(CommandStatus.Status.QUEUED)); verify(commandStore).enqueueCommand( eq(TerminateCluster.TERMINATE_CLUSTER_STATEMENT_TEXT), isA(Statement.class), any(), eq(Collections.singletonMap( ClusterTerminateRequest.DELETE_TOPIC_LIST_PROP, ImmutableList.of("Foo")))); }
commandId, commandStatusFuture, new CommandStatus(CommandStatus.Status.PARSING, "Parsing statement")); final PreparedStatement<?> statement = statementParser.parseSingleStatement(statementString); putStatus( commandId, commandStatusFuture, new CommandStatus(CommandStatus.Status.EXECUTING, "Executing statement") ); executeStatement( } catch (final KsqlException exception) { log.error("Failed to handle: " + command, exception); final CommandStatus errorStatus = new CommandStatus( CommandStatus.Status.ERROR, ExceptionUtil.stackTraceToString(exception)
private void printKsqlResponse(final RestResponse<KsqlEntityList> response) throws IOException { if (response.isSuccessful()) { final KsqlEntityList ksqlEntities = response.getResponse(); boolean noErrorFromServer = true; for (final KsqlEntity entity : ksqlEntities) { if (entity instanceof CommandStatusEntity && ( ((CommandStatusEntity) entity).getCommandStatus().getStatus() == CommandStatus.Status.ERROR) ) { final String fullMessage = ((CommandStatusEntity) entity).getCommandStatus().getMessage(); terminal.printError(fullMessage.split("\n")[0], fullMessage); noErrorFromServer = false; } } if (noErrorFromServer) { terminal.printKsqlEntityList(response.getResponse()); } } else { terminal.printErrorMessage(response.getErrorMessage()); } }
@Test public void shouldRegisterBeforeDistributeAndReturnStatusOnGetNewCommands() { // Given: when(commandIdAssigner.getCommandId(any())).thenReturn(commandId); when(commandTopic.send(any(), any())).thenAnswer( invocation -> { final QueuedCommand queuedCommand = commandStore.getNewCommands().get(0); assertThat(queuedCommand.getCommandId(), equalTo(commandId)); assertThat(queuedCommand.getStatus().isPresent(), equalTo(true)); assertThat( queuedCommand.getStatus().get().getStatus().getStatus(), equalTo(CommandStatus.Status.QUEUED)); return recordMetadata; } ); // When: commandStore.enqueueCommand(statementText, statement, KSQL_CONFIG, OVERRIDE_PROPERTIES); // Then: verify(commandTopic).send(any(), any()); }
final CommandStatus successStatus = new CommandStatus( CommandStatus.Status.SUCCESS, result != null ? result.getMessage() : successMessage
@Test public void shouldFailCreateAsSelectIfExceedActivePersistentQueriesLimit() { // Given: createStreamsAndStartTwoPersistentQueries(); // Prepare to try adding a third final KsqlConfig cmdConfig = givenCommandConfig(KsqlConfig.KSQL_ACTIVE_PERSISTENT_QUERY_LIMIT_CONFIG, 2); final Command csasCommand = givenCommand("CREATE STREAM user2pv AS select * from pageview;", cmdConfig); final CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen2", CommandId.Action.CREATE); // When: handleStatement(csasCommand, csasCommandId, Optional.empty()); // Then: final CommandStatus commandStatus = getCommandStatus(csasCommandId); assertThat("CSAS statement should fail since exceeds limit of 2 active persistent queries", commandStatus.getStatus(), is(CommandStatus.Status.ERROR)); assertThat( commandStatus.getMessage(), containsString("would cause the number of active, persistent queries " + "to exceed the configured limit")); }
@Test public void shouldReturnStatusForSpecificCommand() { // When: final RestResponse<CommandStatus> response = ksqlRestClient.makeStatusRequest("TOPIC/c1/CREATE"); // Then: assertThat(response, is(notNullValue())); assertThat(response.isSuccessful(), is(true)); assertThat(response.getResponse().getStatus(), is(CommandStatus.Status.SUCCESS)); }
"e", CommandId.fromString("topic/1/create"), new CommandStatus(CommandStatus.Status.SUCCESS, "Success Message"), 0L), new PropertiesList("e", properties, Collections.emptyList(), Collections.emptyList()),
@Test public void shouldFailInsertIntoIfExceedActivePersistentQueriesLimit() { // Given: createStreamsAndStartTwoPersistentQueries(); // Set limit and prepare to try adding a query that exceeds the limit final KsqlConfig cmdConfig = givenCommandConfig(KsqlConfig.KSQL_ACTIVE_PERSISTENT_QUERY_LIMIT_CONFIG, 1); final Command insertIntoCommand = givenCommand("INSERT INTO user1pv select * from pageview;", cmdConfig); final CommandId insertIntoCommandId = new CommandId(CommandId.Type.STREAM, "_InsertQuery1", CommandId.Action.CREATE); // When: handleStatement(insertIntoCommand, insertIntoCommandId, Optional.empty()); // Then: statement should fail since exceeds limit of 1 active persistent query final CommandStatus commandStatus = getCommandStatus(insertIntoCommandId); assertThat(commandStatus.getStatus(), is(CommandStatus.Status.ERROR)); assertThat( commandStatus.getMessage(), containsString("would cause the number of active, persistent queries " + "to exceed the configured limit")); }
private void terminateQueries() { final Command terminateCommand1 = new Command( "TERMINATE CSAS_USER1PV_0;", Collections.emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated()); final CommandId terminateCommandId1 = new CommandId(CommandId.Type.STREAM, "_TerminateGen", CommandId.Action.CREATE); handleStatement( statementExecutor, terminateCommand1, terminateCommandId1, Optional.empty()); assertThat( getCommandStatus(terminateCommandId1).getStatus(), equalTo(CommandStatus.Status.SUCCESS)); final Command terminateCommand2 = new Command( "TERMINATE CTAS_TABLE1_1;", Collections.emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated()); final CommandId terminateCommandId2 = new CommandId(CommandId.Type.TABLE, "_TerminateGen", CommandId.Action.CREATE); handleStatement( statementExecutor, terminateCommand2, terminateCommandId2, Optional.empty()); assertThat( getCommandStatus(terminateCommandId2).getStatus(), equalTo(CommandStatus.Status.SUCCESS)); }
assertThat(dropStreamCommandStatus1.get().getStatus(), CoreMatchers.equalTo(CommandStatus.Status.ERROR)); assertThat( dropStreamCommandStatus1 .get() .getMessage(), containsString("io.confluent.ksql.util.KsqlReferentialIntegrityException: Cannot drop PAGEVIEW.")); assertThat( dropStreamCommandStatus1 .get() .getMessage(), containsString("The following queries read from this source: [CTAS_TABLE1_1, CSAS_USER1PV_0].")); assertThat( dropStreamCommandStatus1 .get() .getMessage(), containsString("The following queries write into this source: [].")); assertThat( dropStreamCommandStatus1 .get() .getMessage(), containsString("You need to terminate them before dropping PAGEVIEW.")); assertThat(dropStreamCommandStatus2.get().getStatus(), CoreMatchers.equalTo(CommandStatus.Status.ERROR)); assertThat( dropStreamCommandStatus2.get() .getMessage(), containsString(
containsInAnyOrder(topicCommandId, csCommandId, csasCommandId, ctasCommandId, terminateCmdId)); assertThat(statusStore.get(topicCommandId).getStatus(), equalTo(CommandStatus.Status.SUCCESS)); assertThat(statusStore.get(csCommandId).getStatus(), equalTo(CommandStatus.Status.SUCCESS)); assertThat(statusStore.get(csasCommandId).getStatus(), equalTo(CommandStatus.Status.SUCCESS)); assertThat(statusStore.get(ctasCommandId).getStatus(), equalTo(CommandStatus.Status.ERROR)); assertThat(statusStore.get(terminateCmdId).getStatus(), equalTo(CommandStatus.Status.SUCCESS));
@Test public void shouldHandleCorrectDDLStatement() { final Command command = new Command("REGISTER TOPIC users_topic " + "WITH (value_format = 'json', kafka_topic='user_topic_json');", Collections.emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated()); final CommandId commandId = new CommandId(CommandId.Type.TOPIC, "_CorrectTopicGen", CommandId.Action.CREATE); handleStatement(command, commandId, Optional.empty()); final Map<CommandId, CommandStatus> statusStore = statementExecutor.getStatuses(); Assert.assertNotNull(statusStore); Assert.assertEquals(statusStore.size(), 1); Assert.assertEquals(statusStore.get(commandId).getStatus(), CommandStatus.Status.SUCCESS); }
@Test public void shouldHandleIncorrectDDLStatement() { final Command command = new Command("REGIST ER TOPIC users_topic " + "WITH (value_format = 'json', kafka_topic='user_topic_json');", Collections.emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated()); final CommandId commandId = new CommandId(CommandId.Type.TOPIC, "_IncorrectTopicGen", CommandId.Action.CREATE); handleStatement(command, commandId, Optional.empty()); final Map<CommandId, CommandStatus> statusStore = statementExecutor.getStatuses(); Assert.assertNotNull(statusStore); Assert.assertEquals(statusStore.size(), 1); Assert.assertEquals(statusStore.get(commandId).getStatus(), CommandStatus.Status.ERROR); }