Skip to content

Commit

Permalink
Merge branch 'develop' into installable-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
azimov committed Aug 18, 2023
2 parents 6d287df + bc58d17 commit cb9c6d9
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 20 deletions.
2 changes: 1 addition & 1 deletion R/DatabaseMetaData.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ createDatabaseMetaData <- function(executionSettings, keyringName = NULL) {
connection = connection,
databaseSchema = executionSettings$cdmDatabaseSchema
)
cdmTableList <- tolower(cdmTableList)
cdmTableList <- unique(tolower(cdmTableList))

if (!length(cdmTableList[which(x = cdmTableList %in% requiredTables)]) == length(requiredTables)) {
missingCdmTables <- requiredTables[!(requiredTables %in% cdmTableList)]
Expand Down
14 changes: 13 additions & 1 deletion R/Execution.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ execute <- function(analysisSpecifications,
checkmate::assertChoice(x = keyringName, choices = keyringList$keyring, null.ok = TRUE, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

# Assert that the temp emulation schema is set if required for the dbms
# specified by the executionSettings
if (is(executionSettings, "CdmExecutionSettings")) {
connectionDetails <- retrieveConnectionDetails(
connectionDetailsReference = executionSettings$connectionDetailsReference,
keyringName = keyringName
)
DatabaseConnector::assertTempEmulationSchemaSet(
dbms = connectionDetails$dbms,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchema")
)
}
modules <- ensureAllModulesInstantiated(analysisSpecifications)

if (is.null(executionScriptFolder)) {
Expand Down Expand Up @@ -170,7 +182,7 @@ generateTargetsScript <- function(analysisSpecifications, executionSettings, dep

dependenciesFileName <- gsub("\\\\", "/", file.path(executionScriptFolder, "dependencies.rds"))
saveRDS(dependencies, dependenciesFileName)

execResultsUpload <- all(c(is(executionSettings, "CdmExecutionSettings"),
!is.null(executionSettings$resultsConnectionDetailsReference),
!is.null(executionSettings$resultsDatabaseSchema)))
Expand Down
15 changes: 14 additions & 1 deletion R/ModuleEnv.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ withModuleRenv <- function(code,
libPath <- file.path(find.package("Strategus"), "../")
script <- c(sprintf("library(Strategus, lib.loc = '%s')", libPath),
script)
# Adding Strategus dependencies to the script
libPath <- file.path(find.package("CohortGenerator"), "../")
script <- c(sprintf("library(CohortGenerator, lib.loc = '%s')", libPath),
script)
libPath <- file.path(find.package("DatabaseConnector"), "../")
script <- c(sprintf("library(DatabaseConnector, lib.loc = '%s')", libPath),
script)
libPath <- file.path(find.package("keyring"), "../")
script <- c(sprintf("library(keyring, lib.loc = '%s')", libPath),
script)
libPath <- file.path(find.package("openssl"), "../")
script <- c(sprintf("library(openssl, lib.loc = '%s')", libPath),
script)
}

# Write file and execute script inside an renv
Expand All @@ -83,4 +96,4 @@ withModuleRenv <- function(code,
project = moduleFolder
)
return(invisible(NULL))
}
}
18 changes: 9 additions & 9 deletions R/ModuleInstantiation.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ instantiateModule <- function(module, version, remoteRepo, remoteUsername, modul
stop(message)
}

script <- "
renv::restore(prompt = FALSE)
if (!require('ParallelLogger', quietly = TRUE)) {
install.packages('ParallelLogger')
}
if (!require('keyring', quietly = TRUE)) {
install.packages('keyring')
}
"
script <- paste(
c(
"renv::install(c('ParallelLogger', 'keyring'), prompt = FALSE)",
sprintf("ParallelLogger::addDefaultFileLogger(file.path('%s', 'moduleInitLog.txt'))", moduleFolder),
sprintf("ParallelLogger::addDefaultErrorReportLogger(fileName = file.path('%s', 'moduleInitErrorReport.txt'))", moduleFolder),
"renv::restore(prompt = FALSE)"
),
collapse = "\n"
)
tempScriptFile <- tempfile(fileext = ".R")
fileConn <- file(tempScriptFile)
writeLines(script, fileConn)
Expand Down
15 changes: 9 additions & 6 deletions R/RunModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,24 @@ runModule <- function(analysisSpecifications, keyringSettings, moduleIndex, exec
ParallelLogger::addDefaultErrorReportLogger(file.path(jobContext$moduleExecutionSettings$resultsSubFolder, 'errorReport.R'))

options(andromedaTempFolder = file.path(jobContext$moduleExecutionSettings$workFolder, 'andromedaTemp'))
options(tempEmulationSchema = jobContext$moduleExecutionSettings$tempEmulationSchema)

if (Sys.getenv('FORCE_RENV_USE', '') == 'TRUE') {
renv::use(lockfile = 'renv.lock')
}

# NOTE injected variable isResultsExecution - will look strange outside of Strategus definition
if (isCdmExecution) {
connectionDetails <- keyring::key_get(jobContext$moduleExecutionSettings$connectionDetailsReference, keyring = keyringName)
connectionDetails <- ParallelLogger::convertJsonToSettings(connectionDetails)
connectionDetails <- do.call(DatabaseConnector::createConnectionDetails, connectionDetails)
connectionDetails <- Strategus::retrieveConnectionDetails(
connectionDetailsReference = jobContext$moduleExecutionSettings$connectionDetailsReference,
keyringName = keyringName
)
jobContext$moduleExecutionSettings$connectionDetails <- connectionDetails
} else {
resultsConnectionDetails <- keyring::key_get(jobContext$moduleExecutionSettings$resultsConnectionDetailsReference, keyring = keyringName)
resultsConnectionDetails <- ParallelLogger::convertJsonToSettings(resultsConnectionDetails)
resultsConnectionDetails <- do.call(DatabaseConnector::createConnectionDetails, resultsConnectionDetails)
resultsConnectionDetails <- Strategus::retrieveConnectionDetails(
connectionDetailsReference = jobContext$moduleExecutionSettings$resultsConnectionDetailsReference,
keyringName = keyringName
)
jobContext$moduleExecutionSettings$resultsConnectionDetails <- resultsConnectionDetails
}
if (keyringLocked) {
Expand Down
13 changes: 12 additions & 1 deletion R/Settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ createCdmExecutionSettings <- function(connectionDetailsReference,
workDatabaseSchema,
cdmDatabaseSchema,
cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = "cohort"),
tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"),
workFolder,
resultsFolder,
minCellCount = 5,
Expand All @@ -125,6 +126,7 @@ createCdmExecutionSettings <- function(connectionDetailsReference,
workDatabaseSchema = workDatabaseSchema,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortTableNames = cohortTableNames,
tempEmulationSchema = tempEmulationSchema,
workFolder = workFolder,
resultsFolder = resultsFolder,
minCellCount = minCellCount,
Expand Down Expand Up @@ -214,7 +216,7 @@ storeConnectionDetails <- function(connectionDetails, connectionDetailsReference
if (is.function(connectionDetails[[i]])) {
detail <- connectionDetails[[i]]()
if (is.null(detail)) {
connectionDetails[[i]] <- ""
connectionDetails[[i]] <- list(NULL) # Fixes Issue #74
} else {
connectionDetails[[i]] <- connectionDetails[[i]]()
}
Expand Down Expand Up @@ -255,6 +257,15 @@ retrieveConnectionDetails <- function(connectionDetailsReference, keyringName =

connectionDetails <- keyring::key_get(connectionDetailsReference, keyring = keyringName)
connectionDetails <- ParallelLogger::convertJsonToSettings(connectionDetails)

# Ensure that NA values are converted to NULL prior to calling
# DatabaseConnector
for (i in 1:length(connectionDetails)) {
if (isTRUE(is.na(connectionDetails[[i]]))) {
connectionDetails[[i]] <- list(NULL) # Fixes Issue #74
}
}

connectionDetails <- do.call(DatabaseConnector::createConnectionDetails, connectionDetails)

if (keyringLocked) {
Expand Down
2 changes: 1 addition & 1 deletion inst/testdata/analysisSpecification.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"moduleSpecifications": [
{
"module": "CohortGeneratorModule",
"version": "0.1.0",
"version": "0.1.1-1",
"remoteRepo": "github.com",
"remoteUsername": "ohdsi",
"settings": {
Expand Down
1 change: 1 addition & 0 deletions man/Strategus-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/createCdmExecutionSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions man/withModuleRenv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb9c6d9

Please sign in to comment.