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();
}
}
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()));
}
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;
}
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);
}
}
Aggregations