Skip to content

Commit

Permalink
Merge pull request #125 from YukiInu/replace-mongobee
Browse files Browse the repository at this point in the history
Replace mongobee
  • Loading branch information
hoegertn authored Aug 30, 2022
2 parents 3818223 + f4c81eb commit 4083b09
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 169 deletions.
21 changes: 12 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
* Jetty 9.4.48.v20220622
* Joda-Time 2.11.1
* ActiveMQ 5.16.5
* Log4J 2.18.0
* Guava 31.1
* Commons Codec 1.15
* Mongo Java Server 1.40.0
* Log4J 2.18.0
* Guava 31.1
* Commons Codec 1.15
* Mongo Java Server 1.40.0
* Liquibase 4.11.0
* Mongo Java Driver 3.12.11
* Mongo Java Driver 4.7.0
* Bson 2.13.1
* Nimbus JOSE+JWT 9.23
* JSON Small and Fast Parser 2.4.8
* Swagger 2.2.2
* etcd4j 2.18.0
* Hazelcast 5.1.3
* XDocReport 2.0.4
* etcd4j 2.18.0
* Hazelcast 5.1.3
* XDocReport 2.0.4
* Bouncycastle Provider 1.71.1
* Moved Mongo Java Server to optional dependency (in most cases Fake Mongo is not needed or can be added)

* Moved Mongo Java Server to optional dependency (in most cases Fake Mongo is not needed or can be added)
* BREAKING: replaced mongobee with Mongock (5.0.36), mostly backwards compatibility but configuration(see Class `MongoDBConfig`) and annotations (@Changelog and @ChangeSet) have to be replaced by Mongock equivalent https://docs.mongock.io/v5/features/legacy-migration/index.html

