Search in sources :

Example 6 with EventDeliveryException

use of org.apache.flume.EventDeliveryException in project phoenix by apache.

the class RegexEventSerializerIT method testMismatchKeyGenerator.

@Test
public void testMismatchKeyGenerator() throws EventDeliveryException, SQLException {
    final String fullTableName = generateUniqueName();
    initSinkContextWithDefaults(fullTableName);
    setConfig(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_ROWKEY_TYPE_GENERATOR, DefaultKeyGenerator.UUID.name());
    sink = new PhoenixSink();
    Configurables.configure(sink, sinkContext);
    assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
    final Channel channel = this.initChannel();
    sink.setChannel(channel);
    sink.start();
    final String eventBody = "val1\tval2";
    final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
    // put event in channel
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    channel.put(event);
    transaction.commit();
    transaction.close();
    try {
        sink.process();
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getCause().getMessage().contains("java.lang.IllegalArgumentException: Invalid format:"));
    }
}
Also used : Transaction(org.apache.flume.Transaction) MemoryChannel(org.apache.flume.channel.MemoryChannel) Channel(org.apache.flume.Channel) Event(org.apache.flume.Event) SQLException(java.sql.SQLException) EventDeliveryException(org.apache.flume.EventDeliveryException) PhoenixSink(org.apache.phoenix.flume.sink.PhoenixSink) Test(org.junit.Test)

Example 7 with EventDeliveryException

use of org.apache.flume.EventDeliveryException in project phoenix by apache.

the class JsonEventSerializerIT method testMismatchKeyGenerator.

@Test
public void testMismatchKeyGenerator() throws EventDeliveryException, SQLException {
    final String fullTableName = "FLUME_JSON_TEST";
    initSinkContextWithDefaults(fullTableName);
    setConfig(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_ROWKEY_TYPE_GENERATOR, DefaultKeyGenerator.UUID.name());
    sink = new PhoenixSink();
    Configurables.configure(sink, sinkContext);
    assertEquals(LifecycleState.IDLE, sink.getLifecycleState());
    final Channel channel = this.initChannel();
    sink.setChannel(channel);
    sink.start();
    final String eventBody = "{\"col1\" : \"kalyan\", \"col2\" : 10.5, \"col3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}";
    final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody));
    // put event in channel
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    channel.put(event);
    transaction.commit();
    transaction.close();
    try {
        sink.process();
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getCause().getMessage().contains("java.lang.IllegalArgumentException: Invalid format:"));
    }
    dropTable(fullTableName);
}
Also used : Transaction(org.apache.flume.Transaction) MemoryChannel(org.apache.flume.channel.MemoryChannel) Channel(org.apache.flume.Channel) Event(org.apache.flume.Event) SQLException(java.sql.SQLException) EventDeliveryException(org.apache.flume.EventDeliveryException) PhoenixSink(org.apache.phoenix.flume.sink.PhoenixSink) Test(org.junit.Test)

Example 8 with EventDeliveryException

use of org.apache.flume.EventDeliveryException in project rocketmq-externals by apache.

the class RocketMQSourceTest method testEvent.

