Search in sources :

Example 1 with LoggingEventSerializer

use of co.cask.cdap.logging.serialize.LoggingEventSerializer in project cdap by caskdata.

the class KafkaLogProcessorPipelineTest method publishLog.

private void publishLog(String topic, Iterable<ILoggingEvent> events, LoggingContext context) {
    KafkaPublisher.Preparer preparer = KAFKA_TESTER.getKafkaClient().getPublisher(KafkaPublisher.Ack.LEADER_RECEIVED, Compression.NONE).prepare(topic);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    for (ILoggingEvent event : events) {
        preparer.add(ByteBuffer.wrap(serializer.toBytes(new LogMessage(event, context))), context.getLogPartition());
    }
    preparer.send();
}
Also used : LogMessage(co.cask.cdap.logging.appender.LogMessage) LoggingEventSerializer(co.cask.cdap.logging.serialize.LoggingEventSerializer) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KafkaPublisher(org.apache.twill.kafka.client.KafkaPublisher)

Example 2 with LoggingEventSerializer

use of co.cask.cdap.logging.serialize.LoggingEventSerializer in project cdap by caskdata.

the class KafkaOffsetResolverTest method publishLog.

private void publishLog(String topic, Iterable<ILoggingEvent> events, LoggingContext context) {
    KafkaPublisher.Preparer preparer = KAFKA_TESTER.getKafkaClient().getPublisher(KafkaPublisher.Ack.LEADER_RECEIVED, Compression.NONE).prepare(topic);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    for (ILoggingEvent event : events) {
        preparer.add(ByteBuffer.wrap(serializer.toBytes(event)), context.getLogPartition());
    }
    preparer.send();
}
Also used : LoggingEventSerializer(co.cask.cdap.logging.serialize.LoggingEventSerializer) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KafkaPublisher(org.apache.twill.kafka.client.KafkaPublisher)

Example 3 with LoggingEventSerializer

use of co.cask.cdap.logging.serialize.LoggingEventSerializer in project cdap by caskdata.

the class DistributedLogFrameworkTest method publishLog.

/**
 * Publishes multiple log events.
 */
private void publishLog(String topic, LoggingContext context, Iterable<ILoggingEvent> events) {
    KafkaPublisher.Preparer preparer = KAFKA_TESTER.getKafkaClient().getPublisher(KafkaPublisher.Ack.LEADER_RECEIVED, Compression.NONE).prepare(topic);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    for (ILoggingEvent event : events) {
        preparer.add(ByteBuffer.wrap(serializer.toBytes(new LogMessage(event, context))), context.getLogPartition());
    }
    preparer.send();
}
Also used : LogMessage(co.cask.cdap.logging.appender.LogMessage) LoggingEventSerializer(co.cask.cdap.logging.serialize.LoggingEventSerializer) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KafkaPublisher(org.apache.twill.kafka.client.KafkaPublisher)

Example 4 with LoggingEventSerializer

use of co.cask.cdap.logging.serialize.LoggingEventSerializer in project cdap by caskdata.

the class TestKafkaLogging method convertFetchedMessage.

private Map.Entry<Integer, String> convertFetchedMessage(FetchedMessage message) throws IOException {
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    ILoggingEvent iLoggingEvent = serializer.fromBytes(message.getPayload());
    LoggingContext loggingContext = LoggingContextHelper.getLoggingContext(iLoggingEvent.getMDCPropertyMap());
    String key = loggingContext.getLogPartition();
    // Temporary map for pretty format
    Map<String, String> tempMap = new HashMap<>();
    tempMap.put("Timestamp", Long.toString(iLoggingEvent.getTimeStamp()));
    return Maps.immutableEntry(message.getTopicPartition().getPartition(), key);
}
Also used : LoggingContext(co.cask.cdap.common.logging.LoggingContext) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) HashMap(java.util.HashMap) LoggingEventSerializer(co.cask.cdap.logging.serialize.LoggingEventSerializer) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)4 LoggingEventSerializer (co.cask.cdap.logging.serialize.LoggingEventSerializer)4 KafkaPublisher (org.apache.twill.kafka.client.KafkaPublisher)3 LogMessage (co.cask.cdap.logging.appender.LogMessage)2 LoggingContext (co.cask.cdap.common.logging.LoggingContext)1 FlowletLoggingContext (co.cask.cdap.logging.context.FlowletLoggingContext)1 HashMap (java.util.HashMap)1