Search in sources :

Example 1 with ColumnList

use of org.apache.storm.hbase.common.ColumnList in project storm by apache.

the class HBaseBolt method execute.

@Override
public void execute(Tuple tuple) {
    try {
        if (batchHelper.shouldHandle(tuple)) {
            byte[] rowKey = this.mapper.rowKey(tuple);
            ColumnList cols = this.mapper.columns(tuple);
            List<Mutation> mutations = hBaseClient.constructMutationReq(rowKey, cols, writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
            batchMutations.addAll(mutations);
            batchHelper.addBatch(tuple);
        }
        if (batchHelper.shouldFlush()) {
            this.hBaseClient.batchMutate(batchMutations);
            LOG.debug("acknowledging tuples after batchMutate");
            batchHelper.ack();
            batchMutations.clear();
        }
    } catch (Exception e) {
        batchHelper.fail(e);
        batchMutations.clear();
    }
}
Also used : ColumnList(org.apache.storm.hbase.common.ColumnList) Mutation(org.apache.hadoop.hbase.client.Mutation)

Example 2 with ColumnList

use of org.apache.storm.hbase.common.ColumnList in project streamline by hortonworks.

the class StreamlineEventHBaseMapperTest method testMapper.

@Test
public void testMapper() {
    byte[] bytes = mapper.rowKey(mockTuple);
    Assert.assertTrue(Arrays.equals(TEST_EVENT.getId().getBytes(UTF_8), bytes));
    ColumnList columns = mapper.columns(mockTuple);
    Assert.assertEquals(1, columns.getColumns().size());
    ColumnList.Column column = columns.getColumns().get(0);
    Assert.assertTrue(Arrays.equals(COLUMN_FAMILY.getBytes(Charsets.UTF_8), column.getFamily()));
    Assert.assertTrue(Arrays.equals(COLUMN_FIELD.getBytes(Charsets.UTF_8), column.getQualifier()));
    Assert.assertTrue(Arrays.equals(COLUMN_FIELD.getBytes(Charsets.UTF_8), column.getValue()));
}
Also used : ColumnList(org.apache.storm.hbase.common.ColumnList) Test(org.junit.Test)

Example 3 with ColumnList

use of org.apache.storm.hbase.common.ColumnList in project streamline by hortonworks.

the class StreamlineEventHBaseMapper method columns.

@Override
public ColumnList columns(Tuple tuple) {
    StreamlineEvent event = (StreamlineEvent) tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
    ColumnList columnList = new ColumnList();
    for (String key : event.keySet()) {
        // Hbase bolt can not handle null values.
        if (event.get(key) != null) {
            columnList.addColumn(columnFamily, key.getBytes(Charsets.UTF_8), toBytes(event.get(key)));
        }
    }
    return columnList;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ColumnList(org.apache.storm.hbase.common.ColumnList)

Example 4 with ColumnList

use of org.apache.storm.hbase.common.ColumnList in project storm by apache.

the class HBaseState method updateState.

public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
    List<Mutation> mutations = Lists.newArrayList();
    for (TridentTuple tuple : tuples) {
        byte[] rowKey = options.mapper.rowKey(tuple);
        ColumnList cols = options.mapper.columns(tuple);
        mutations.addAll(hBaseClient.constructMutationReq(rowKey, cols, options.durability));
    }
    try {
        hBaseClient.batchMutate(mutations);
    } catch (Exception e) {
        collector.reportError(e);
        throw new FailedException(e);
    }
}
Also used : FailedException(org.apache.storm.topology.FailedException) Mutation(org.apache.hadoop.hbase.client.Mutation) ColumnList(org.apache.storm.hbase.common.ColumnList) FailedException(org.apache.storm.topology.FailedException) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Aggregations

ColumnList (org.apache.storm.hbase.common.ColumnList)4 Mutation (org.apache.hadoop.hbase.client.Mutation)2 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 FailedException (org.apache.storm.topology.FailedException)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1 Test (org.junit.Test)1