Skip to content

Commit

Permalink
Merge pull request #395 from kbase/dev-add_retryWrites
Browse files Browse the repository at this point in the history
add retryWrites
  • Loading branch information
Xiangs18 authored Aug 27, 2024
2 parents 5316580 + 7ab4105 commit ff5bc82
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# KBase Groups Service release notes

## 0.1.8

* The MongoDB clients have been updated to the most recent version.
* Added the ``mongo-retrywrites`` configuration setting in ``deploy.cfg``, defaulting to
``false``.

## 0.1.7

* The build tool has been switched from Ant to Gradle.
Expand Down
4 changes: 4 additions & 0 deletions deploy.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ mongo-db=
mongo-user=
mongo-pwd=

# Whether to enable ('true') the MongoDB retryWrites parameter or not (anything other than 'true').
# See https://www.mongodb.com/docs/manual/core/retryable-writes/
mongo-retrywrites=false

# KBase Auth server root url.
auth-url=https://ci.kbase.us/services/auth

Expand Down
1 change: 1 addition & 0 deletions deployment/conf/.templates/deployment.cfg.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mongo-host={{ default .Env.mongo_host "ci-mongo" }}
mongo-db={{ default .Env.mongo_db "groups" }}
mongo-user={{ default .Env.mongo_user "" }}
mongo-pwd={{ default .Env.mongo_pwd "" }}
mongo-retrywrites={{ default .Env.mongo_retrywrites "false" }}
auth-url={{ default .Env.auth_url "https://ci.kbase.us/services/auth" }}
workspace-url={{ default .Env.workspace_url "https://ci.kbase.us/services/ws" }}
workspace-admin-token={{ default .Env.workspace_admin_token ""}}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/us/kbase/groups/build/GroupsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ public GroupsBuilder(final GroupsConfig cfg, final MongoClient mc)

