use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class EsState method updateState.
/**
* Store current state to ElasticSearch.
*
* @param tuples list of tuples for storing to ES.
* Each tuple should have relevant fields (source, index, type, id) for EsState's tupleMapper to extract ES document.
*/
public void updateState(List<TridentTuple> tuples) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (TridentTuple tuple : tuples) {
String source = tupleMapper.getSource(tuple);
String index = tupleMapper.getIndex(tuple);
String type = tupleMapper.getType(tuple);
String id = tupleMapper.getId(tuple);
bulkRequest.add(client.prepareIndex(index, type, id).setSource(source));
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
LOG.warn("failed processing bulk index requests " + bulkResponse.buildFailureMessage());
throw new FailedException();
}
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class CassandraState method updateState.
public void updateState(List<TridentTuple> tuples, final TridentCollector collector) {
List<Statement> statements = new ArrayList<>();
for (TridentTuple tuple : tuples) {
statements.addAll(options.cqlStatementTupleMapper.map(conf, session, tuple));
}
try {
if (options.batchingType != null) {
BatchStatement batchStatement = new BatchStatement(options.batchingType);
batchStatement.addAll(statements);
session.execute(batchStatement);
} else {
for (Statement statement : statements) {
session.execute(statement);
}
}
} catch (Exception e) {
LOG.warn("Batch write operation is failed.");
collector.reportError(e);
throw new FailedException(e);
}
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class CassandraState method batchRetrieve.
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
Preconditions.checkNotNull(options.cqlResultSetValuesMapper, "CassandraState.Options should have cqlResultSetValuesMapper");
List<List<Values>> batchRetrieveResult = new ArrayList<>();
try {
for (TridentTuple tridentTuple : tridentTuples) {
List<Statement> statements = options.cqlStatementTupleMapper.map(conf, session, tridentTuple);
for (Statement statement : statements) {
List<List<Values>> values = options.cqlResultSetValuesMapper.map(session, statement, tridentTuple);
batchRetrieveResult.addAll(values);
}
}
} catch (Exception e) {
LOG.warn("Batch retrieve operation is failed.");
throw new FailedException(e);
}
return batchRetrieveResult;
}
use of org.apache.storm.trident.tuple.TridentTuple in project storm by apache.
the class TestSocketDataSourceProvider method mockTupleList.
private static List<TridentTuple> mockTupleList() {
List<TridentTuple> tupleList = new ArrayList<>();
TridentTuple t0 = mock(TridentTuple.class);
TridentTuple t1 = mock(TridentTuple.class);
when(t0.getValueByField("ID")).thenReturn(1);
when(t0.getValueByField("val")).thenReturn("2");
doReturn(Lists.<Object>newArrayList(1, "2")).when(t0).getValues();
when(t0.size()).thenReturn(2);
when(t1.getValueByField("ID")).thenReturn(2);
when(t1.getValueByField("val")).thenReturn("3");
doReturn(Lists.<Object>newArrayList(2, "3")).when(t1).getValues();
when(t1.size()).thenReturn(2);
tupleList.add(t0);
tupleList.add(t1);
return tupleList;
}
use of org.apache.storm.trident.tuple.TridentTuple 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