From 48e5aa04d3ff0683bf38be2a1b4704e8c54cb1a2 Mon Sep 17 00:00:00 2001 From: Sijie Date: Wed, 2 Oct 2024 15:51:46 -0700 Subject: [PATCH 1/3] update release notes --- RELEASE_NOTES.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 785246e..854a7ec 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -2,9 +2,12 @@ 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/3/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. From a161722fb590ac846e3aae9d85c557754f37d81e Mon Sep 17 00:00:00 2001 From: Sijie Date: Wed, 9 Oct 2024 15:49:55 -0700 Subject: [PATCH 2/3] update release notes && add retryWrites param --- RELEASE_NOTES.txt | 5 ++--- deploy.cfg | 4 ++++ .../conf/.templates/deployment.cfg.templ | 3 +++ .../us/kbase/userprofile/MongoController.java | 18 +++++++++++------- .../kbase/userprofile/UserProfileServer.java | 18 ++++++++---------- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 854a7ec..7291dd2 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -2,11 +2,10 @@ A lightweight service to store public KBase user profiles and related basic information. -## VERSION: 0.3.0 (Released 10/3/24) +## VERSION: 0.3.0 (Released 10/9/24) * The MongoDB clients have been updated to the most recent version. -* Added the ``mongo-retrywrites`` configuration setting in ``deploy.cfg``, defaulting to - ``false``. +* 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 } From 972e12ae703586e57eb0897d8d5edabdc6962c65 Mon Sep 17 00:00:00 2001 From: Sijie Date: Wed, 9 Oct 2024 16:11:11 -0700 Subject: [PATCH 3/3] add missing retryWrites param into the test config --- src/test/java/us/kbase/test/userprofile/FullServerTest.java | 1 + 1 file changed, 1 insertion(+) 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);