Search in sources :

Example 1 with Bson

use of org.bson.conversions.Bson in project storm by apache.

the class MongoMapState method multiPut.

@Override
public void multiPut(List<List<Object>> keysList, List<T> values) {
    try {
        for (int i = 0; i < keysList.size(); i++) {
            List<Object> keys = keysList.get(i);
            T value = values.get(i);
            Bson filter = options.queryCreator.createFilterByKeys(keys);
            Document document = options.mapper.toDocumentByKeys(keys);
            document.append(options.serDocumentField, this.serializer.serialize(value));
            this.mongoClient.update(filter, document, true, false);
        }
    } catch (Exception e) {
        LOG.warn("Batch write operation failed.", e);
        throw new FailedException(e);
    }
}
Also used : FailedException(org.apache.storm.topology.FailedException) Document(org.bson.Document) FailedException(org.apache.storm.topology.FailedException) Bson(org.bson.conversions.Bson)

Example 2 with Bson

use of org.bson.conversions.Bson in project storm by apache.

the class MongoState method batchRetrieve.

public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
    List<List<Values>> batchRetrieveResult = Lists.newArrayList();
    try {
        for (TridentTuple tuple : tridentTuples) {
            Bson filter = options.queryCreator.createFilter(tuple);
            Document doc = mongoClient.find(filter);
            List<Values> values = options.lookupMapper.toTuple(tuple, doc);
            batchRetrieveResult.add(values);
        }
    } catch (Exception e) {
        LOG.warn("Batch get operation failed. Triggering replay.", e);
        throw new FailedException(e);
    }
    return batchRetrieveResult;
}
Also used : FailedException(org.apache.storm.topology.FailedException) Values(org.apache.storm.tuple.Values) List(java.util.List) Document(org.bson.Document) FailedException(org.apache.storm.topology.FailedException) TridentTuple(org.apache.storm.trident.tuple.TridentTuple) Bson(org.bson.conversions.Bson)

Example 3 with Bson

use of org.bson.conversions.Bson in project storm by apache.

the class MongoLookupBolt method execute.

@Override
public void execute(Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        return;
    }
    try {
        //get query filter
        Bson filter = queryCreator.createFilter(tuple);
        //find document from mongodb
        Document doc = mongoClient.find(filter);
        //get storm values and emit
        List<Values> valuesList = mapper.toTuple(tuple, doc);
        for (Values values : valuesList) {
            this.collector.emit(tuple, values);
        }
        this.collector.ack(tuple);
    } catch (Exception e) {
        this.collector.reportError(e);
        this.collector.fail(tuple);
    }
}
Also used : Values(org.apache.storm.tuple.Values) Document(org.bson.Document) Bson(org.bson.conversions.Bson)

Example 4 with Bson

use of org.bson.conversions.Bson in project storm by apache.

the class MongoUpdateBolt method execute.

@Override
public void execute(Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        return;
    }
    try {
        //get document
        Document doc = mapper.toDocument(tuple);
        //get query filter
        Bson filter = queryCreator.createFilter(tuple);
        mongoClient.update(filter, doc, upsert, many);
        this.collector.ack(tuple);
    } catch (Exception e) {
        this.collector.reportError(e);
        this.collector.fail(tuple);
    }
}
Also used : Document(org.bson.Document) Bson(org.bson.conversions.Bson)

Example 5 with Bson

use of org.bson.conversions.Bson in project mongo-java-driver by mongodb.

the class MongoDatabaseImpl method createBsonDocumentList.

private List<BsonDocument> createBsonDocumentList(final List<? extends Bson> pipeline) {
    notNull("pipeline", pipeline);
    List<BsonDocument> bsonDocumentPipeline = new ArrayList<BsonDocument>(pipeline.size());
    for (Bson obj : pipeline) {
        if (obj == null) {
            throw new IllegalArgumentException("pipeline can not contain a null value");
        }
        bsonDocumentPipeline.add(obj.toBsonDocument(BsonDocument.class, codecRegistry));
    }
    return bsonDocumentPipeline;
}
Also used : BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson)

Aggregations

Bson (org.bson.conversions.Bson)31 Document (org.bson.Document)20 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 MongoDatabase (com.mongodb.client.MongoDatabase)5 IOException (java.io.IOException)5 UpdateResult (com.mongodb.client.result.UpdateResult)4 NoSuchElementException (java.util.NoSuchElementException)4 Exchange (org.apache.camel.Exchange)4 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)4 BsonDocument (org.bson.BsonDocument)4 Formatter (java.util.Formatter)3 HashMap (java.util.HashMap)3 List (java.util.List)3 FailedException (org.apache.storm.topology.FailedException)3 MongoClient (com.mongodb.MongoClient)2 MongoClientURI (com.mongodb.MongoClientURI)2 Processor (org.apache.camel.Processor)2 ManagedOperation (org.apache.camel.api.management.ManagedOperation)2 Values (org.apache.storm.tuple.Values)2