Search in sources :

Example 1 with FailedException

use of backtype.storm.topology.FailedException 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 2 with FailedException

use of backtype.storm.topology.FailedException in project storm by nathanmarz.

the class CoordinatedBolt method checkFinishId.

private boolean checkFinishId(Tuple tup, TupleType type) {
    Object id = tup.getValue(0);
    boolean failed = false;
    synchronized (_tracked) {
        TrackingInfo track = _tracked.get(id);
        try {
            if (track != null) {
                boolean delayed = false;
                if (_idStreamSpec == null && type == TupleType.COORD || _idStreamSpec != null && type == TupleType.ID) {
                    track.ackTuples.add(tup);
                    delayed = true;
                }
                if (track.failed) {
                    failed = true;
                    for (Tuple t : track.ackTuples) {
                        _collector.fail(t);
                    }
                    _tracked.remove(id);
                } else if (track.receivedId && (_sourceArgs.isEmpty() || track.reportCount == _numSourceReports && track.expectedTupleCount == track.receivedTuples)) {
                    if (_delegate instanceof FinishedCallback) {
                        ((FinishedCallback) _delegate).finishedId(id);
                    }
                    if (!(_sourceArgs.isEmpty() || type != TupleType.REGULAR)) {
                        throw new IllegalStateException("Coordination condition met on a non-coordinating tuple. Should be impossible");
                    }
                    Iterator<Integer> outTasks = _countOutTasks.iterator();
                    while (outTasks.hasNext()) {
                        int task = outTasks.next();
                        int numTuples = get(track.taskEmittedTuples, task, 0);
                        _collector.emitDirect(task, Constants.COORDINATED_STREAM_ID, tup, new Values(id, numTuples));
                    }
                    for (Tuple t : track.ackTuples) {
                        _collector.ack(t);
                    }
                    track.finished = true;
                    _tracked.remove(id);
                }
                if (!delayed && type != TupleType.REGULAR) {
                    if (track.failed) {
                        _collector.fail(tup);
                    } else {
                        _collector.ack(tup);
                    }
                }
            } else {
                if (type != TupleType.REGULAR)
                    _collector.fail(tup);
            }
        } catch (FailedException e) {
            LOG.error("Failed to finish batch", e);
            for (Tuple t : track.ackTuples) {
                _collector.fail(t);
            }
            _tracked.remove(id);
            failed = true;
        }
    }
    return failed;
}
Also used : FailedException(backtype.storm.topology.FailedException) Iterator(java.util.Iterator) Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple)

Example 3 with FailedException

use of backtype.storm.topology.FailedException in project jstorm by alibaba.

the class TridentSpoutExecutor method execute.

@Override
public void execute(BatchInfo info, Tuple input) {
    // there won't be a BatchInfo for the success stream
    TransactionAttempt attempt = (TransactionAttempt) input.getValue(0);
    if (input.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) {
        if (attempt.equals(_activeBatches.get(attempt.getTransactionId()))) {
            ((ICommitterTridentSpout.Emitter) _emitter).commit(attempt);
            _activeBatches.remove(attempt.getTransactionId());
        } else {
            throw new FailedException("Received commit for different transaction attempt");
        }
    } else if (input.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) {
        // valid to delete before what's been committed since
        // those batches will never be accessed again
        _activeBatches.headMap(attempt.getTransactionId()).clear();
        _emitter.success(attempt);
    } else {
        _collector.setBatch(info.batchId);
        _emitter.emitBatch(attempt, input.getValue(1), _collector);
        _activeBatches.put(attempt.getTransactionId(), attempt);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) TransactionAttempt(storm.trident.topology.TransactionAttempt)

Example 4 with FailedException

use of backtype.storm.topology.FailedException in project jstorm by alibaba.

the class DBBolt method commit.

@Override
public byte[] commit(BatchId id) throws FailedException {
    AtomicLong count = (AtomicLong) counters.remove(id);
    if (count == null) {
        count = new AtomicLong(0);
    }
    AtomicLong sum = (AtomicLong) sums.remove(id);
    if (sum == null) {
        sum = new AtomicLong(0);
    }
    CommitedValue commitedValue = new CommitedValue(count, sum);
    try {
        commitedValue.commit();
        return Utils.serialize(commitedValue);
    } catch (Exception e) {
        LOG.error("Failed to commit " + commitedValue, e);
        throw new FailedException(e);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FailedException(backtype.storm.topology.FailedException) FailedException(backtype.storm.topology.FailedException)

Example 5 with FailedException

use of backtype.storm.topology.FailedException in project jstorm by alibaba.

the class MetaSimpleClient method revert.

@Override
public void revert(BatchId id, byte[] commitResult) {
    try {
        switchOffsetMap();
        updateOffsetToZk(currentOffsets);
    } catch (Exception e) {
        LOG.warn("Failed to update offset to ZK", e);
        throw new FailedException(e);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) FailedException(backtype.storm.topology.FailedException) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Aggregations

FailedException (backtype.storm.topology.FailedException)18 Values (backtype.storm.tuple.Values)6 ReportedFailedException (backtype.storm.topology.ReportedFailedException)5 BigInteger (java.math.BigInteger)4 Tuple (backtype.storm.tuple.Tuple)2 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)2 Iterator (java.util.Iterator)2 IBatchID (storm.trident.spout.IBatchID)2 TransactionAttempt (storm.trident.topology.TransactionAttempt)2 TridentTuple (storm.trident.tuple.TridentTuple)2 BatchId (com.alibaba.jstorm.batch.BatchId)1 IPrepareCommit (com.alibaba.jstorm.batch.IPrepareCommit)1 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1 ElasticSearchException (org.elasticsearch.ElasticSearchException)1 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1