Skip to content

Commit

Permalink
Merge pull request #101 from kbase/dev-add_retryWrites
Browse files Browse the repository at this point in the history
add retryWrites
  • Loading branch information
Xiangs18 authored Oct 28, 2024
2 parents a43205e + 2bb681d commit 6b371d3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
4 changes: 3 additions & 1 deletion RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ NARRATIVE METHOD STORE OVERVIEW
The Narrative Method Store provides an API to dynamically access the available
narrative method/app/type specifications and documentation.

VERSION: 0.3.12 (Released TBD)
VERSION: 0.3.12 (Released 10/28/2024)
------------------------------------

UPDATED FEATURES:
- 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 `exact_match_on` field to the dynamic dropdown options.
- Changed the build system from Make / Ant to Gradle.

Expand Down
4 changes: 4 additions & 0 deletions deploy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ method-spec-admin-users = kbaseadmin,kbaseadmin2
endpoint-host=https://ci.kbase.us
endpoint-base=/services

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

# Default tag used when tag is not specified in Narrative requests.
# It should be changed into 'release' in production deployment.
method-spec-default-tag = dev
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 @@ -35,6 +35,7 @@ method-spec-mongo-host = {{ default .Env.method_spec_mongo_host "localhost:27017
method-spec-mongo-dbname = {{ default .Env.method_spec_mongo_dbname "method_store_repo_db" }}
method-spec-mongo-user = {{ default .Env.method_spec_mongo_user "" }}
method-spec-mongo-password = {{ default .Env.method_spec_mongo_password "" }}
method-spec-mongo-retrywrites={{ default .Env.method_spec_mongo_retrywrites "false" }}
method-spec-admin-users = {{ default .Env.method_spec_admin_users "kbaseadmin,kbaseadmin2" }}
endpoint-host={{ default .Env.endpoint_host "https://ci.kbase.us" }}
endpoint-base={{ default .Env.endpoint_base "/services" }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class NarrativeMethodStoreServer extends JsonServerServlet {
public static final String CFG_PROP_MONGO_USER = "method-spec-mongo-user";
public static final String CFG_PROP_MONGO_PASSWORD = "method-spec-mongo-password";
public static final String CFG_PROP_MONGO_READONLY = "method-spec-mongo-readonly";
public static final String CFG_PROP_MONGO_RETRY_WRITES = "method-spec-mongo-retrywrites";
public static final String CFG_PROP_ADMIN_USERS = "method-spec-admin-users";
public static final String CFG_PROP_ENDPOINT_BASE = "endpoint-base";
public static final String CFG_PROP_ENDPOINT_HOST = "endpoint-host";
Expand Down Expand Up @@ -190,6 +191,10 @@ public static synchronized LocalGitDB getLocalGitDB() throws Exception {
String dbPwd = nullIfWhitespace(config().get(CFG_PROP_MONGO_PASSWORD));
System.out.println(NarrativeMethodStoreServer.class.getName() + ": " + CFG_PROP_MONGO_USER +" = " + (dbUser == null ? "<not-set>" : dbUser));
System.out.println(NarrativeMethodStoreServer.class.getName() + ": " + CFG_PROP_MONGO_PASSWORD +" = " + (dbPwd == null ? "<not-set>" : "[*****]"));

final boolean retryWrites = config().get(CFG_PROP_MONGO_RETRY_WRITES).equals("true");
System.out.println(NarrativeMethodStoreServer.class.getName() + ": " + CFG_PROP_MONGO_RETRY_WRITES +" = " + retryWrites);

String mongoReadOnlyText = config().get(CFG_PROP_MONGO_READONLY);
boolean mongoRO = mongoReadOnlyText != null && (mongoReadOnlyText.equals("1") || mongoReadOnlyText.equals("true") ||
mongoReadOnlyText.equals("y") || mongoReadOnlyText.equals("yes"));
Expand All @@ -213,7 +218,7 @@ public static synchronized LocalGitDB getLocalGitDB() throws Exception {
System.out.println(NarrativeMethodStoreServer.class.getName() + ": " + CFG_PROP_AUTH_INSECURE +" = " +
(authAllowInsecure == null ? "<not-set> ('false' will be used)" : authAllowInsecure));
localGitDB = new LocalGitDB(new URL(getGitRepo()), getGitBranch(), new File(getGitLocalDir()), getGitRefreshRate(), getCacheSize(),
new MongoDynamicRepoDB(getMongoHost(), getMongoDbname(), dbUser, dbPwd, adminUsers, mongoRO),
new MongoDynamicRepoDB(getMongoHost(), getMongoDbname(), dbUser, dbPwd, adminUsers, mongoRO, retryWrites),
new File(getTempDir()),
new ServiceUrlTemplateEvaluater(endpointHost, endpointBase), RepoTag.valueOf(defaultTag));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public MongoDynamicRepoDB(
final String dbUser,
final String dbPwd,
final List<String> globalAdminUserIds,
final boolean isReadOnly)
final boolean isReadOnly,
final boolean retryWrites)
throws NarrativeMethodStoreException {
this.isReadOnly = isReadOnly;
try {
db = getDB(host, database, dbUser, dbPwd);
db = getDB(host, database, dbUser, dbPwd, retryWrites);
if (!isReadOnly)
ensureIndeces();
globalAdmins = new HashSet<String>(globalAdminUserIds);
Expand All @@ -90,9 +91,11 @@ public MongoDynamicRepoDB(
}
}

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(user, db, pwd.toCharArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,7 @@ public void debug(String arg0) {}
ws.add("method-spec-temp-dir", dbHelper.getWorkDir());
ws.add("method-spec-mongo-host", "localhost:" + dbHelper.getMongoPort());
ws.add("method-spec-mongo-dbname", dbName);
ws.add("method-spec-mongo-retrywrites", "false");
ws.add("method-spec-admin-users", admin1 + "," + admin2);
ws.add("endpoint-host", "https://ci.kbase.us");
ws.add("endpoint-base", "/services");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ private MongoDynamicRepoDB getDB(final List<String> admins)
null,
null,
admins,
false,
false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void testRepo(boolean localFiles) throws Exception {

String host = "localhost:" + dbHelper.getMongoPort();
MongoDynamicRepoDB db = new MongoDynamicRepoDB(host, dbName, null, null,
Arrays.asList(globalAdmin), false);
Arrays.asList(globalAdmin), false, false);
Assert.assertEquals(0, db.listRepoModuleNames().size());
RepoProvider pvd = localFiles ? new FileRepoProvider(new File(localPath)) :
new GitHubRepoProvider(new URL(gitUrl), null, dbHelper.getWorkDir());
Expand Down Expand Up @@ -209,7 +209,7 @@ public void testPy() throws Exception {
String globalAdmin = "admin";
String host = "localhost:" + dbHelper.getMongoPort();
MongoDynamicRepoDB db = new MongoDynamicRepoDB(host, dbName, null, null,
Arrays.asList(globalAdmin), false);
Arrays.asList(globalAdmin), false, false);
Assert.assertEquals(0, db.listRepoModuleNames().size());
RepoProvider pvd = new FileRepoProvider(repoDir);
db.registerRepo(userId, pvd);
Expand Down

0 comments on commit 6b371d3

Please sign in to comment.