Search in sources :

Example 1 with HttpChunkedResponseSocket

use of io.questdb.cutlass.http.HttpChunkedResponseSocket in project questdb by bluestreak01.

the class PrometheusMetricsProcessor method onRequestComplete.

@Override
public void onRequestComplete(HttpConnectionContext context) throws PeerDisconnectedException, PeerIsSlowToReadException {
    HttpChunkedResponseSocket r = context.getChunkedResponseSocket();
    r.status(200, CONTENT_TYPE_TEXT);
    r.sendHeader();
    metrics.scrapeIntoPrometheus(r);
    r.done();
}
Also used : HttpChunkedResponseSocket(io.questdb.cutlass.http.HttpChunkedResponseSocket)

Example 2 with HttpChunkedResponseSocket

use of io.questdb.cutlass.http.HttpChunkedResponseSocket in project questdb by bluestreak01.

the class TableStatusCheckProcessor method onRequestComplete.

@Override
public void onRequestComplete(HttpConnectionContext context) throws PeerDisconnectedException, PeerIsSlowToReadException {
    CharSequence tableName = context.getRequestHeader().getUrlParam("j");
    if (tableName == null) {
        context.simpleResponse().sendStatus(200, "table name missing");
    } else {
        int check = cairoEngine.getStatus(context.getCairoSecurityContext(), path, tableName);
        if (Chars.equalsNc("json", context.getRequestHeader().getUrlParam("f"))) {
            HttpChunkedResponseSocket r = context.getChunkedResponseSocket();
            r.status(200, "application/json");
            r.headers().put(keepAliveHeader);
            r.sendHeader();
            r.put('{').putQuoted("status").put(':').putQuoted(toResponse(check)).put('}');
            r.sendChunk(true);
        } else {
            context.simpleResponse().sendStatus(200, toResponse(check));
        }
    }
}
Also used : HttpChunkedResponseSocket(io.questdb.cutlass.http.HttpChunkedResponseSocket)

Example 3 with HttpChunkedResponseSocket

use of io.questdb.cutlass.http.HttpChunkedResponseSocket in project questdb by bluestreak01.

the class JsonQueryProcessorState method of.

boolean of(RecordCursorFactory factory, SqlExecutionContextImpl sqlExecutionContext) throws PeerDisconnectedException, PeerIsSlowToReadException, SqlException {
    this.recordCursorFactory = factory;
    queryCacheable = true;
    this.cursor = factory.getCursor(sqlExecutionContext);
    final RecordMetadata metadata = factory.getMetadata();
    HttpRequestHeader header = httpConnectionContext.getRequestHeader();
    DirectByteCharSequence columnNames = header.getUrlParam("cols");
    int columnCount;
    columnSkewList.clear();
    if (columnNames != null) {
        columnsQueryParameter.clear();
        try {
            TextUtil.utf8Decode(columnNames.getLo(), columnNames.getHi(), columnsQueryParameter);
        } catch (Utf8Exception e) {
            info().$("utf8 error when decoding column list '").$(columnNames).$('\'').$();
            HttpChunkedResponseSocket socket = getHttpConnectionContext().getChunkedResponseSocket();
            JsonQueryProcessor.header(socket, "");
            socket.put('{').putQuoted("error").put(':').putQuoted("utf8 error in column list");
            socket.put('}');
            socket.sendChunk(true);
            return false;
        }
        columnCount = 1;
        int start = 0;
        int comma = 0;
        while (comma > -1) {
            comma = Chars.indexOf(columnsQueryParameter, start, ',');
            if (comma > -1) {
                if (addColumnToOutput(metadata, columnsQueryParameter, start, comma)) {
                    return false;
                }
                start = comma + 1;
                columnCount++;
            } else {
                int hi = columnsQueryParameter.length();
                if (addColumnToOutput(metadata, columnsQueryParameter, start, hi)) {
                    return false;
                }
            }
        }
    } else {
        columnCount = metadata.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            addColumnTypeAndName(metadata, i);
        }
    }
    this.columnCount = columnCount;
    return true;
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) HttpChunkedResponseSocket(io.questdb.cutlass.http.HttpChunkedResponseSocket) DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) HttpRequestHeader(io.questdb.cutlass.http.HttpRequestHeader) Utf8Exception(io.questdb.cutlass.text.Utf8Exception)

Example 4 with HttpChunkedResponseSocket

use of io.questdb.cutlass.http.HttpChunkedResponseSocket in project questdb by bluestreak01.

the class HealthCheckProcessor method onRequestComplete.

@Override
public void onRequestComplete(HttpConnectionContext context) throws PeerDisconnectedException, PeerIsSlowToReadException {
    HttpChunkedResponseSocket r = context.getChunkedResponseSocket();
    r.status(200, "text/plain");
    r.sendHeader();
    r.done();
}
Also used : HttpChunkedResponseSocket(io.questdb.cutlass.http.HttpChunkedResponseSocket)

Example 5 with HttpChunkedResponseSocket

use of io.questdb.cutlass.http.HttpChunkedResponseSocket in project questdb by bluestreak01.

the class JsonQueryProcessorState method addColumnToOutput.

private boolean addColumnToOutput(RecordMetadata metadata, CharSequence columnNames, int start, int hi) throws PeerDisconnectedException, PeerIsSlowToReadException {
    if (start == hi) {
        info().$("empty column in list '").$(columnNames).$('\'').$();
        HttpChunkedResponseSocket socket = getHttpConnectionContext().getChunkedResponseSocket();
        JsonQueryProcessor.header(socket, "");
        socket.put('{').putQuoted("query").put(':').encodeUtf8AndQuote(query).put(',').putQuoted("error").put(':').putQuoted("empty column in list");
        socket.put('}');
        socket.sendChunk(true);
        return true;
    }
    int columnIndex = metadata.getColumnIndexQuiet(columnNames, start, hi);
    if (columnIndex == RecordMetadata.COLUMN_NOT_FOUND) {
        info().$("invalid column in list: '").$(columnNames, start, hi).$('\'').$();
        HttpChunkedResponseSocket socket = getHttpConnectionContext().getChunkedResponseSocket();
        JsonQueryProcessor.header(socket, "");
        socket.put('{').putQuoted("query").put(':').encodeUtf8AndQuote(query).put(',').putQuoted("error").put(':').put('\'').put("invalid column in list: ").put(columnNames, start, hi).put('\'');
        socket.put('}');
        socket.sendChunk(true);
        return true;
    }
    addColumnTypeAndName(metadata, columnIndex);
    this.columnSkewList.add(columnIndex);
    return false;
}
Also used : HttpChunkedResponseSocket(io.questdb.cutlass.http.HttpChunkedResponseSocket)

Aggregations

HttpChunkedResponseSocket (io.questdb.cutlass.http.HttpChunkedResponseSocket)5 RecordMetadata (io.questdb.cairo.sql.RecordMetadata)1 HttpRequestHeader (io.questdb.cutlass.http.HttpRequestHeader)1 Utf8Exception (io.questdb.cutlass.text.Utf8Exception)1 DirectByteCharSequence (io.questdb.std.str.DirectByteCharSequence)1