MongoDB Replica Set connections cannot resolve (#776 & #777)

This commit is contained in:
Andrew 2018-02-20 14:59:29 -05:00 committed by Luck
parent 31e436868d
commit 9c92522564
7 changed files with 53 additions and 24 deletions

View File

@ -329,6 +329,10 @@ data:
# collections for different servers. The default is no prefix.
mongodb_collection_prefix: ''
# MongoDB ClientConnectionURI for use with replicasets and custom connection options
# See https://docs.mongodb.com/manual/reference/connection-string/
mongodb_connection_URI: ''
# This option controls how frequently LuckPerms will perform a sync task.
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is
# being used by the plugin.

View File

@ -271,6 +271,10 @@ data:
# collections for different servers. The default is no prefix.
mongodb_collection_prefix: ''
# MongoDB ClientConnectionURI for use with replicasets and custom connection options
# See https://docs.mongodb.com/manual/reference/connection-string/
mongodb_connection_URI: ''
# This option controls how frequently LuckPerms will perform a sync task.
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is
# being used by the plugin.

View File

@ -405,6 +405,11 @@ public class ConfigKeys {
*/
public static final ConfigKey<String> MONGODB_COLLECTION_PREFIX = EnduringKey.wrap(StringKey.of("data.mongodb_collection_prefix", ""));
/**
* MongoDB ClientConnectionURI to override default connection options
*/
public static final ConfigKey<String> MONGODB_CONNECTION_URI = EnduringKey.wrap(StringKey.of("data.mongodb_connection_URI", ""));
/**
* The name of the storage method being used
*/

View File

@ -158,7 +158,8 @@ public class StorageFactory {
return new MongoDao(
this.plugin,
this.plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES),
this.plugin.getConfiguration().get(ConfigKeys.MONGODB_COLLECTION_PREFIX)
this.plugin.getConfiguration().get(ConfigKeys.MONGODB_COLLECTION_PREFIX),
this.plugin.getConfiguration().get(ConfigKeys.MONGODB_CONNECTION_URI)
);
case YAML:
return new YamlDao(this.plugin, "yaml-storage");

View File

@ -28,6 +28,7 @@ package me.lucko.luckperms.common.storage.dao.mongodb;
import com.google.common.base.Strings;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
@ -77,15 +78,20 @@ public class MongoDao extends AbstractDao {
private MongoClient mongoClient;
private MongoDatabase database;
private final String prefix;
private final String connectionURI;
public MongoDao(LuckPermsPlugin plugin, StorageCredentials configuration, String prefix) {
public MongoDao(LuckPermsPlugin plugin, StorageCredentials configuration, String prefix, String connectionURI) {
super(plugin, "MongoDB");
this.configuration = configuration;
this.prefix = prefix;
this.connectionURI = connectionURI;
}
@Override
public void init() {
if (!Strings.isNullOrempty(this.connectionURI)) {
this.mongoClient = new MongoClient(new MongoClientURI(this.connectionURI));
} else {
MongoCredential credential = null;
if (!Strings.isNullOrEmpty(this.configuration.getUsername())) {
credential = MongoCredential.createCredential(
@ -105,6 +111,7 @@ public class MongoDao extends AbstractDao {
} else {
this.mongoClient = new MongoClient(address, credential, MongoClientOptions.builder().build());
}
}
this.database = this.mongoClient.getDatabase(this.configuration.getDatabase());
}

View File

@ -329,6 +329,10 @@ data:
# collections for different servers. The default is no prefix.
mongodb_collection_prefix: ''
# MongoDB ClientConnectionURI for use with replicasets and custom connection options
# See https://docs.mongodb.com/manual/reference/connection-string/
mongodb_connection_URI: ''
# This option controls how frequently LuckPerms will perform a sync task.
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is
# being used by the plugin.

View File

@ -278,6 +278,10 @@ data {
# collections for different servers. The default is no prefix.
mongodb_collection_prefix=""
# MongoDB ClientConnectionURI for use with replicasets and custom connection options
# See https://docs.mongodb.com/manual/reference/connection-string/
mongodb_connection_URI=""
# This option controls how frequently LuckPerms will perform a sync task.
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is
# being used by the plugin.