use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.
the class InputServiceImpl method totalExtractorCount.
@Override
public long totalExtractorCount() {
final DBObject query = new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, new BasicDBObject("$exists", true));
final DBCursor inputs = collection(InputImpl.class).find(query, new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, 1));
long extractorsCount = 0;
for (DBObject input : inputs) {
final BasicDBList extractors = (BasicDBList) input.get(InputImpl.EMBEDDED_EXTRACTORS);
extractorsCount += extractors.size();
}
return extractorsCount;
}
use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.
the class InputServiceImpl method totalExtractorCountByType.
@Override
public Map<Extractor.Type, Long> totalExtractorCountByType() {
final Map<Extractor.Type, Long> extractorsCountByType = new HashMap<>();
final DBObject query = new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, new BasicDBObject("$exists", true));
final DBCursor inputs = collection(InputImpl.class).find(query, new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, 1));
for (DBObject input : inputs) {
final BasicDBList extractors = (BasicDBList) input.get(InputImpl.EMBEDDED_EXTRACTORS);
for (Object fuckYouMongoDb : extractors) {
final DBObject extractor = (DBObject) fuckYouMongoDb;
final Extractor.Type type = Extractor.Type.fuzzyValueOf(((String) extractor.get(Extractor.FIELD_TYPE)));
if (type != null) {
final Long oldValue = extractorsCountByType.get(type);
final Long newValue = (oldValue == null) ? 1 : oldValue + 1;
extractorsCountByType.put(type, newValue);
}
}
}
return extractorsCountByType;
}
use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.
the class InputServiceImpl method getExtractors.
@Override
@SuppressWarnings("unchecked")
public List<Extractor> getExtractors(Input input) {
if (input.getFields().get(InputImpl.EMBEDDED_EXTRACTORS) == null) {
return Collections.emptyList();
}
final ImmutableList.Builder<Extractor> listBuilder = ImmutableList.builder();
final BasicDBList mEx = (BasicDBList) input.getFields().get(InputImpl.EMBEDDED_EXTRACTORS);
for (final Object element : mEx) {
final DBObject ex = (BasicDBObject) element;
// SOFT MIGRATION: does this extractor have an order set? Implemented for issue: #726
Long order = 0L;
if (ex.containsField(Extractor.FIELD_ORDER)) {
// mongodb driver gives us a java.lang.Long
order = (Long) ex.get(Extractor.FIELD_ORDER);
}
try {
final Extractor extractor = extractorFactory.factory((String) ex.get(Extractor.FIELD_ID), (String) ex.get(Extractor.FIELD_TITLE), order.intValue(), Extractor.CursorStrategy.valueOf(((String) ex.get(Extractor.FIELD_CURSOR_STRATEGY)).toUpperCase(Locale.ENGLISH)), Extractor.Type.valueOf(((String) ex.get(Extractor.FIELD_TYPE)).toUpperCase(Locale.ENGLISH)), (String) ex.get(Extractor.FIELD_SOURCE_FIELD), (String) ex.get(Extractor.FIELD_TARGET_FIELD), (Map<String, Object>) ex.get(Extractor.FIELD_EXTRACTOR_CONFIG), (String) ex.get(Extractor.FIELD_CREATOR_USER_ID), getConvertersOfExtractor(ex), Extractor.ConditionType.valueOf(((String) ex.get(Extractor.FIELD_CONDITION_TYPE)).toUpperCase(Locale.ENGLISH)), (String) ex.get(Extractor.FIELD_CONDITION_VALUE));
listBuilder.add(extractor);
} catch (Exception e) {
LOG.error("Cannot build extractor from persisted data. Skipping.", e);
}
}
return listBuilder.build();
}
use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.
the class MongoConnectionImpl method getMongoVersion.
@Nullable
private Version getMongoVersion(DB adminDb) {
final CommandResult buildInfoResult = adminDb.command("buildInfo");
if (buildInfoResult.ok()) {
final BasicDBList versionArray = (BasicDBList) buildInfoResult.get("versionArray");
if (versionArray == null || versionArray.size() < 3) {
LOG.debug("Couldn't retrieve MongoDB version");
return null;
}
final int majorVersion = (int) versionArray.get(0);
final int minorVersion = (int) versionArray.get(1);
final int patchVersion = (int) versionArray.get(2);
return Version.forIntegers(majorVersion, minorVersion, patchVersion);
} else {
LOG.debug("Couldn't retrieve MongoDB buildInfo: {}", buildInfoResult.getErrorMessage());
return null;
}
}
use of com.mongodb.BasicDBList in project gora by apache.
the class TestMongoStore method testFromMongoList_empty.
@Test
public void testFromMongoList_empty() throws Exception {
MongoStore store = new MongoStore();
String field = "myField";
BasicDBObject emptyField = new BasicDBObject(field, new BasicDBList());
Object item = store.fromMongoList(field, null, new BSONDecorator(emptyField), null);
assertNotNull(item);
}
Aggregations