Skip to content

Commit

Permalink
ClusterEventPeriodical must use MongoJackObjectMapper (#3217)
Browse files Browse the repository at this point in the history
* use correct objectmapper for mongodb interaction

previous reading from the database used the wrong object mapper configuration

fixes #3216

* use mongojack objectmapper for both reading and writing the cluster config paylod
  • Loading branch information
kroepke authored and bernd committed Dec 19, 2016
1 parent 460cac6 commit 76ade2c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
Expand Up @@ -16,12 +16,14 @@
*/
package org.graylog2.cluster;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.EventBus;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.DBCollection;
import com.mongodb.WriteConcern;

import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.database.MongoConnection;
import org.graylog2.events.ClusterEventBus;
Expand All @@ -39,9 +41,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.Set;

import javax.inject.Inject;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;

Expand All @@ -61,18 +64,17 @@ public class ClusterConfigServiceImpl implements ClusterConfigService {
public ClusterConfigServiceImpl(final MongoJackObjectMapperProvider mapperProvider,
final MongoConnection mongoConnection,
final NodeId nodeId,
final ObjectMapper objectMapper,
final ChainingClassLoader chainingClassLoader,
final ClusterEventBus clusterEventBus) {
this(JacksonDBCollection.wrap(prepareCollection(mongoConnection), ClusterConfig.class, String.class, mapperProvider.get()),
nodeId, objectMapper, chainingClassLoader, clusterEventBus);
nodeId, mapperProvider.get(), chainingClassLoader, clusterEventBus);
}

ClusterConfigServiceImpl(final JacksonDBCollection<ClusterConfig, String> dbCollection,
final NodeId nodeId,
final ObjectMapper objectMapper,
final ChainingClassLoader chainingClassLoader,
final EventBus clusterEventBus) {
private ClusterConfigServiceImpl(final JacksonDBCollection<ClusterConfig, String> dbCollection,
final NodeId nodeId,
final ObjectMapper objectMapper,
final ChainingClassLoader chainingClassLoader,
final EventBus clusterEventBus) {
this.nodeId = checkNotNull(nodeId);
this.dbCollection = checkNotNull(dbCollection);
this.objectMapper = checkNotNull(objectMapper);
Expand Down
Expand Up @@ -16,18 +16,20 @@
*/
package org.graylog2.events;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.eventbus.DeadEvent;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;

import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.database.MongoConnection;
import org.graylog2.plugin.periodical.Periodical;
Expand Down Expand Up @@ -62,15 +64,14 @@ public class ClusterEventPeriodical extends Periodical {
public ClusterEventPeriodical(final MongoJackObjectMapperProvider mapperProvider,
final MongoConnection mongoConnection,
final NodeId nodeId,
final ObjectMapper objectMapper,
final ChainingClassLoader chainingClassLoader,
final EventBus serverEventBus,
final ClusterEventBus clusterEventBus) {
this(JacksonDBCollection.wrap(prepareCollection(mongoConnection), ClusterEvent.class, String.class, mapperProvider.get()),
nodeId, objectMapper, chainingClassLoader, serverEventBus, clusterEventBus);
nodeId, mapperProvider.get(), chainingClassLoader, serverEventBus, clusterEventBus);
}

ClusterEventPeriodical(final JacksonDBCollection<ClusterEvent, String> dbCollection,
private ClusterEventPeriodical(final JacksonDBCollection<ClusterEvent, String> dbCollection,
final NodeId nodeId,
final ObjectMapper objectMapper,
final ChainingClassLoader chainingClassLoader,
Expand Down
Expand Up @@ -16,15 +16,17 @@
*/
package org.graylog2.cluster;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.eventbus.Subscribe;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lordofthejars.nosqlunit.annotation.UsingDataSet;
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum;
import com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.WriteConcern;

import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.database.MongoConnection;
import org.graylog2.database.MongoConnectionRule;
Expand Down Expand Up @@ -84,7 +86,6 @@ public void setUpService() throws Exception {
provider,
mongoRule.getMongoConnection(),
nodeId,
objectMapper,
new ChainingClassLoader(getClass().getClassLoader()),
clusterEventBus
);
Expand Down
Expand Up @@ -16,18 +16,20 @@
*/
package org.graylog2.events;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.google.common.eventbus.DeadEvent;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lordofthejars.nosqlunit.annotation.UsingDataSet;
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum;
import com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.WriteConcern;

import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.database.MongoConnection;
import org.graylog2.database.MongoConnectionRule;
Expand Down Expand Up @@ -93,7 +95,6 @@ public void setUpService() throws Exception {
provider,
mongoRule.getMongoConnection(),
nodeId,
objectMapper,
new ChainingClassLoader(getClass().getClassLoader()),
serverEventBus,
clusterEventBus
Expand Down Expand Up @@ -311,4 +312,4 @@ public void handleSimpleEvent(SimpleEvent event) {
invocations++;
}
}
}
}
Expand Up @@ -16,11 +16,13 @@
*/
package org.graylog2.indexer.indexset;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.eventbus.Subscribe;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lordofthejars.nosqlunit.annotation.UsingDataSet;
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum;
import com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb;

import org.bson.types.ObjectId;
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.buffers.processors.fakestreams.FakeStream;
Expand Down Expand Up @@ -84,7 +86,7 @@ public class MongoIndexSetServiceTest {
public void setUp() throws Exception {
clusterEventBus = new ClusterEventBus();
clusterConfigService = new ClusterConfigServiceImpl(objectMapperProvider, mongoRule.getMongoConnection(),
nodeId, objectMapper, new ChainingClassLoader(getClass().getClassLoader()), clusterEventBus);
nodeId, new ChainingClassLoader(getClass().getClassLoader()), clusterEventBus);
indexSetService = new MongoIndexSetService(mongoRule.getMongoConnection(), objectMapperProvider, streamService, clusterConfigService, clusterEventBus);
}

Expand Down Expand Up @@ -331,4 +333,4 @@ public List<IndexSetDeletedEvent> getEvents() {
return events;
}
}
}
}
Expand Up @@ -70,7 +70,7 @@ public class V20161215163900_MoveIndexSetDefaultConfigTest {
@Before
public void setUp() throws Exception {
this.clusterConfigService = spy(new ClusterConfigServiceImpl(objectMapperProvider,
fongoRule.getConnection(), nodeId, objectMapper,
fongoRule.getConnection(), nodeId,
new ChainingClassLoader(getClass().getClassLoader()), new ClusterEventBus()));

this.collection = fongoRule.getDatabase().getCollection("index_sets");
Expand Down Expand Up @@ -136,4 +136,4 @@ public void upgradeWhenDefaultIndexSetConfigExists() throws Exception {

verify(clusterConfigService, never()).write(any(DefaultIndexSetConfig.class));
}
}
}

0 comments on commit 76ade2c

Please sign in to comment.