@Test
public void testEvent() throws EventDeliveryException, MQBrokerException, MQClientException, InterruptedException, UnsupportedEncodingException {
    // publish test message
    DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
    producer.setNamesrvAddr(nameServer);
    String sendMsg = "\"Hello Flume\"" + "," + DateFormatUtils.format(new Date(), "yyyy-MM-DD hh:mm:ss");
    try {
        producer.start();
        Message msg = new Message(TOPIC_DEFAULT, tag, sendMsg.getBytes("UTF-8"));
        SendResult sendResult = producer.send(msg);
        log.info("publish message : {}, sendResult:{}", sendMsg, sendResult);
    } catch (Exception e) {
        throw new MQClientException("Failed to publish messages", e);
    } finally {
        producer.shutdown();
    }
    // start source
    Context context = new Context();
    context.put(NAME_SERVER_CONFIG, nameServer);
    context.put(TAG_CONFIG, tag);
    Channel channel = new MemoryChannel();
    Configurables.configure(channel, context);
    List<Channel> channels = new ArrayList<>();
    channels.add(channel);
    ChannelSelector channelSelector = new ReplicatingChannelSelector();
    channelSelector.setChannels(channels);
    ChannelProcessor channelProcessor = new ChannelProcessor(channelSelector);
    RocketMQSource source = new RocketMQSource();
    source.setChannelProcessor(channelProcessor);
    Configurables.configure(source, context);
    source.start();
    PollableSource.Status status = source.process();
    if (status == PollableSource.Status.BACKOFF) {
        fail("Error");
    }
    /*
        wait for processQueueTable init
         */
    Thread.sleep(1000);
    source.stop();
    /*
        mock flume sink
         */
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    Event event = channel.take();
    if (event == null) {
        transaction.commit();
        fail("Error");
    }
    byte[] body = event.getBody();
    String receiveMsg = new String(body, "UTF-8");
    log.info("receive message : {}", receiveMsg);
    assertEquals(sendMsg, receiveMsg);
}
Also used : Context(org.apache.flume.Context) MemoryChannel(org.apache.flume.channel.MemoryChannel) Message(org.apache.rocketmq.common.message.Message) MemoryChannel(org.apache.flume.channel.MemoryChannel) Channel(org.apache.flume.Channel) ArrayList(java.util.ArrayList) ChannelProcessor(org.apache.flume.channel.ChannelProcessor) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) Date(java.util.Date) MQClientException(org.apache.rocketmq.client.exception.MQClientException) EventDeliveryException(org.apache.flume.EventDeliveryException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PollableSource(org.apache.flume.PollableSource) ReplicatingChannelSelector(org.apache.flume.channel.ReplicatingChannelSelector) Transaction(org.apache.flume.Transaction) SendResult(org.apache.rocketmq.client.producer.SendResult) Event(org.apache.flume.Event) ReplicatingChannelSelector(org.apache.flume.channel.ReplicatingChannelSelector) ChannelSelector(org.apache.flume.ChannelSelector) MQClientException(org.apache.rocketmq.client.exception.MQClientException) Test(org.junit.Test)

Example 9 with EventDeliveryException

use of org.apache.flume.EventDeliveryException in project cdap-ingest by caskdata.

the class CdapFlumeIT method writeEvents.

private void writeEvents(EmbeddedAgent agent, int startNumber, int endNumber) {
    for (int i = startNumber; i < endNumber; i++) {
        Event event = new SimpleEvent();
        event.setBody((EVENT_STR + i).getBytes());
        try {
            agent.put(event);
        } catch (EventDeliveryException ignored) {
        }
    }
}
Also used : SimpleEvent(org.apache.flume.event.SimpleEvent) EventDeliveryException(org.apache.flume.EventDeliveryException) Event(org.apache.flume.Event) SimpleEvent(org.apache.flume.event.SimpleEvent)

Example 10 with EventDeliveryException

use of org.apache.flume.EventDeliveryException in project ignite by apache.

the class IgniteSink method process.

/**
 * Processes Flume events.
 */
@Override
public Status process() throws EventDeliveryException {
    Channel channel = getChannel();
    Transaction transaction = channel.getTransaction();
    int eventCount = 0;
    try {
        transaction.begin();
        List<Event> batch = new ArrayList<>(batchSize);
        for (; eventCount < batchSize; ++eventCount) {
            Event event = channel.take();
            if (event == null) {
                break;
            }
            batch.add(event);
        }
        if (!batch.isEmpty()) {
            ignite.cache(cacheName).putAll(eventTransformer.transform(batch));
            if (batch.size() < batchSize)
                sinkCounter.incrementBatchUnderflowCount();
            else
                sinkCounter.incrementBatchCompleteCount();
        } else {
            sinkCounter.incrementBatchEmptyCount();
        }
        sinkCounter.addToEventDrainAttemptCount(batch.size());
        transaction.commit();
        sinkCounter.addToEventDrainSuccessCount(batch.size());
    } catch (Exception e) {
        log.error("Failed to process events", e);
        try {
            transaction.rollback();
        } catch (Throwable e1) {
            e.addSuppressed(e1);
        }
        throw new EventDeliveryException(e);
    } finally {
        transaction.close();
    }
    return eventCount == 0 ? Status.BACKOFF : Status.READY;
}
Also used : Transaction(org.apache.flume.Transaction) EventDeliveryException(org.apache.flume.EventDeliveryException) Channel(org.apache.flume.Channel) ArrayList(java.util.ArrayList) Event(org.apache.flume.Event) FlumeException(org.apache.flume.FlumeException) EventDeliveryException(org.apache.flume.EventDeliveryException)

Aggregations

EventDeliveryException (org.apache.flume.EventDeliveryException)12 Event (org.apache.flume.Event)11 Transaction (org.apache.flume.Transaction)9 Channel (org.apache.flume.Channel)8 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 MemoryChannel (org.apache.flume.channel.MemoryChannel)4 Test (org.junit.Test)4 PhoenixSink (org.apache.phoenix.flume.sink.PhoenixSink)3 ChannelException (org.apache.flume.ChannelException)2 FlumeException (org.apache.flume.FlumeException)2 PollableSource (org.apache.flume.PollableSource)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 Message (org.apache.rocketmq.common.message.Message)2 NetletThrowable (com.datatorrent.netlet.NetletThrowable)1 NetletRuntimeException (com.datatorrent.netlet.NetletThrowable.NetletRuntimeException)1 Slice (com.datatorrent.netlet.util.Slice)1 IOError (java.io.IOError)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1