Skip to content

Commit

Permalink
upgrade mongo dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Aug 22, 2024
1 parent 3b4e7e7 commit 02e6488
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ dependencies {
exclude group: 'javax.servlet', module: 'servlet-api' // 2.5 vs 3.0.1 above
}
implementation 'org.ini4j:ini4j:0.5.2'
implementation 'org.mongodb:mongo-java-driver:3.8.2'
implementation 'org.mongodb:mongodb-driver-core:4.11.1'
implementation 'org.mongodb:mongodb-driver-sync:4.11.1'
implementation 'org.mongodb:bson-record-codec:4.11.1'
implementation 'org.mongodb:bson:4.11.1'
implementation 'org.apache.kafka:kafka-clients:2.1.0'
implementation 'com.google.guava:guava:18.0'
implementation 'org.slf4j:slf4j-api:1.7.25'
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/us/kbase/groups/build/GroupsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableMap;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.MongoException;
import com.mongodb.ServerAddress;
Expand Down Expand Up @@ -106,15 +107,16 @@ public GroupsBuilder(final GroupsConfig cfg, final MongoClient mc)

private MongoClient buildMongo(final GroupsConfig c) throws StorageInitException {
//TODO ZLATER MONGO handle shards & replica sets
final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder().applyToClusterSettings(
builder -> builder.hosts(Arrays.asList(new ServerAddress(c.getMongoHost()))));
try {
if (c.getMongoUser().isPresent()) {
final MongoCredential creds = MongoCredential.createCredential(
c.getMongoUser().get(), c.getMongoDatabase(), c.getMongoPwd().get());
// unclear if and when it's safe to clear the password
return new MongoClient(new ServerAddress(c.getMongoHost()), creds,
MongoClientOptions.builder().build());
return MongoClients.create(mongoBuilder.credential(creds).build());
} else {
return new MongoClient(new ServerAddress(c.getMongoHost()));
return MongoClients.create(mongoBuilder.build());
}
} catch (MongoException e) {
LoggerFactory.getLogger(getClass()).error(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/us/kbase/groups/service/GroupsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.LoggerFactory;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoClient;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import org.bson.Document;

import com.github.zafarkhaja.semver.Version;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;

import us.kbase.groups.core.resource.ResourceType;
Expand All @@ -39,7 +40,7 @@ public MongoStorageTestManager(final String dbName) throws Exception {
wiredTiger = TestCommon.useWiredTigerEngine();
System.out.println(String.format("Testing against mongo executable %s on port %s",
TestCommon.getMongoExe(), mongo.getServerPort()));
mc = new MongoClient("localhost:" + mongo.getServerPort());
mc = MongoClients.create("mongodb://localhost:" + mongo.getServerPort());
db = mc.getDatabase(dbName);

final Document bi = db.runCommand(new Document("buildinfo", 1));
Expand Down

0 comments on commit 02e6488

Please sign in to comment.