org.apache.flume.source.avro.AvroFlumeEvent Java Examples

The following examples show how to use org.apache.flume.source.avro.AvroFlumeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PulsarSink.java    From pulsar-flume-ng-sink with Apache License 2.0 6 votes vote down vote up
private byte[] serializeEvent(Event event, boolean useAvroEventFormat) throws IOException {
    byte[] bytes;
    if (useAvroEventFormat) {
        if (!tempOutStream.isPresent()) {
            tempOutStream = Optional.of(new ByteArrayOutputStream());
        }
        if (!writer.isPresent()) {
            writer = Optional.of(new SpecificDatumWriter<AvroFlumeEvent>(AvroFlumeEvent.class));
        }
        tempOutStream.get().reset();
        AvroFlumeEvent e = new AvroFlumeEvent(toCharSeqMap(event.getHeaders()),
                ByteBuffer.wrap(event.getBody()));
        encoder = EncoderFactory.get().directBinaryEncoder(tempOutStream.get(), encoder);
        writer.get().write(e, encoder);
        encoder.flush();
        bytes = tempOutStream.get().toByteArray();
    } else {
        bytes = event.getBody();
    }
    return bytes;
}
 
Example #2
Source File: AvroSource.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
@Override
public Status append(AvroFlumeEvent avroEvent) {
  logger.debug("Avro source {}: Received avro event: {}", getName(),
      avroEvent);
  sourceCounter.incrementAppendReceivedCount();
  sourceCounter.incrementEventReceivedCount();

  Event event = EventBuilder.withBody(avroEvent.getBody().array(),
      toStringMap(avroEvent.getHeaders()));

  try {
    getChannelProcessor().processEvent(event);
  } catch (ChannelException ex) {
    logger.warn("Avro source " + getName() + ": Unable to process event. " +
        "Exception follows.", ex);
    return Status.FAILED;
  }

  sourceCounter.incrementAppendAcceptedCount();
  sourceCounter.incrementEventAcceptedCount();

  return Status.OK;
}
 
Example #3
Source File: TestLoadBalancingLog4jAppender.java    From kite with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) {
  if (isFail) {
    return Status.FAILED;
  }
  appendCount.addAndGet(events.size());
  return super.appendBatch(events);
}
 
Example #4
Source File: TestEmbeddedAgent.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
public Event poll() {
  AvroFlumeEvent avroEvent = eventQueue.poll();
  if(avroEvent != null) {
    return EventBuilder.withBody(avroEvent.getBody().array(),
        toStringMap(avroEvent.getHeaders()));
  }
  return null;
}
 
Example #5
Source File: TestLoadBalancingLog4jAppender.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) {
  if (isFail) {
    return Status.FAILED;
  }
  appendCount.addAndGet(events.size());
  return super.appendBatch(events);
}
 
Example #6
Source File: TestLoadBalancingLog4jAppender.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status append(AvroFlumeEvent avroEvent) {
  if (isFail) {
    return Status.FAILED;
  }
  appendCount.incrementAndGet();
  return super.append(avroEvent);
}
 
Example #7
Source File: FlumeEmbeddedAgentTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public Event poll() {

            AvroFlumeEvent avroEvent = null;
            try {
                avroEvent = eventQueue.poll(30000, TimeUnit.MILLISECONDS);
            } catch (final InterruptedException ie) {
                // Ignore the exception.
            }
            if (avroEvent != null) {
                return EventBuilder.withBody(avroEvent.getBody().array(), toStringMap(avroEvent.getHeaders()));
            }
            System.out.println("No Event returned");
            return null;
        }
 
Example #8
Source File: TestAvroSink.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events)
    throws AvroRemoteException {
  logger.debug("Received event batch:{}; delaying for {}ms", events, delay);
  sleep();
  return Status.OK;
}
 
Example #9
Source File: AvroSource.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) {
  logger.debug("Avro source {}: Received avro event batch of {} events.",
      getName(), events.size());
  sourceCounter.incrementAppendBatchReceivedCount();
  sourceCounter.addToEventReceivedCount(events.size());

  List<Event> batch = new ArrayList<Event>();

  for (AvroFlumeEvent avroEvent : events) {
    Event event = EventBuilder.withBody(avroEvent.getBody().array(),
        toStringMap(avroEvent.getHeaders()));

    batch.add(event);
  }

  try {
    getChannelProcessor().processEventBatch(batch);
  } catch (Throwable t) {
    logger.error("Avro source " + getName() + ": Unable to process event " +
        "batch. Exception follows.", t);
    if (t instanceof Error) {
      throw (Error) t;
    }
    return Status.FAILED;
  }

  sourceCounter.incrementAppendBatchAcceptedCount();
  sourceCounter.addToEventAcceptedCount(events.size());

  return Status.OK;
}
 
Example #10
Source File: RpcTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) throws
    AvroRemoteException {
  logger.info("Throwing: Received {} events from appendBatch()",
      events.size());
  throw new AvroRemoteException("Handler smash!");
}
 
Example #11
Source File: FlumePersistentPerf.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public Event poll() {

            AvroFlumeEvent avroEvent = null;
            try {
                avroEvent = eventQueue.poll(30000, TimeUnit.MILLISECONDS);
            } catch (final InterruptedException ie) {
                // Ignore the exception.
            }
            if (avroEvent != null) {
                return EventBuilder.withBody(avroEvent.getBody().array(), toStringMap(avroEvent.getHeaders()));
            }
            System.out.println("No Event returned");
            return null;
        }
 
Example #12
Source File: RpcTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) throws
    AvroRemoteException {
  logger.info("Unknown: Received {} events from appendBatch()",
      events.size());
  return Status.UNKNOWN;
}
 
