Search in sources :

Example 71 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class StreamRuleServiceImpl method create.

@Override
public StreamRule create(String streamId, CreateStreamRuleRequest cr) {
    Map<String, Object> streamRuleData = Maps.newHashMap();
    streamRuleData.put(StreamRuleImpl.FIELD_TYPE, cr.type());
    streamRuleData.put(StreamRuleImpl.FIELD_VALUE, cr.value());
    streamRuleData.put(StreamRuleImpl.FIELD_FIELD, cr.field());
    streamRuleData.put(StreamRuleImpl.FIELD_INVERTED, cr.inverted());
    streamRuleData.put(StreamRuleImpl.FIELD_STREAM_ID, new ObjectId(streamId));
    streamRuleData.put(StreamRuleImpl.FIELD_DESCRIPTION, cr.description());
    return new StreamRuleImpl(streamRuleData);
}
Also used : ObjectId(org.bson.types.ObjectId) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 72 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class StreamServiceImpl method removeOutputFromAllStreams.

@Override
public void removeOutputFromAllStreams(Output output) {
    ObjectId outputId = new ObjectId(output.getId());
    DBObject match = new BasicDBObject(StreamImpl.FIELD_OUTPUTS, outputId);
    DBObject modify = new BasicDBObject("$pull", new BasicDBObject(StreamImpl.FIELD_OUTPUTS, outputId));
    collection(StreamImpl.class).update(match, modify, false, true);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 73 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class MongoIndexSetService method delete.

/**
     * {@inheritDoc}
     */
@Override
public int delete(ObjectId id) {
    if (!isDeletable(id)) {
        return 0;
    }
    final DBQuery.Query query = DBQuery.is("_id", id);
    final WriteResult<IndexSetConfig, ObjectId> writeResult = collection.remove(query);
    final int removedEntries = writeResult.getN();
    if (removedEntries > 0) {
        final IndexSetDeletedEvent deletedEvent = IndexSetDeletedEvent.create(id.toHexString());
        clusterEventBus.post(deletedEvent);
    }
    return removedEntries;
}
Also used : ObjectId(org.bson.types.ObjectId) DBQuery(org.mongojack.DBQuery) IndexSetDeletedEvent(org.graylog2.indexer.indexset.events.IndexSetDeletedEvent)

Example 74 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class IndexFailureServiceImpl method all.

@Override
public List<IndexFailure> all(int limit, int offset) {
    final DBObject sort = new BasicDBObject("$natural", -1);
    final List<DBObject> results = query(IndexFailureImpl.class, new BasicDBObject(), sort, limit, offset);
    final List<IndexFailure> failures = new ArrayList<>(results.size());
    for (DBObject o : results) {
        failures.add(new IndexFailureImpl((ObjectId) o.get("_id"), o.toMap()));
    }
    return failures;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 75 with ObjectId

use of org.bson.types.ObjectId in project graylog2-server by Graylog2.

the class LegacyMongoIndexRangeServiceTest method testGetExistingIndexRange.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testGetExistingIndexRange() throws Exception {
    final IndexRange indexRange = indexRangeService.get("graylog_0");
    final DateTime end = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
    final IndexRange expected = MongoIndexRange.create(new ObjectId("56250da2d400000000000001"), "graylog_0", EPOCH, end, end, 0);
    assertThat(indexRange).isEqualTo(expected);
}
Also used : ObjectId(org.bson.types.ObjectId) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

ObjectId (org.bson.types.ObjectId)249 Test (org.junit.Test)157 BasicDBObject (com.mongodb.BasicDBObject)54 Document (org.bson.Document)38 DBObject (com.mongodb.DBObject)35 ArrayList (java.util.ArrayList)28 BsonObjectId (org.bson.BsonObjectId)27 Date (java.util.Date)24 DBRef (com.mongodb.DBRef)15 List (java.util.List)15 StreamRuleMock (org.graylog2.streams.matchers.StreamRuleMock)14 Message (org.graylog2.plugin.Message)13 BasicBSONObject (org.bson.BasicBSONObject)12 Query (org.springframework.data.mongodb.core.query.Query)11 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)10 Map (java.util.Map)10 Binary (org.bson.types.Binary)10 GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)7 Code (org.bson.types.Code)7