## 1.32
* Update dependencies
Expand Down
29 changes: 22 additions & 7 deletions mongodb/dvalin-mongodb.iml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,31 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.7" level="project" />
<orderEntry type="library" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.2" level="project" />
<orderEntry type="library" name="Maven: jakarta.activation:jakarta.activation-api:1.2.1" level="project" />
<orderEntry type="library" name="Maven: de.undercouch:bson4jackson:2.12.0" level="project" />
<orderEntry type="library" name="Maven: de.undercouch:bson4jackson:2.13.1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.22" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.22" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.22" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.12.11" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-legacy:4.7.0" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:bson:4.7.0" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-core:4.7.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.mongodb:bson-record-codec:4.7.0" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongodb-driver-sync:4.7.0" level="project" />
<orderEntry type="library" name="Maven: org.jongo:jongo:1.5.0" level="project" />
<orderEntry type="library" name="Maven: com.github.mongobee:mongobee:0.12" level="project" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.9" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.18.2-GA" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-standalone:5.0.36" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-standalone-base:5.0.36" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-runner-core:5.0.36" level="project" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.10.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-artifact:3.6.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-utils:3.2.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongodb-sync-v4-driver:5.0.36" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-driver-core:5.0.36" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-driver-api:5.0.36" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.28.0-GA" level="project" />
<orderEntry type="library" name="Maven: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-utils:5.0.36" level="project" />
<orderEntry type="library" name="Maven: io.mongock:mongock-api:5.0.36" level="project" />
<orderEntry type="library" name="Maven: de.bwaldvogel:mongo-java-server:1.40.0" level="project" />
<orderEntry type="library" name="Maven: de.bwaldvogel:mongo-java-server-core:1.40.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.netty:netty-transport:4.1.77.Final" level="project" />
Expand Down Expand Up @@ -86,6 +101,6 @@
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-mockito2:2.0.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-support:2.0.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:3.3.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.6" level="project" />
</component>
</module>
47 changes: 20 additions & 27 deletions mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
<inceptionYear>2015</inceptionYear>
<properties>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-bom</artifactId>
<version>${mongock.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.taimos</groupId>
Expand Down Expand Up @@ -43,7 +54,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-legacy</artifactId>
</dependency>
<dependency>
<groupId>org.jongo</groupId>
Expand All @@ -69,32 +80,14 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.github.mongobee</groupId>
<artifactId>mongobee</artifactId>
<version>${mongobee.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.data</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.jongo</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-standalone</artifactId>
</dependency>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongodb-sync-v4-driver</artifactId>
<!--<artifactId>mongodb-v3-driver</artifactId> for MongoDB driver v3-->
</dependency>
<dependency>
<groupId>de.bwaldvogel</groupId>
<artifactId>mongo-java-server</artifactId>
Expand Down
24 changes: 8 additions & 16 deletions mongodb/src/main/java/de/taimos/dvalin/mongo/MongoDBInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@

import javax.annotation.PostConstruct;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import de.taimos.daemon.spring.conditional.OnSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;

import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.util.JSON;

import de.taimos.daemon.spring.conditional.OnSystemProperty;


/**
* Copyright 2014 Taimos GmbH<br>
Expand Down Expand Up @@ -86,14 +84,8 @@ public void initDatabase() {
int lines = 0;
while (scan.hasNextLine()) {
String json = scan.nextLine();
Object parse = JSON.parse(json);
if (parse instanceof DBObject) {
DBObject dbObject = (DBObject) parse;
dbCollection.insertOne(dbObject);
} else {
MongoDBInit.LOGGER.error("Invalid object found: {}", parse);
throw new RuntimeException("Invalid object");
}
DBObject parse = BasicDBObject.parse(json);
dbCollection.insertOne(parse);
lines++;
}
MongoDBInit.LOGGER.info("Imported {} objects into collection {}", lines, collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
* #L%
*/

import com.mongodb.ConnectionString;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoClients;
import de.bwaldvogel.mongo.MongoServer;
import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.taimos.daemon.spring.conditional.OnSystemProperty;
Expand All @@ -45,4 +47,11 @@ public MongoClient mongoClient(MongoServer mongoServer) {
return new MongoClient(new ServerAddress(mongoServer.bind()));
}

@Bean
public com.mongodb.client.MongoClient mongoClient2(MongoServer mongoServer) {
ServerAddress serverAddress = new ServerAddress(mongoServer.bind());
ConnectionString uri = new ConnectionString(String.format("mongodb://%s:%d", serverAddress.getHost(), serverAddress.getPort()));
return MongoClients.create(uri);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@
* #L%
*/

import com.github.mongobee.Mongobee;
import java.util.concurrent.TimeUnit;

import com.mongodb.DB;
import com.mongodb.MongoClient;
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoDatabase;
import de.taimos.dvalin.mongo.JongoFactory;
import io.mongock.api.config.LegacyMigration;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import io.mongock.runner.standalone.RunnerStandaloneBuilder;
import org.jongo.Jongo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -32,23 +41,34 @@
@Configuration
public class MongoDBConfig {

@Value("${mongobee.enabled:false}")
private boolean beeEnabled;
@Value("${mongock.enabled:false}")
private boolean mongockEnabled;

@Value("${mongock.legacyMigration.table:dbchangelog}")
private String mongockLegacyTable;

@Value("${mongodb.name}")
private String dbName;

@Value("${mongobee.basepackage:${mongobee.basePackage:}}")
private String beeBasePackage;
@Value("${mongock.basepackage:${mongock.basePackage:}}")
private String basePackage;

@Bean
public Mongobee mongobee(MongoClient mongoClient, Jongo jongo) {
Mongobee bee = new Mongobee(mongoClient);
bee.setDbName(this.dbName);
bee.setEnabled(this.beeEnabled);
bee.setChangeLogsScanPackage(this.beeBasePackage);
bee.setJongo(jongo);
return bee;
public RunnerStandaloneBuilder mongockRunner(com.mongodb.client.MongoClient mongoClient, Jongo jongo) {

MongoSync4Driver driver = MongoSync4Driver.withDefaultLock(mongoClient, this.dbName);
driver.setWriteConcern(WriteConcern.MAJORITY.withJournal(true).withWTimeout(1000, TimeUnit.MILLISECONDS));
driver.setReadConcern(ReadConcern.MAJORITY);
driver.setReadPreference(ReadPreference.primary());
driver.disableTransaction();


LegacyMigration legacyMigration = new LegacyMigration();
legacyMigration.setOrigin(this.mongockLegacyTable);
RunnerStandaloneBuilder runnerStandaloneBuilder = MongockStandalone.builder().setDriver(driver).setTransactionEnabled(false).addMigrationScanPackage(this.basePackage);
runnerStandaloneBuilder.setLegacyMigration(legacyMigration).addDependency(jongo).buildRunner().execute();

return runnerStandaloneBuilder;
}

@Bean
Expand All @@ -58,7 +78,11 @@ public MongoDatabase mongoDatabase(MongoClient mongoClient) {

@Bean
public Jongo jongo(MongoClient mongoClient) {
return JongoFactory.createDefault(mongoClient.getDB(dbName));
return JongoFactory.createDefault(mongoClient.getDB(this.dbName));
}

@Bean
public DB mongoDB(MongoClient mongoClient){
return mongoClient.getDB(this.dbName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
* #L%
*/

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;

import com.mongodb.client.MongoClients;
import de.taimos.daemon.spring.conditional.OnSystemProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@OnSystemProperty(propertyName = "mongodb.type", propertyValue = "real")
Expand All @@ -54,6 +53,14 @@ public MongoClient mongoClient() {
return new MongoClient(new MongoClientURI(this.mongoURI, builder));
}

@Bean
public com.mongodb.client.MongoClient mongoClient2() {
MongoClientOptions.Builder builder = MongoClientOptions.builder();
builder.socketTimeout(this.socketTimeout);
builder.connectTimeout(this.connectTimeout);
return MongoClients.create(new MongoClientURI(this.mongoURI, builder).getURI());
}



}

This file was deleted.

Loading

0 comments on commit 4083b09

Please sign in to comment.