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