Search in sources :

Example 6 with ReadRange

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);
}
Also used : ReadRange(co.cask.cdap.logging.read.ReadRange) Test(org.junit.Test)

Example 7 with ReadRange

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);
}
Also used : ReadRange(co.cask.cdap.logging.read.ReadRange) Test(org.junit.Test)

Example 8 with ReadRange

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
        }
    };
}
Also used : CloseableIterator(co.cask.cdap.api.dataset.lib.CloseableIterator) ReadRange(co.cask.cdap.logging.read.ReadRange) LogEvent(co.cask.cdap.logging.read.LogEvent)

Example 9 with ReadRange

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());
    }
}
Also used : Callback(co.cask.cdap.logging.read.Callback) ReadRange(co.cask.cdap.logging.read.ReadRange) Filter(co.cask.cdap.logging.filter.Filter) LogOffset(co.cask.cdap.logging.read.LogOffset)

Example 10 with ReadRange

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);
}
Also used : ReadRange(co.cask.cdap.logging.read.ReadRange) Test(org.junit.Test)

Aggregations

ReadRange (co.cask.cdap.logging.read.ReadRange)12 Test (org.junit.Test)6 Filter (co.cask.cdap.logging.filter.Filter)4 LogEvent (co.cask.cdap.logging.read.LogEvent)3 Callback (co.cask.cdap.logging.read.Callback)2 LogOffset (co.cask.cdap.logging.read.LogOffset)2 CloseableIterator (co.cask.cdap.api.dataset.lib.CloseableIterator)1