diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 785246e..7291dd2 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -2,9 +2,11 @@ A lightweight service to store public KBase user profiles and related basic information. -## VERSION: 0.3.0 (Released TDB) +## VERSION: 0.3.0 (Released 10/9/24) -* Switched the build system from Make / Ant to Gradle +* The MongoDB clients have been updated to the most recent version. +* Added the ``mongo-retrywrites`` configuration setting in ``deploy.cfg``, defaulting to ``false``. +* Switched the build system from Make / Ant to Gradle. * The `lookup_globus_user` method was removed. * The `globus-url` configuration parameter was removed. diff --git a/deploy.cfg b/deploy.cfg index c55d0bb..0e07b07 100644 --- a/deploy.cfg +++ b/deploy.cfg @@ -21,6 +21,10 @@ mongodb-database = user_profile_db # password for the account #mongodb-pwd = add password here +# Whether to enable ('true') the MongoDB retryWrites parameter or not (anything other than 'true'). +# See https://www.mongodb.com/docs/manual/core/retryable-writes/ +mongodb-retrywrites=false + # the user name for an administrator admin = kbuserprofileadmin diff --git a/deployment/conf/.templates/deployment.cfg.templ b/deployment/conf/.templates/deployment.cfg.templ index 68d5a58..b30ba1f 100644 --- a/deployment/conf/.templates/deployment.cfg.templ +++ b/deployment/conf/.templates/deployment.cfg.templ @@ -21,6 +21,9 @@ mongodb-user = {{ default .Env.mongodb_user "" }} # password for the account mongodb-pwd = {{ default .Env.mongodb_pwd "" }} +# whether to enable the MongoDB retryWrites parameter or not +mongodb-retrywrites={{ default .Env.mongodb_retrywrites "false" }} + # the user name for an administrator admin = {{ default .Env.admin "kbuserprofileadmin" }} diff --git a/src/main/java/us/kbase/userprofile/MongoController.java b/src/main/java/us/kbase/userprofile/MongoController.java index 0afeb35..40e38e4 100644 --- a/src/main/java/us/kbase/userprofile/MongoController.java +++ b/src/main/java/us/kbase/userprofile/MongoController.java @@ -31,22 +31,26 @@ public class MongoController { private final MongoCollection profiles; - public MongoController(final String host, final String database) { - final MongoDatabase db = getDB(host, database, null, null); + public MongoController(final String host, final String database, final boolean mongoRetryWrites) { + final MongoDatabase db = getDB(host, database, null, null, mongoRetryWrites); profiles = db.getCollection(COL_PROFILES); ensureIndex(); } public MongoController(final String host, final String database, - final String mongoUser, final String mongoPswd) { - final MongoDatabase db = getDB(host, database, mongoUser, mongoPswd); + final String mongoUser, final String mongoPswd, + final boolean mongoRetryWrites) { + final MongoDatabase db = getDB(host, database, mongoUser, mongoPswd, mongoRetryWrites); profiles = db.getCollection(COL_PROFILES); ensureIndex(); } - private MongoDatabase getDB(final String host, final String db, final String user, final String pwd) { - final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder().applyToClusterSettings( - builder -> builder.hosts(Arrays.asList(new ServerAddress(host)))); + private MongoDatabase getDB(final String host, final String db, final String user, + final String pwd, final boolean retryWrites) { + final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder() + .retryWrites(retryWrites) + .applyToClusterSettings( + builder -> builder.hosts(Arrays.asList(new ServerAddress(host)))); final MongoClient cli; if (user != null) { final MongoCredential creds = MongoCredential.createCredential( diff --git a/src/main/java/us/kbase/userprofile/UserProfileServer.java b/src/main/java/us/kbase/userprofile/UserProfileServer.java index 9a80b92..6c55731 100644 --- a/src/main/java/us/kbase/userprofile/UserProfileServer.java +++ b/src/main/java/us/kbase/userprofile/UserProfileServer.java @@ -37,8 +37,10 @@ public class UserProfileServer extends JsonServerServlet { public static final String CFG_MONGO_DB = "mongodb-database"; public static final String CFG_MONGO_USER = "mongodb-user"; public static final String CFG_MONGO_PSWD = "mongodb-pwd"; + public static final String CFG_MONGO_RETRY_WRITES = "mongodb-retrywrites"; public static final String CFG_ADMIN = "admin"; + public static final String TRUE = "true"; private static Throwable configError = null; private static Map config = null; @@ -90,18 +92,14 @@ public UserProfileServer() throws Exception { } catch (Exception e) { useMongoAuth = false; } - + + final boolean mongoRetryWrites = TRUE.equals(getConfig(CFG_MONGO_RETRY_WRITES)); + if(useMongoAuth) { - db = new MongoController( - getConfig(CFG_MONGO_HOST), - getConfig(CFG_MONGO_DB), - mongoUser, - getConfig(CFG_MONGO_PSWD) - ); + db = new MongoController(getConfig(CFG_MONGO_HOST), getConfig(CFG_MONGO_DB), + mongoUser, getConfig(CFG_MONGO_PSWD), mongoRetryWrites); } else { - db = new MongoController( - getConfig(CFG_MONGO_HOST), - getConfig(CFG_MONGO_DB)); + db = new MongoController(getConfig(CFG_MONGO_HOST), getConfig(CFG_MONGO_DB), mongoRetryWrites); } //END_CONSTRUCTOR } diff --git a/src/test/java/us/kbase/test/userprofile/FullServerTest.java b/src/test/java/us/kbase/test/userprofile/FullServerTest.java index 1f77ef9..63ede21 100644 --- a/src/test/java/us/kbase/test/userprofile/FullServerTest.java +++ b/src/test/java/us/kbase/test/userprofile/FullServerTest.java @@ -232,6 +232,7 @@ public static void setUpClass() throws Exception { ws.add(UserProfileServer.CFG_MONGO_HOST, "localhost:" + MONGO.getServerPort()); ws.add(UserProfileServer.CFG_MONGO_DB , "user_profile_test"); ws.add(UserProfileServer.CFG_ADMIN, adminAuthToken.getUserName()); + ws.add(UserProfileServer.CFG_MONGO_RETRY_WRITES, "false"); ws.add("auth-service-url", authServiceUrl); ws.add("auth-service-url-allow-insecure", authAllowInsecureString);