Search in sources :

Example 1 with Callback

use of io.cdap.cdap.logging.read.Callback in project cdap by caskdata.

the class AbstractLogHttpHandler method doPrev.

protected void doPrev(LogReader logReader, HttpResponder responder, LoggingContext loggingContext, int maxEvents, String fromOffsetStr, boolean escape, String filterStr, @Nullable RunRecordDetail runRecord, String format, List<String> fieldsToSuppress) {
    try {
        Filter filter = FilterParser.parse(filterStr);
        Callback logCallback = getNextOrPrevLogsCallback(format, responder, fieldsToSuppress, escape);
        LogOffset logOffset = FormattedTextLogEvent.parseLogOffset(fromOffsetStr);
        ReadRange readRange = ReadRange.createToRange(logOffset);
        readRange = adjustReadRange(readRange, runRecord, true);
        try {
            logReader.getLogPrev(loggingContext, readRange, maxEvents, filter, logCallback);
        } catch (Exception ex) {
            LOG.debug("Exception while reading logs for logging context {}", loggingContext, ex);
        } finally {
            logCallback.close();
        }
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (IllegalArgumentException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    }
}
Also used : Callback(io.cdap.cdap.logging.read.Callback) ReadRange(io.cdap.cdap.logging.read.ReadRange) Filter(io.cdap.cdap.logging.filter.Filter) LogOffset(io.cdap.cdap.logging.read.LogOffset)

Example 2 with Callback

use of io.cdap.cdap.logging.read.Callback in project cdap by caskdata.

the class AbstractLogHttpHandler method doNext.

protected void doNext(LogReader logReader, HttpResponder responder, LoggingContext loggingContext, int maxEvents, String fromOffsetStr, boolean escape, String filterStr, @Nullable RunRecordDetail runRecord, String format, List<String> fieldsToSuppress) {
    try {
        Filter filter = FilterParser.parse(filterStr);
        Callback logCallback = getNextOrPrevLogsCallback(format, responder, fieldsToSuppress, escape);
        LogOffset logOffset = FormattedTextLogEvent.parseLogOffset(fromOffsetStr);
        ReadRange readRange = ReadRange.createFromRange(logOffset);
        readRange = adjustReadRange(readRange, runRecord, true);
        try {
            logReader.getLogNext(loggingContext, readRange, maxEvents, filter, logCallback);
        } catch (Exception ex) {
            LOG.debug("Exception while reading logs for logging context {}", loggingContext, ex);
        } finally {
            logCallback.close();
        }
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (IllegalArgumentException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    }
}
Also used : Callback(io.cdap.cdap.logging.read.Callback) ReadRange(io.cdap.cdap.logging.read.ReadRange) Filter(io.cdap.cdap.logging.filter.Filter) LogOffset(io.cdap.cdap.logging.read.LogOffset)

Aggregations

Filter (io.cdap.cdap.logging.filter.Filter)2 Callback (io.cdap.cdap.logging.read.Callback)2 LogOffset (io.cdap.cdap.logging.read.LogOffset)2 ReadRange (io.cdap.cdap.logging.read.ReadRange)2