Skip to content

Commit

Permalink
Merge pull request #21 from kbase/dev-add_retryWrites
Browse files Browse the repository at this point in the history
Add retryWrites
  • Loading branch information
Xiangs18 authored Oct 10, 2024
2 parents f182149 + 972e12a commit 1cb58fd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
6 changes: 4 additions & 2 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions deploy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions deployment/conf/.templates/deployment.cfg.templ
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}

Expand Down
18 changes: 11 additions & 7 deletions src/main/java/us/kbase/userprofile/MongoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ public class MongoController {

private final MongoCollection<Document> 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(
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/us/kbase/userprofile/UserProfileServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> config = null;

Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1cb58fd

Please sign in to comment.