Example #13
Source File: RpcTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) throws
    AvroRemoteException {
  logger.info("Failed: Received {} events from appendBatch()",
      events.size());
  return Status.FAILED;
}
 
Example #14
Source File: RpcTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) throws
    AvroRemoteException {
  logger.info("OK: Received {} events from appendBatch()",
      events.size());
  return Status.OK;
}
 
Example #15
Source File: FlumeEmbeddedAppenderTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public Event poll() {

            AvroFlumeEvent avroEvent = null;
            try {
                avroEvent = eventQueue.poll(30000, TimeUnit.MILLISECONDS);
            } catch (final InterruptedException ie) {
                // Ignore the exception.
            }
            if (avroEvent != null) {
                return EventBuilder.withBody(avroEvent.getBody().array(), toStringMap(avroEvent.getHeaders()));
            }
            System.out.println("No Event returned");
            return null;
        }
 
Example #16
Source File: RpcTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events) throws
    AvroRemoteException {
  if (failed) {
    logger.debug("Event batch rejected");
    return Status.FAILED;
  }
  logger.debug("LB: Received {} events from appendBatch()",
      events.size());

  appendBatchCount++;
  return Status.OK;
}
 
Example #17
Source File: RpcTestUtils.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public Status append(AvroFlumeEvent event) throws AvroRemoteException {
  if (failed) {
    logger.debug("Event rejected");
    return Status.FAILED;
  }
  logger.debug("LB: Received event from append(): {}",
      new String(event.getBody().array(), Charset.forName("UTF8")));
  appendCount++;
  return Status.OK;
}
 
Example #18
Source File: TestLoadBalancingLog4jAppender.java    From kite with Apache License 2.0 5 votes vote down vote up
@Override
public Status append(AvroFlumeEvent avroEvent) {
  if (isFail) {
    return Status.FAILED;
  }
  appendCount.incrementAndGet();
  return super.append(avroEvent);
}
 
Example #19
Source File: FakeFlume.java    From incubator-retired-htrace with Apache License 2.0 5 votes vote down vote up
private void start() {
  flumeServer = RpcTestUtils.startServer(new AvroSourceProtocol(){

    @Override
    public Status append(AvroFlumeEvent event) throws AvroRemoteException {
      return protocol.append(event);
    }

    @Override
    public Status appendBatch(List<AvroFlumeEvent> events) throws AvroRemoteException {
      return protocol.appendBatch(events);
    }
  });
}
 
Example #20
Source File: FlumePersistentAppenderTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Status appendBatch(final List<AvroFlumeEvent> events) throws AvroRemoteException {
    Preconditions.checkState(eventQueue.addAll(events));
    for (final AvroFlumeEvent event : events) {
        // System.out.println("Received event " + event.getHeaders().get(new org.apache.avro.util.Utf8(FlumeEvent.GUID)));
    }
    return Status.OK;
}
 
Example #21
Source File: FlumePersistentAppenderTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public Event poll() {

            AvroFlumeEvent avroEvent = null;
            try {
                avroEvent = eventQueue.poll(30000, TimeUnit.MILLISECONDS);
            } catch (final InterruptedException ie) {
                // Ignore the exception.
            }
            if (avroEvent != null) {
                return EventBuilder.withBody(avroEvent.getBody().array(), toStringMap(avroEvent.getHeaders()));
            }
            System.out.println("No Event returned");
            return null;
        }
 
Example #22
Source File: TestAvroSink.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@Override
public Status append(AvroFlumeEvent event) throws AvroRemoteException {
  logger.debug("Received event:{}; delaying for {}ms", event, delay);
  sleep();
  return Status.OK;
}
 
Example #23
Source File: FlumePersistentPerf.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status appendBatch(final List<AvroFlumeEvent> events)
    throws AvroRemoteException {
    Preconditions.checkState(eventQueue.addAll(events));
    return Status.OK;
}
 
Example #24
Source File: TestEmbeddedAgent.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@Override
public Status appendBatch(List<AvroFlumeEvent> events)
    throws AvroRemoteException {
  Preconditions.checkState(eventQueue.addAll(events));
  return Status.OK;
}
 
Example #25
Source File: FlumePersistentAppenderTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status append(final AvroFlumeEvent event) throws AvroRemoteException {
    eventQueue.add(event);
    //System.out.println("Received event " + event.getHeaders().get(new org.apache.avro.util.Utf8(FlumeEvent.GUID)));
    return Status.OK;
}
 
Example #26
Source File: FlumeEmbeddedAgentTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status append(final AvroFlumeEvent event) throws AvroRemoteException {
    eventQueue.add(event);
    return Status.OK;
}
 
Example #27
Source File: FlumeEmbeddedAgentTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status appendBatch(final List<AvroFlumeEvent> events)
    throws AvroRemoteException {
    Preconditions.checkState(eventQueue.addAll(events));
    return Status.OK;
}
 
Example #28
Source File: FlumeEmbeddedAppenderTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status appendBatch(final List<AvroFlumeEvent> events)
    throws AvroRemoteException {
    Preconditions.checkState(eventQueue.addAll(events));
    return Status.OK;
}
 
Example #29
Source File: FlumeEmbeddedAppenderTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status append(final AvroFlumeEvent event) throws AvroRemoteException {
    eventQueue.add(event);
    return Status.OK;
}
 
Example #30
Source File: FlumePersistentPerf.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Status append(final AvroFlumeEvent event) throws AvroRemoteException {
    eventQueue.add(event);
    return Status.OK;
}