use of storm.trident.tuple.TridentTuple in project jstorm by alibaba.
the class WindowsStateUpdater method updateState.
@Override
public void updateState(WindowsState state, List<TridentTuple> tuples, TridentCollector collector) {
Long currentTxId = state.getCurrentTxId();
LOG.debug("Removing triggers using WindowStateUpdater, txnId: [{}] ", currentTxId);
for (TridentTuple tuple : tuples) {
try {
Object fieldValue = tuple.getValueByField(WindowTridentProcessor.TRIGGER_FIELD_NAME);
if (!(fieldValue instanceof WindowTridentProcessor.TriggerInfo)) {
throw new IllegalClassException(WindowTridentProcessor.TriggerInfo.class, fieldValue.getClass());
}
WindowTridentProcessor.TriggerInfo triggerInfo = (WindowTridentProcessor.TriggerInfo) fieldValue;
String triggerCompletedKey = WindowTridentProcessor.getWindowTriggerInprocessIdPrefix(triggerInfo.windowTaskId) + currentTxId;
LOG.debug("Removing trigger key [{}] and trigger completed key [{}] from store: [{}]", triggerInfo, triggerCompletedKey, windowsStore);
windowsStore.removeAll(Lists.newArrayList(triggerInfo.generateTriggerKey(), triggerCompletedKey));
} catch (Exception ex) {
LOG.warn(ex.getMessage());
collector.reportError(ex);
throw new FailedException(ex);
}
}
}
use of storm.trident.tuple.TridentTuple in project storm-elastic-search by hmsonline.
the class ElasticSearchState method createIndices.
public void createIndices(TridentElasticSearchMapper mapper, List<TridentTuple> tuples) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
Set<String> existingIndex = new HashSet<String>();
for (TridentTuple tuple : tuples) {
String indexName = mapper.mapToIndex(tuple);
String type = mapper.mapToType(tuple);
String key = mapper.mapToKey(tuple);
Map<String, Object> data = mapper.mapToData(tuple);
String parentId = mapper.mapToParentId(tuple);
if (!existingIndex.contains(indexName) && !client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet().isExists()) {
createIndex(bulkRequest, indexName, mapper.mapToIndexSettings(tuple));
createMapping(bulkRequest, indexName, type, mapper.mapToMappingSettings(tuple));
existingIndex.add(indexName);
}
if (StringUtils.isBlank(parentId)) {
bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data));
} else {
LOGGER.debug("parent: " + parentId);
bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data).setParent(parentId));
}
}
try {
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
// Index failed. Retry!
throw new FailedException("Cannot create index via ES: " + bulkResponse.buildFailureMessage());
}
} catch (ElasticSearchException e) {
StormElasticSearchUtils.handleElasticSearchException(getClass(), e);
}
}
use of storm.trident.tuple.TridentTuple in project storm by nathanmarz.
the class MapReducerAggStateUpdater method updateState.
@Override
public void updateState(MapState map, List<TridentTuple> tuples, TridentCollector collector) {
Map<List<Object>, List<TridentTuple>> grouped = new HashMap();
List<List<Object>> groups = new ArrayList<List<Object>>(tuples.size());
List<Object> values = new ArrayList<Object>(tuples.size());
for (TridentTuple t : tuples) {
List<Object> group = _groupFactory.create(t);
List<TridentTuple> groupTuples = grouped.get(group);
if (groupTuples == null) {
groupTuples = new ArrayList();
grouped.put(group, groupTuples);
}
groupTuples.add(_inputFactory.create(t));
}
List<List<Object>> uniqueGroups = new ArrayList(grouped.keySet());
List<ValueUpdater> updaters = new ArrayList(uniqueGroups.size());
for (List<Object> group : uniqueGroups) {
updaters.add(new ReducerValueUpdater(_agg, grouped.get(group)));
}
List<Object> results = map.multiUpdate(uniqueGroups, updaters);
for (int i = 0; i < uniqueGroups.size(); i++) {
List<Object> group = uniqueGroups.get(i);
Object result = results.get(i);
collector.emit(_factory.create(new List[] { group, new Values(result) }));
}
}
use of storm.trident.tuple.TridentTuple in project storm by nathanmarz.
the class StateQueryProcessor method finishBatch.
@Override
public void finishBatch(ProcessorContext processorContext) {
BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
if (!state.tuples.isEmpty()) {
List<Object> results = _function.batchRetrieve(_state, state.args);
if (results.size() != state.tuples.size()) {
throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
}
for (int i = 0; i < state.tuples.size(); i++) {
TridentTuple tuple = state.tuples.get(i);
Object result = results.get(i);
_collector.setContext(processorContext, tuple);
_function.execute(_projection.create(tuple), result, _collector);
}
}
}
use of storm.trident.tuple.TridentTuple in project storm by nathanmarz.
the class ChainedAggregatorImpl method aggregate.
public void aggregate(ChainedResult val, TridentTuple tuple, TridentCollector collector) {
val.setFollowThroughCollector(collector);
for (int i = 0; i < _aggs.length; i++) {
TridentTuple projected = _inputFactories[i].create((TridentTupleView) tuple);
_aggs[i].aggregate(val.objs[i], projected, val.collectors[i]);
}
}
Aggregations