Setting operational attributes for mongo also when configured via URI.
This commit is contained in:
parent
8e391ffa4e
commit
eb197c46f7
1 changed files with 11 additions and 2 deletions
|
@ -148,15 +148,25 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
*/
|
*/
|
||||||
protected MongoClient createMongoClient() throws UnknownHostException {
|
protected MongoClient createMongoClient() throws UnknownHostException {
|
||||||
|
operationalInfo = new LinkedHashMap<>();
|
||||||
|
String dbName = config.get("db", "keycloak");
|
||||||
|
|
||||||
String uriString = config.get("uri");
|
String uriString = config.get("uri");
|
||||||
if (uriString != null) {
|
if (uriString != null) {
|
||||||
MongoClientURI uri = new MongoClientURI(uriString);
|
MongoClientURI uri = new MongoClientURI(uriString);
|
||||||
MongoClient client = new MongoClient(uri);
|
MongoClient client = new MongoClient(uri);
|
||||||
|
|
||||||
|
String hosts = String.join(", ", uri.getHosts());
|
||||||
|
operationalInfo.put("mongoHosts", hosts);
|
||||||
|
operationalInfo.put("mongoDatabaseName", dbName);
|
||||||
|
operationalInfo.put("mongoUser", uri.getUsername());
|
||||||
|
operationalInfo.put("mongoDriverVersion", client.getVersion());
|
||||||
|
|
||||||
|
logger.debugv("Initialized mongo model. host(s): %s, db: %s", uri.getHosts(), dbName);
|
||||||
return client;
|
return client;
|
||||||
} else {
|
} else {
|
||||||
String host = config.get("host", ServerAddress.defaultHost());
|
String host = config.get("host", ServerAddress.defaultHost());
|
||||||
int port = config.getInt("port", ServerAddress.defaultPort());
|
int port = config.getInt("port", ServerAddress.defaultPort());
|
||||||
String dbName = config.get("db", "keycloak");
|
|
||||||
|
|
||||||
String user = config.get("user");
|
String user = config.get("user");
|
||||||
String password = config.get("password");
|
String password = config.get("password");
|
||||||
|
@ -171,7 +181,6 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro
|
||||||
client = new MongoClient(new ServerAddress(host, port), clientOptions);
|
client = new MongoClient(new ServerAddress(host, port), clientOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
operationalInfo = new LinkedHashMap<>();
|
|
||||||
operationalInfo.put("mongoServerAddress", client.getAddress().toString());
|
operationalInfo.put("mongoServerAddress", client.getAddress().toString());
|
||||||
operationalInfo.put("mongoDatabaseName", dbName);
|
operationalInfo.put("mongoDatabaseName", dbName);
|
||||||
operationalInfo.put("mongoUser", user);
|
operationalInfo.put("mongoUser", user);
|
||||||
|
|
Loading…
Reference in a new issue