diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 67576215..faffaada 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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. diff --git a/deploy.cfg.example b/deploy.cfg.example index 49547470..fc262f26 100644 --- a/deploy.cfg.example +++ b/deploy.cfg.example @@ -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 diff --git a/deployment/conf/.templates/deployment.cfg.templ b/deployment/conf/.templates/deployment.cfg.templ index 46f7e870..8dc4f5fe 100644 --- a/deployment/conf/.templates/deployment.cfg.templ +++ b/deployment/conf/.templates/deployment.cfg.templ @@ -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 ""}} diff --git a/src/main/java/us/kbase/groups/build/GroupsBuilder.java b/src/main/java/us/kbase/groups/build/GroupsBuilder.java index ca05883f..fd511d3b 100644 --- a/src/main/java/us/kbase/groups/build/GroupsBuilder.java +++ b/src/main/java/us/kbase/groups/build/GroupsBuilder.java @@ -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( diff --git a/src/main/java/us/kbase/groups/config/GroupsConfig.java b/src/main/java/us/kbase/groups/config/GroupsConfig.java index b752f09b..47d9df30 100644 --- a/src/main/java/us/kbase/groups/config/GroupsConfig.java +++ b/src/main/java/us/kbase/groups/config/GroupsConfig.java @@ -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"; @@ -81,6 +82,7 @@ public class GroupsConfig { private final String mongoDB; private final Optional mongoUser; private final Optional mongoPwd; + private final boolean mongoRetryWrites; private final URL authURL; private final URL workspaceURL; private final Token workspaceAdminToken; @@ -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 mongop = Optional.fromNullable(getString(KEY_MONGO_PWD, cfg)); if (mongoUser.isPresent() ^ mongop.isPresent()) { @@ -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 */ diff --git a/src/main/java/us/kbase/groups/service/api/Root.java b/src/main/java/us/kbase/groups/service/api/Root.java index c93c2695..61918375 100644 --- a/src/main/java/us/kbase/groups/service/api/Root.java +++ b/src/main/java/us/kbase/groups/service/api/Root.java @@ -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. diff --git a/src/test/java/us/kbase/test/groups/config/GroupsConfigTest.java b/src/test/java/us/kbase/test/groups/config/GroupsConfigTest.java index 4196f3d2..e996a473 100644 --- a/src/test/java/us/kbase/test/groups/config/GroupsConfigTest.java +++ b/src/test/java/us/kbase/test/groups/config/GroupsConfigTest.java @@ -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"))); @@ -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" + @@ -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"))); @@ -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" + @@ -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())); @@ -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"))); @@ -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" + @@ -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())); diff --git a/src/test/java/us/kbase/test/groups/service/api/RootTest.java b/src/test/java/us/kbase/test/groups/service/api/RootTest.java index f5d9aa04..0a9af723 100644 --- a/src/test/java/us/kbase/test/groups/service/api/RootTest.java +++ b/src/test/java/us/kbase/test/groups/service/api/RootTest.java @@ -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";