Search in sources :

Example 1 with KsqlClientException

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

the class ClientImpl method handleErrorResponse.

private static <T extends CompletableFuture<?>> void handleErrorResponse(final HttpClientResponse response, final T cf) {
    response.bodyHandler(buffer -> {
        final JsonObject errorResponse = buffer.toJsonObject();
        cf.completeExceptionally(new KsqlClientException(String.format("Received %d response from server: %s. Error code: %d", response.statusCode(), errorResponse.getString("message"), errorResponse.getInteger("error_code"))));
    });
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with KsqlClientException

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

the class StreamInsertsResponseHandler method doHandleBodyBuffer.

@Override
protected void doHandleBodyBuffer(final Buffer buff) {
    final JsonObject jsonObject = new JsonObject(buff);
    final long seqNum = jsonObject.getLong("seq");
    final String status = jsonObject.getString("status");
    if ("ok".equals(status)) {
        final InsertAck ack = new InsertAckImpl(seqNum);
        final boolean full = acksPublisher.accept(ack);
        if (full && !paused) {
            recordParser.pause();
            acksPublisher.drainHandler(this::publisherReceptive);
            paused = true;
        }
    } else if ("error".equals(status)) {
        acksPublisher.handleError(new KsqlClientException(String.format("Received error from /inserts-stream. Inserts sequence number: %d. " + "Error code: %d. Message: %s", seqNum, jsonObject.getInteger("error_code"), jsonObject.getString("message"))));
    } else {
        throw new IllegalStateException("Unrecognized status response from /inserts-stream: " + status);
    }
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) InsertAck(io.confluent.ksql.api.client.InsertAck) JsonObject(io.vertx.core.json.JsonObject)

Example 3 with KsqlClientException

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

the class ExecuteQueryResponseHandler method handleRow.

@Override
protected void handleRow(final Buffer buff) {
    final Row row;
    final Object json = buff.toJson();
    if (json instanceof JsonObject) {
        final JsonObject jsonObject = (JsonObject) json;
        // Don't add it to the result list since the user should not see it
        if (jsonObject.getMap() != null && jsonObject.getMap().containsKey("consistencyToken")) {
            log.info("Response contains consistency vector " + jsonObject);
            serializedConsistencyVector.set((String) ((JsonObject) json).getMap().get("consistencyToken"));
        } else {
            throw new RuntimeException("Could not decode JSON, expected consistency toke: " + json);
        }
    } else if (json instanceof JsonArray) {
        final JsonArray values = new JsonArray(buff);
        if (rows.size() < maxRows) {
            rows.add(new RowImpl(columnNames, columnTypes, values, columnNameToIndex));
        } else {
            throw new KsqlClientException("Reached max number of rows that may be returned by executeQuery(). " + "Increase the limit via ClientOptions#setExecuteQueryMaxResultRows(). " + "Current limit: " + maxRows);
        }
    } else {
        throw new RuntimeException("Could not decode JSON: " + json);
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Row(io.confluent.ksql.api.client.Row)

Example 4 with KsqlClientException

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

the class InsertIntoResponseHandler method doHandleBodyBuffer.

@Override
protected void doHandleBodyBuffer(final Buffer buff) {
    final JsonObject jsonObject = new JsonObject(buff);
    final String status = jsonObject.getString("status");
    if ("ok".equals(status)) {
        numAcks++;
    } else if ("error".equals(status)) {
        cf.completeExceptionally(new KsqlClientException(String.format("Received error from /inserts-stream. Error code: %d. Message: %s", jsonObject.getInteger("error_code"), jsonObject.getString("message"))));
    } else {
        throw new IllegalStateException("Unrecognized status response from /inserts-stream: " + status);
    }
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)4 JsonObject (io.vertx.core.json.JsonObject)4 InsertAck (io.confluent.ksql.api.client.InsertAck)1 Row (io.confluent.ksql.api.client.Row)1 JsonArray (io.vertx.core.json.JsonArray)1