Search in sources :

Example 11 with TridentTuple

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);
        }
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) IllegalClassException(org.apache.commons.lang.IllegalClassException) FailedException(backtype.storm.topology.FailedException) IllegalClassException(org.apache.commons.lang.IllegalClassException) TridentTuple(storm.trident.tuple.TridentTuple)

Example 12 with TridentTuple

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);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) ElasticSearchException(org.elasticsearch.ElasticSearchException) HashSet(java.util.HashSet) TridentTuple(storm.trident.tuple.TridentTuple)

Example 13 with TridentTuple

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) }));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(backtype.storm.tuple.Values) ReducerValueUpdater(storm.trident.state.ReducerValueUpdater) ValueUpdater(storm.trident.state.ValueUpdater) ReducerValueUpdater(storm.trident.state.ReducerValueUpdater) ArrayList(java.util.ArrayList) List(java.util.List) ComboList(storm.trident.tuple.ComboList) TridentTuple(storm.trident.tuple.TridentTuple)

Example 14 with TridentTuple

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);
        }
    }
}
Also used : TridentTuple(storm.trident.tuple.TridentTuple)

Example 15 with TridentTuple

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]);
    }
}
Also used : TridentTuple(storm.trident.tuple.TridentTuple)

Aggregations

TridentTuple (storm.trident.tuple.TridentTuple)25 ArrayList (java.util.ArrayList)10 List (java.util.List)8 Values (backtype.storm.tuple.Values)6 HashMap (java.util.HashMap)6 ComboList (storm.trident.tuple.ComboList)6 Map (java.util.Map)4 ValueUpdater (storm.trident.state.ValueUpdater)4 FailedException (backtype.storm.topology.FailedException)2 Fields (backtype.storm.tuple.Fields)2 TridentTopology (storm.trident.TridentTopology)2 Consumer (storm.trident.operation.Consumer)2 CombinerValueUpdater (storm.trident.state.CombinerValueUpdater)2 ReducerValueUpdater (storm.trident.state.ReducerValueUpdater)2 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)2 ProjectionFactory (storm.trident.tuple.TridentTupleView.ProjectionFactory)2 HashSet (java.util.HashSet)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1 Put (org.apache.hadoop.hbase.client.Put)1 ElasticSearchException (org.elasticsearch.ElasticSearchException)1