public Object get() { if (isSuccessful()) { return getResponse(); } else { return getErrorMessage(); } }
restClient.makePrintTopicRequest(printTopic); if (topicResponse.isSuccessful()) { try (Scanner topicStreamScanner = new Scanner(topicResponse.getResponse(), UTF_8.name()); StatusClosable ignored = terminal.setStatusMessage("Press CTRL-C to interrupt")
private void handleStreamedQuery(final String query) throws IOException { final RestResponse<KsqlRestClient.QueryStream> queryResponse = restClient.makeQueryRequest(query); LOGGER.debug("Handling streamed query"); if (!queryResponse.isSuccessful()) { terminal.printErrorMessage(queryResponse.getErrorMessage()); } else { try (KsqlRestClient.QueryStream queryStream = queryResponse.getResponse(); StatusClosable ignored = terminal.setStatusMessage("Press CTRL-C to interrupt")) { streamResults(queryStream); } } }
private ReceiverThread(final RestResponse<KsqlRestClient.QueryStream> queryResponse) { assertThat("not successful", queryResponse.isSuccessful(), is(true)); this.queryStream = queryResponse.getResponse(); this.thread = new Thread(() -> { try { while (queryStream.hasNext()) { final StreamedRow row = queryStream.next(); rows.add(row); } } catch (final Exception e) { exception.set(e); } }, "receiver-thread"); thread.setDaemon(true); thread.start(); }
private static void dropStream(final String name) { final String dropStatement = String.format("drop stream %s;", name); final RestResponse response = restClient.makeKsqlRequest(dropStatement); if (response.isSuccessful()) { return; } final java.util.regex.Matcher matcher = WRITE_QUERIES .matcher(response.getErrorMessage().getMessage()); if (!matcher.matches()) { throw new RuntimeException("Failed to drop stream: " + response.getErrorMessage()); } Arrays.stream(matcher.group(1).split("/w*,/w*")) .forEach(CliTest::terminateQuery); runStatement(dropStatement, restClient); }
private static void maybeDropStream(final String name) { final String dropStatement = String.format("drop stream %s;", name); final RestResponse response = restClient.makeKsqlRequest(dropStatement); if (response.isSuccessful() || response.getErrorMessage().toString().contains("does not exist")) { return; } dropStream(name); }
private static void createStreams() { try (final KsqlRestClient ksqlRestClient = new KsqlRestClient(REST_APP.getHttpListener().toString()) ) { final RestResponse createStreamResponse = ksqlRestClient .makeKsqlRequest(String.format( "CREATE STREAM %s (viewtime bigint, pageid varchar, userid varchar)" + " WITH (kafka_topic='pageviews', value_format='json');", PAGE_VIEW_STREAM)); assertTrue(createStreamResponse.isSuccessful()); } } }
@Test public void testKsqlResource() { final RestResponse<KsqlEntityList> results = ksqlRestClient.makeKsqlRequest("Test request"); assertThat(results, is(notNullValue())); assertThat(results.isSuccessful(), is(true)); final KsqlEntityList ksqlEntityList = results.getResponse(); assertThat(ksqlEntityList, hasSize(1)); assertThat(ksqlEntityList.get(0), is(instanceOf(ExecutionPlan.class))); }
@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)); }
private int canMakeCliRequest(final String username, final String password) { try (KsqlRestClient restClient = new KsqlRestClient(REST_APP.getHttpListener().toString())) { if (!username.isEmpty()) { restClient.setupAuthenticationCredentials(username, password); } final RestResponse<ServerInfo> response = restClient.getServerInfo(); if (response.isSuccessful()) { return Code.OK.getCode(); } return response.getErrorMessage().getErrorCode(); } }
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 testStatus() { // When: final RestResponse<CommandStatuses> response = ksqlRestClient.makeStatusRequest(); // Then: assertThat(response, is(notNullValue())); assertThat(response.isSuccessful(), is(true)); assertThat(response.getResponse(), is(new CommandStatuses(ImmutableMap.of( new CommandId(CommandId.Type.TOPIC, "c1", CommandId.Action.CREATE), CommandStatus.Status.SUCCESS, new CommandId(CommandId.Type.TOPIC, "c2", CommandId.Action.CREATE), CommandStatus.Status.ERROR )))); }
private static void runStatement(final String statement, final KsqlRestClient restClient) { final RestResponse response = restClient.makeKsqlRequest(statement); Assert.assertThat(response.isSuccessful(), is(true)); final KsqlEntityList entityList = ((KsqlEntityList) response.get()); Assert.assertThat(entityList.size(), equalTo(1)); Assert.assertThat(entityList.get(0), instanceOf(CommandStatusEntity.class)); final CommandStatusEntity entity = (CommandStatusEntity) entityList.get(0); final CommandStatus status = entity.getCommandStatus(); Assert.assertThat(status, not(CommandStatus.Status.ERROR)); if (status.getStatus() != Status.SUCCESS) { assertThatEventually( "", () -> { final RestResponse statusResponse = restClient .makeStatusRequest(entity.getCommandId().toString()); Assert.assertThat(statusResponse.isSuccessful(), is(true)); Assert.assertThat(statusResponse.get(), instanceOf(CommandStatus.class)); return ((CommandStatus) statusResponse.get()).getStatus(); }, anyOf( is(CommandStatus.Status.SUCCESS), is(CommandStatus.Status.TERMINATED), is(CommandStatus.Status.ERROR)), 120, TimeUnit.SECONDS ); } }