use of co.cask.cdap.logging.read.ReadRange in project cdap by caskdata.
the class TestDistributedLogReader method testDistributedLogPrevBoth.
@Test
public void testDistributedLogPrevBoth() throws Exception {
ReadRange readRange = new ReadRange(0, Long.MAX_VALUE, LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogPrev(readRange, LOGGING_CONTEXT_BOTH, 16, 4, "TestDistributedLogReader Log message1 ", 60);
readRange = new ReadRange(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1), System.currentTimeMillis(), LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogPrev(readRange, LOGGING_CONTEXT_BOTH, 16, 4, "TestDistributedLogReader Log message1 ", 60);
testDistributedLogPrev(ReadRange.LATEST, LOGGING_CONTEXT_BOTH, 9, 8, "TestDistributedLogReader Log message1 ", 60);
}
use of co.cask.cdap.logging.read.ReadRange in project cdap by caskdata.
the class TestDistributedLogReader method testDistributedLogPrevKafka.
@Test
public void testDistributedLogPrevKafka() throws Exception {
ReadRange readRange = new ReadRange(0, Long.MAX_VALUE, LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogPrev(readRange, LOGGING_CONTEXT_KAFKA, 5, 6, "TestDistributedLogReader Log message3 ", 30);
readRange = new ReadRange(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1), System.currentTimeMillis(), LogOffset.INVALID_KAFKA_OFFSET);
testDistributedLogPrev(readRange, LOGGING_CONTEXT_KAFKA, 5, 6, "TestDistributedLogReader Log message3 ", 30);
testDistributedLogPrev(ReadRange.LATEST, LOGGING_CONTEXT_KAFKA, 5, 6, "TestDistributedLogReader Log message3 ", 30);
}
use of co.cask.cdap.logging.read.ReadRange in project cdap by caskdata.
the class MockLogReader method getLog.
@Override
public CloseableIterator<LogEvent> getLog(LoggingContext loggingContext, long fromTimeMs, long toTimeMs, Filter filter) {
CollectingCallback collectingCallback = new CollectingCallback();
// since its just for test case, we don't need to lazily read logs (which is the purpose of returning an Iterator)
long fromOffset = getOffset(fromTimeMs / 1000);
long toOffset = getOffset(toTimeMs / 1000);
getLogNext(loggingContext, new ReadRange(fromTimeMs, toTimeMs, fromOffset), (int) (toOffset - fromOffset), filter, collectingCallback);
final Iterator<LogEvent> iterator = collectingCallback.getLogEvents().iterator();
return new CloseableIterator<LogEvent>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public LogEvent next() {
return iterator.next();
}
@Override
public void remove() {
iterator.remove();
}
@Override
public void close() {
// no-op
}
};
}
use of co.cask.cdap.logging.read.ReadRange in project cdap by caskdata.
the class AbstractLogHandler method doNext.
protected void doNext(HttpResponder responder, LoggingContext loggingContext, int maxEvents, String fromOffsetStr, boolean escape, String filterStr, @Nullable RunRecordMeta 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 co.cask.cdap.logging.read.ReadRange in project cdap by caskdata.
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