Search in sources :

Example 1 with PutLogEventsRequest

use of com.amazonaws.services.logs.model.PutLogEventsRequest in project cas by apereo.

the class CloudWatchAppender method flush.

private void flush() {
    int drained;
    final List<InputLogEvent> logEvents = new ArrayList<>(AWS_DRAIN_LIMIT);
    do {
        drained = queue.drainTo(logEvents, AWS_DRAIN_LIMIT);
        if (logEvents.isEmpty()) {
            break;
        }
        logEvents.sort(Comparator.comparing(InputLogEvent::getTimestamp));
        if (lastReportedTimestamp > 0) {
            for (final InputLogEvent event : logEvents) {
                if (event.getTimestamp() < lastReportedTimestamp) {
                    event.setTimestamp(lastReportedTimestamp);
                }
            }
        }
        lastReportedTimestamp = logEvents.get(logEvents.size() - 1).getTimestamp();
        final PutLogEventsRequest putLogEventsRequest = new PutLogEventsRequest(logGroupName, logStreamName, logEvents);
        putLogEventsRequest.setSequenceToken(sequenceTokenCache);
        try {
            final PutLogEventsResult putLogEventsResult = awsLogsClient.putLogEvents(putLogEventsRequest);
            sequenceTokenCache = putLogEventsResult.getNextSequenceToken();
        } catch (final DataAlreadyAcceptedException daae) {
            sequenceTokenCache = daae.getExpectedSequenceToken();
        } catch (final InvalidSequenceTokenException iste) {
            sequenceTokenCache = iste.getExpectedSequenceToken();
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        logEvents.clear();
    } while (drained >= AWS_DRAIN_LIMIT);
}
Also used : InvalidSequenceTokenException(com.amazonaws.services.logs.model.InvalidSequenceTokenException) InputLogEvent(com.amazonaws.services.logs.model.InputLogEvent) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) ArrayList(java.util.ArrayList) DataAlreadyAcceptedException(com.amazonaws.services.logs.model.DataAlreadyAcceptedException) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) InvalidSequenceTokenException(com.amazonaws.services.logs.model.InvalidSequenceTokenException) DataAlreadyAcceptedException(com.amazonaws.services.logs.model.DataAlreadyAcceptedException)

Aggregations

DataAlreadyAcceptedException (com.amazonaws.services.logs.model.DataAlreadyAcceptedException)1 InputLogEvent (com.amazonaws.services.logs.model.InputLogEvent)1 InvalidSequenceTokenException (com.amazonaws.services.logs.model.InvalidSequenceTokenException)1 PutLogEventsRequest (com.amazonaws.services.logs.model.PutLogEventsRequest)1 PutLogEventsResult (com.amazonaws.services.logs.model.PutLogEventsResult)1 ArrayList (java.util.ArrayList)1