Skip to content

Commit

Permalink
pom: Update mongodb-driver
Browse files Browse the repository at this point in the history
Motivation:

\#7257 happened due to conflicting dependencies with dCache using an older version of the MongoDB-Driver.

Modification:

Replace mongo-java-driver, which is not maintained anymore, with the newest version of mongo-driver-sync. Update the code to work with the new version.

Result:

The MongoDB driver is updated

Target: master
Request: 9.2, 9.1, 9.0, 8.2
Requires-notes: yes
Requires-book: no
Acked-by: Tigran
  • Loading branch information
svemeyer committed Nov 29, 2023
1 parent fc02003 commit a83cc7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion modules/dcache/pom.xml
Expand Up @@ -313,7 +313,7 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>

<dependency>
Expand Down
Expand Up @@ -6,10 +6,11 @@
import static org.dcache.util.Exceptions.messageOrClassName;

import com.google.common.base.Stopwatch;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoException;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.event.ServerClosedEvent;
import com.mongodb.event.ServerDescriptionChangedEvent;
Expand Down Expand Up @@ -130,14 +131,13 @@ public MongoDbMetadataRepository(FileStore fileStore, Path ignored, String poolN

@Override
public void init() throws CacheException {
MongoClientSettings settings = MongoClientSettings.builder()
.applicationName("dCache-" + Version.of(MongoDbMetadataRepository.class).getVersion())
.applyToServerSettings(builder -> builder.addServerListener(this))
.applyConnectionString(new ConnectionString(url))
.build();
mongo = MongoClients.create(settings);

MongoClientOptions.Builder optionBuilder = new MongoClientOptions.Builder()
.addServerListener(this)
.description(pool)
.applicationName(
"dCache-" + Version.of(MongoDbMetadataRepository.class).getVersion());

mongo = new MongoClient(new MongoClientURI(url, optionBuilder));
collection = mongo.getDatabase(dbName).getCollection(collectionName);
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public long getTotalSpace() {

@Override
public String toString() {
return String.format("[data=%s;meta=%s]", fileStore, mongo.getConnectPoint());
return String.format("[data=%s;meta=%s]", fileStore, url);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -832,8 +832,8 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.4.2</version>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.11.1</version>
</dependency>

<dependency>
Expand Down

0 comments on commit a83cc7f

Please sign in to comment.