Skip to content

Commit 5f83831

Browse files
authored
Upgrade Mongojack to version 5.0.2 (#21493)
* Gracefully remove DBQuery usages * Replace remaining usages of deprecated MongoJack API * Fix DBJobTriggerServiceTest * Update MongoJack to 5.0.2 * Remove unused fields from MongoUtils * Add upgrade notes * add changelog * Improve readability when creating a projection
1 parent 8062b90 commit 5f83831

33 files changed

+100
-2621
lines changed

UPGRADING.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ Upgrading to Graylog 6.2.x
44
## Breaking Changes
55

66
### Plugins
7-
8-
Adjustment of `enterpriseWidgets` web interface plugin. The `editComponent` attribute now no longer has a `onSubmit` prop.
9-
Before this change the prop had to be called to close the widget edit mode. Now it is enough to call `applyAllWidgetChanges` from the `WidgetEditApplyAllChangesContext`.
10-
Alternatively the `SaveOrCancelButtons` component can be used in the edit component for custom widgets. It renders a cancel and submit button and calls `applyAllWidgetChanges` on submit.
7+
* This release includes Java API changes which might require plugin authors to adjust their code. Please check
8+
[Java API Changes](#java-api-changes) for details.
9+
* Adjustment of `enterpriseWidgets` web interface plugin. The `editComponent` attribute now no longer has a `onSubmit` prop.
10+
Before this change the prop had to be called to close the widget edit mode. Now it is enough to call `applyAllWidgetChanges` from the `WidgetEditApplyAllChangesContext`.
11+
Alternatively the `SaveOrCancelButtons` component can be used in the edit component for custom widgets. It renders a cancel and submit button and calls `applyAllWidgetChanges` on submit.
1112

1213
## Configuration File Changes
1314

@@ -21,7 +22,12 @@ Alternatively the `SaveOrCancelButtons` component can be used in the edit compon
2122

2223
## Java API Changes
2324

24-
The following Java Code API changes have been made.
25+
Upgraded [MongoJack](https://github.com/mongojack/mongojack) to version 5.x. This impacts the Java API for accessing
26+
documents in MongoDB. Some previously deprecated MongoJack classes (like `org.mongojack.DBQuery`) have been removed.
27+
Plugin authors will have to replace usages of removed classes to corresponding classes from the MongoDB driver
28+
packages, most prominently `com.mongodb.client.model.Filters`.
29+
30+
Additionally, the following Java Code API changes are included in this release:
2531

2632
| File/method | Description |
2733
|------------------------------------------------|-------------|

changelog/unreleased/pr-21493.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type = "c"
2+
message = "Upgraded MongoJack dependency to `5.0.2`. This might require changes to third-party plugins. Please check Graylog upgrade notes."
3+
4+
pulls = ["21493"]

graylog2-server/src/main/java/org/graylog/scheduler/DBJobDefinitionService.java

-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
2727
import org.graylog2.database.MongoCollections;
2828
import org.graylog2.database.utils.MongoUtils;
29-
import org.mongojack.DBQuery;
3029

3130
import java.util.ArrayList;
3231
import java.util.Collection;
@@ -78,12 +77,6 @@ private static Bson buildConfigFieldQuery(String configField, Object value) {
7877
return Filters.eq(field, value);
7978
}
8079

81-
@Deprecated
82-
public List<JobDefinitionDto> getByQuery(DBQuery.Query query) {
83-
mongoUtils.initializeLegacyMongoJackBsonObject(query);
84-
return getByQuery((Bson) query);
85-
}
86-
8780
public List<JobDefinitionDto> getByQuery(Bson query) {
8881
return collection.find(query).into(new ArrayList<>());
8982
}

graylog2-server/src/main/java/org/graylog/scheduler/DBJobTriggerService.java

-26
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.graylog2.database.utils.MongoUtils;
4242
import org.graylog2.plugin.system.NodeId;
4343
import org.joda.time.DateTime;
44-
import org.mongojack.DBQuery;
4544

4645
import java.util.ArrayList;
4746
import java.util.Collection;
@@ -335,22 +334,10 @@ public int deleteByQuery(Bson query) {
335334
return Ints.saturatedCast(collection.deleteMany(query).getDeletedCount());
336335
}
337336

338-
@Deprecated
339-
public int deleteByQuery(DBQuery.Query query) {
340-
mongoUtils.initializeLegacyMongoJackBsonObject(query);
341-
return deleteByQuery((Bson) query);
342-
}
343-
344337
public long countByQuery(Bson query) {
345338
return collection.countDocuments(query);
346339
}
347340

348-
@Deprecated
349-
public long countByQuery(DBQuery.Query query) {
350-
mongoUtils.initializeLegacyMongoJackBsonObject(query);
351-
return countByQuery((Bson) query);
352-
}
353-
354341
/**
355342
* Locks and returns the next runnable trigger. The caller needs to take care of releasing the trigger lock.
356343
*
@@ -545,13 +532,6 @@ public Optional<JobTriggerDto> cancelTriggerByQuery(Bson query) {
545532
return Optional.ofNullable(collection.findOneAndUpdate(query, update));
546533
}
547534

548-
@Deprecated
549-
public Optional<JobTriggerDto> cancelTriggerByQuery(DBQuery.Query query) {
550-
mongoUtils.initializeLegacyMongoJackBsonObject(query);
551-
return cancelTriggerByQuery((Bson) query);
552-
}
553-
554-
555535
/**
556536
* Find triggers by using the provided query. Use judiciously!
557537
*
@@ -562,12 +542,6 @@ public List<JobTriggerDto> findByQuery(Bson query) {
562542
return stream(collection.find(query).sort(descending(FIELD_UPDATED_AT))).toList();
563543
}
564544

565-
@Deprecated
566-
public List<JobTriggerDto> findByQuery(DBQuery.Query query) {
567-
mongoUtils.initializeLegacyMongoJackBsonObject(query);
568-
return findByQuery((Bson) query);
569-
}
570-
571545
private record OverdueTrigger(@JsonProperty("_id") String type, @JsonProperty("count") long count) {}
572546

573547
/**

graylog2-server/src/main/java/org/graylog2/database/MongoCollections.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public <T extends MongoEntity> MongoUtils<T> utils(String collectionName, Class<
103103
* Provides utility methods like getting documents by ID, etc.
104104
*/
105105
public <T extends MongoEntity> MongoUtils<T> utils(MongoCollection<T> collection) {
106-
return new MongoUtils<>(collection, objectMapper);
106+
return new MongoUtils<>(collection);
107107
}
108108

109109
/**

0 commit comments

Comments
 (0)