use of io.cdap.cdap.logging.read.ReadRange 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());
}
}
use of io.cdap.cdap.logging.read.ReadRange 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());
}
}
use of io.cdap.cdap.logging.read.ReadRange in project cdap by caskdata.
the class AbstractLogHttpHandler method doGetLogs.
protected void doGetLogs(LogReader logReader, HttpResponder responder, LoggingContext loggingContext, long fromTimeSecsParam, long toTimeSecsParam, boolean escape, String filterStr, @Nullable RunRecordDetail runRecord, String format, List<String> fieldsToSuppress) {
try {
TimeRange timeRange = parseTime(fromTimeSecsParam, toTimeSecsParam, responder);
if (timeRange == null) {
return;
}
Filter filter = FilterParser.parse(filterStr);
ReadRange readRange = new ReadRange(timeRange.getFromMillis(), timeRange.getToMillis(), LogOffset.INVALID_KAFKA_OFFSET);
readRange = adjustReadRange(readRange, runRecord, fromTimeSecsParam != -1);
try {
// the iterator is closed by the BodyProducer passed to the HttpResponder
CloseableIterator<LogEvent> logIter = logReader.getLog(loggingContext, readRange.getFromMillis(), readRange.getToMillis(), filter);
AbstractChunkedLogProducer logsProducer = getFullLogsProducer(format, logIter, fieldsToSuppress, escape);
responder.sendContent(HttpResponseStatus.OK, logsProducer, logsProducer.getResponseHeaders());
} catch (Exception ex) {
LOG.debug("Exception while reading logs for logging context {}", loggingContext, ex);
responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
} catch (IllegalArgumentException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
}
}
use of io.cdap.cdap.logging.read.ReadRange in project cdap by cdapio.
the class TestDistributedLogReader method testDistributedLogNextBoth.
@Test
public void testDistributedLogNextBoth() throws Exception {
ReadRange readRange = new ReadRange(0, Long.MAX_VALUE, LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogNext(readRange, LOGGING_CONTEXT_BOTH, 20, 3, "TestDistributedLogReader Log message1 ", 60, 0);
readRange = new ReadRange(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1), System.currentTimeMillis(), LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogNext(readRange, LOGGING_CONTEXT_BOTH, 20, 3, "TestDistributedLogReader Log message1 ", 60, 0);
testDistributedLogNext(ReadRange.LATEST, LOGGING_CONTEXT_BOTH, 1, 3, "TestDistributedLogReader Log message1 ", 3, 57);
}
use of io.cdap.cdap.logging.read.ReadRange in project cdap by cdapio.
the class TestDistributedLogReader method testDistributedLogNextKafka.
@Test
public void testDistributedLogNextKafka() throws Exception {
ReadRange readRange = new ReadRange(0, Long.MAX_VALUE, LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogNext(readRange, LOGGING_CONTEXT_KAFKA, 10, 3, "TestDistributedLogReader Log message3 ", 30, 0);
readRange = new ReadRange(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1), System.currentTimeMillis(), LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogNext(readRange, LOGGING_CONTEXT_KAFKA, 10, 3, "TestDistributedLogReader Log message3 ", 30, 0);
testDistributedLogNext(ReadRange.LATEST, LOGGING_CONTEXT_KAFKA, 1, 8, "TestDistributedLogReader Log message3 ", 8, 22);
}
Aggregations