private MongoClient buildMongo(final GroupsConfig c) throws StorageInitException {
//TODO ZLATER MONGO handle shards & replica sets
final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder().applyToClusterSettings(
builder -> builder.hosts(Arrays.asList(new ServerAddress(c.getMongoHost()))));
final MongoClientSettings.Builder mongoBuilder = MongoClientSettings.builder()
.retryWrites(c.getMongoRetryWrites())
.applyToClusterSettings(builder -> builder.hosts(
Arrays.asList(new ServerAddress(c.getMongoHost()))));
try {
if (c.getMongoUser().isPresent()) {
final MongoCredential creds = MongoCredential.createCredential(
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/us/kbase/groups/config/GroupsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class GroupsConfig {
private static final String KEY_MONGO_DB = "mongo-db";
private static final String KEY_MONGO_USER = "mongo-user";
private static final String KEY_MONGO_PWD = "mongo-pwd";
private static final String KEY_MONGO_RETRY_WRITES = "mongo-retrywrites";
private static final String KEY_AUTH_URL = "auth-url";
private static final String KEY_WORKSPACE_URL = "workspace-url";
private static final String KEY_WORKSPACE_TOKEN = "workspace-admin-token";
Expand Down Expand Up @@ -81,6 +82,7 @@ public class GroupsConfig {
private final String mongoDB;
private final Optional<String> mongoUser;
private final Optional<char[]> mongoPwd;
private final boolean mongoRetryWrites;
private final URL authURL;
private final URL workspaceURL;
private final Token workspaceAdminToken;
Expand Down Expand Up @@ -148,6 +150,7 @@ private GroupsConfig(
notifierParameters = getParams(KEY_PREFIX_NOTIFIER_PARAMS, cfg);
mongoHost = getString(KEY_MONGO_HOST, cfg, true);
mongoDB = getString(KEY_MONGO_DB, cfg, true);
mongoRetryWrites = TRUE.equals(getString(KEY_MONGO_RETRY_WRITES, cfg));
mongoUser = Optional.fromNullable(getString(KEY_MONGO_USER, cfg));
Optional<String> mongop = Optional.fromNullable(getString(KEY_MONGO_PWD, cfg));
if (mongoUser.isPresent() ^ mongop.isPresent()) {
Expand Down Expand Up @@ -420,13 +423,20 @@ public String getMongoHost() {
return mongoHost;
}

/** Ge the MongoDB database to use.
/** Get the MongoDB database to use.
* @return the database.
*/
public String getMongoDatabase() {
return mongoDB;
}

/** Get whether the MongoDB retryWrites parameter should be set.
* @return True to set the retryWrites parameter when connecting to MongoDB, false otherwise.
*/
public boolean getMongoRetryWrites() {
return mongoRetryWrites;
}

/** Get the MongoDB user name, if any. If provided a password will also be provided.
* @return the user name
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/us/kbase/groups/service/api/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Root {
//TODO ZLATER ROOT add configurable contact email or link
//TODO ZLATER swagger

private static final String VERSION = "0.1.7";
private static final String VERSION = "0.1.8";
private static final String SERVER_NAME = "Groups service";

/** Return the root information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void sysPropNoUserNoBools() throws Throwable {
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.absent()));
assertThat("incorrect mongo pwd", cfg.getMongoPwd(), is(Optional.absent()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect auth url", cfg.getAuthURL(), is(new URL("http://auth.com")));
assertThat("incorrect catalog url", cfg.getCatalogURL(), is(new URL("http://cat.com")));
assertThat("incorrect ws url", cfg.getWorkspaceURL(), is(new URL("http://ws.com")));
Expand Down Expand Up @@ -116,6 +117,7 @@ public void sysPropNoUserNoBoolsWhitespaceFields() throws Throwable {
"mongo-db=database\n" +
"mongo-user=\n" +
"mongo-pwd=\n" +
"mongo-retrywrites= false \n" +
"notifier-factory= factoryclass \n" +
"notifier-param-p1 = np1 \n" +
"notifier-param-p2 = np2 \n" +
Expand Down Expand Up @@ -165,6 +167,7 @@ public void sysPropNoUserNoBoolsWhitespaceFields() throws Throwable {
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.absent()));
assertThat("incorrect mongo pwd", cfg.getMongoPwd(), is(Optional.absent()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect auth url", cfg.getAuthURL(), is(new URL("http://auth.com")));
assertThat("incorrect catalog url", cfg.getCatalogURL(), is(new URL("http://cat.com")));
assertThat("incorrect ws url", cfg.getWorkspaceURL(), is(new URL("http://ws.com")));
Expand Down Expand Up @@ -241,6 +244,7 @@ public void envVarWithUserWithBools() throws Throwable {
"mongo-db=database\n" +
"mongo-user=userfoo\n" +
"mongo-pwd=somepwd\n" +
"mongo-retrywrites=true \n" +
"notifier-factory= factoryclass \n" +
"auth-url=https://auth.com\n" +
"catalog-url= http://cat.com \n" +
Expand All @@ -256,6 +260,7 @@ public void envVarWithUserWithBools() throws Throwable {

assertThat("incorrect mongo host", cfg.getMongoHost(), is("mongo"));
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(true));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.of("userfoo")));
assertThat("incorrect mongo pwd", cfg.getMongoPwd().get(),
equalTo("somepwd".toCharArray()));
Expand Down Expand Up @@ -292,6 +297,7 @@ public void pathNoUserNoBoolsStdLogger() throws Throwable {
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.absent()));
assertThat("incorrect mongo pwd", cfg.getMongoPwd(), is(Optional.absent()));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(false));
assertThat("incorrect auth url", cfg.getAuthURL(), is(new URL("https://auth.com")));
assertThat("incorrect catalog url", cfg.getCatalogURL(), is(new URL("http://cat.com")));
assertThat("incorrect ws url", cfg.getWorkspaceURL(), is(new URL("https://ws.com")));
Expand All @@ -315,6 +321,7 @@ public void pathWithUserWithBoolsNullLogger() throws Throwable {
"mongo-db=database\n" +
"mongo-user=userfoo\n" +
"mongo-pwd=somepwd\n" +
"mongo-retrywrites=true\n" +
"notifier-factory= factoryclass \n" +
"auth-url=https://auth.com\n" +
"catalog-url= http://cat.com \n" +
Expand All @@ -327,6 +334,7 @@ public void pathWithUserWithBoolsNullLogger() throws Throwable {

assertThat("incorrect mongo host", cfg.getMongoHost(), is("mongo"));
assertThat("incorrect mongo db", cfg.getMongoDatabase(), is("database"));
assertThat("incorrect retry writes", cfg.getMongoRetryWrites(), is(true));
assertThat("incorrect mongo user", cfg.getMongoUser(), is(Optional.of("userfoo")));
assertThat("incorrect mongo pwd", cfg.getMongoPwd().get(),
equalTo("somepwd".toCharArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class RootTest {

public static final String SERVER_VER = "0.1.7";
public static final String SERVER_VER = "0.1.8";
private static final String GIT_ERR =
"Missing git commit file gitcommit, should be in us.kbase.groups";

Expand Down

0 comments on commit ff5bc82

Please sign in to comment.