Skip to content

Commit

Permalink
Generalized server config and added database SSL properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mullen2 committed May 9, 2019
1 parent d08c309 commit 05ec17d
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 307 deletions.
96 changes: 50 additions & 46 deletions RedCapEtlModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ public function cron()
* Runs an ETL job. Top-level method for running an ETL job that all code should call,
* so that there is one place to do REDCap authorization checks and logging.
*
* @param Configuration $etlConfig REDCap-ETL configuration to run
* @param ServerConfig $serverConfig server to run on; if empty, use embedded server
* @param string $configName the name of the REDCap-ETL configuration to run
* @param string $serverName name of server to run on
* @param boolean $isCronJon indicates whether this is being called from a cron job or not.
*
* @return string the status of the run.
Expand All @@ -211,13 +211,11 @@ public function run($configName, $serverName, $isCronJob = false, $projectId = P
#---------------------------------------------
if (empty($serverName)) {
throw new \Exception('No server specified.');
} elseif (strcasecmp($serverName, ServerConfig::EMBEDDED_SERVER_NAME) === 0) {
# Embedded server
if (!$adminConfig->getAllowEmbeddedServer()) {
throw new \Exception('The embedded server has been disabled, and cannot be used.');
}
} else {
$server = $this->getServerConfig($serverName); # Method throws exception if server not found
$serverConfig = $this->getServerConfig($serverName); # Method throws exception if server not found
if (!$serverConfig->getIsActive()) {
throw new \Exception('Server "'.$serverName.'" has been deactivated and cannot be used.');
}
}

$configUrl = $etlConfig->getProperty(Configuration::REDCAP_API_URL);
Expand Down Expand Up @@ -292,12 +290,13 @@ public function run($configName, $serverName, $isCronJob = false, $projectId = P
#------------------------------------------------------------------------
# If no server configuration was specified, run on the embedded server
#------------------------------------------------------------------------
if (empty($serverConfig)) {
$status = $this->runEmbedded($etlConfig, $isCronJob);
} else {
# Run on the specified server
$status = $serverConfig->run($etlConfig, $isCronJob);
}
#if (empty($serverConfig)) {
# $status = $this->runEmbedded($etlConfig, $isCronJob);
#} else {
# # Run on the specified server
# $status = $serverConfig->run($etlConfig, $isCronJob);
#}
$status = $serverConfig->run($etlConfig, $isCronJob);
} catch (\Exception $exception) {
$details = "ETL job failed\n".$details
.'error: '.$exception->getMessage();
Expand All @@ -312,38 +311,38 @@ public function run($configName, $serverName, $isCronJob = false, $projectId = P
/**
* Runs an ETL configuration on the embedded server.
*/
private function runEmbedded($etlConfiguration, $isCronJob = false)
{
$properties = $etlConfiguration->getPropertiesArray();

$adminConfig = $this->getAdminConfig();
$logger = new \IU\REDCapETL\Logger('REDCap-ETL');

try {
# Set the from e-mail address from the admin. configuration
$properties[Configuration::EMAIL_FROM_ADDRESS] = $adminConfig->getEmbeddedServerEmailFromAddress();
# Set the log file, and set print logging off
$properties[Configuration::LOG_FILE] = $adminConfig->getEmbeddedServerLogFile();
$properties[Configuration::PRINT_LOGGING] = false;

# Set process identifting properties
$properties[Configuration::PROJECT_ID] = $etlConfiguration->getProjectId();
$properties[Configuration::CONFIG_NAME] = $etlConfiguration->getName();
$properties[Configuration::CONFIG_OWNER] = $etlConfiguration->getUsername();
$properties[Configuration::CRON_JOB] = $isCronJob;

$redCapEtl = new \IU\REDCapETL\RedCapEtl($logger, $properties);
$redCapEtl->run();
} catch (\Exception $exception) {
$logger->logException($exception);
$logger->log('Processing failed.');
}

$status = implode("\n", $logger->getLogArray());
return $status;
}
#private function runEmbedded($etlConfiguration, $isCronJob = false)
#{
# $properties = $etlConfiguration->getPropertiesArray();
#
# $adminConfig = $this->getAdminConfig();
#
# $logger = new \IU\REDCapETL\Logger('REDCap-ETL');
#
# try {
# # Set the from e-mail address from the admin. configuration
# $properties[Configuration::EMAIL_FROM_ADDRESS] = $adminConfig->getEmbeddedServerEmailFromAddress();
#
# # Set the log file, and set print logging off
# $properties[Configuration::LOG_FILE] = $adminConfig->getEmbeddedServerLogFile();
# $properties[Configuration::PRINT_LOGGING] = false;
#
# # Set process identifting properties
# $properties[Configuration::PROJECT_ID] = $etlConfiguration->getProjectId();
# $properties[Configuration::CONFIG_NAME] = $etlConfiguration->getName();
# $properties[Configuration::CONFIG_OWNER] = $etlConfiguration->getUsername();
# $properties[Configuration::CRON_JOB] = $isCronJob;
#
# $redCapEtl = new \IU\REDCapETL\RedCapEtl($logger, $properties);
# $redCapEtl->run();
# } catch (\Exception $exception) {
# $logger->logException($exception);
# $logger->log('Processing failed.');
# }
#
# $status = implode("\n", $logger->getLogArray());
# return $status;
#}



Expand Down Expand Up @@ -732,6 +731,11 @@ public function removeServer($serverName)
# Server Config methods
#==================================================================================

public function serverConfigExists($serverName)
{
return $this->settings->serverConfigExists($serverName);
}

public function getServerConfig($serverName)
{
return $this->settings->getServerConfig($serverName);
Expand Down
92 changes: 46 additions & 46 deletions classes/AdminConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class AdminConfig implements \JsonSerializable
# Property constants
const SSL_VERIFY = 'sslVerify';

const ALLOW_EMBEDDED_SERVER = 'allowEmbeddedServer';
const EMBEDDED_SERVER_EMAIL_FROM_ADDRESS = 'embeddedServerEmailFromAddress';
const EMBEDDED_SERVER_LOG_FILE = 'embeddedServerLogFile';
#const ALLOW_EMBEDDED_SERVER = 'allowEmbeddedServer';
#const EMBEDDED_SERVER_EMAIL_FROM_ADDRESS = 'embeddedServerEmailFromAddress';
#const EMBEDDED_SERVER_LOG_FILE = 'embeddedServerLogFile';

const ALLOW_ON_DEMAND = 'allowOnDemand';
const ALLOW_CRON = 'allowCron';
Expand All @@ -21,14 +21,14 @@ class AdminConfig implements \JsonSerializable
/** @var boolean indicates if SSL verification should be done for local REDCap */
private $sslVerify;

private $allowEmbeddedServer; // Allow embedded REDCap-ETL server to be used
# private $allowEmbeddedServer; // Allow embedded REDCap-ETL server to be used

/** @var string log file (if any) on REDCap server to use for the embedded ETL server. */
private $embeddedServerLogFile;
# private $embeddedServerLogFile;

/** @var string E-mail from address to use for embedded server
* (must be set for e-mail logging to work for embedded server). */
private $embeddedServerEmailFromAddress;
#private $embeddedServerEmailFromAddress;

private $allowOnDemand; // Allow the ETL process to be run on demand

Expand Down Expand Up @@ -104,26 +104,26 @@ public function set($properties)
}

# Set allow embedded server (false will return no value)
if (array_key_exists(self::ALLOW_EMBEDDED_SERVER, $properties)) {
$this->allowEmbeddedServer = true;
} else {
$this->allowEmbeddedServer = false;
}
#if (array_key_exists(self::ALLOW_EMBEDDED_SERVER, $properties)) {
# $this->allowEmbeddedServer = true;
#} else {
# $this->allowEmbeddedServer = false;
#}

# Set the e-mail from address for the embedded server
if (array_key_exists(self::EMBEDDED_SERVER_EMAIL_FROM_ADDRESS, $properties)) {
$this->embeddedServerEmailFromAddress =
trim(strip_tags($properties[self::EMBEDDED_SERVER_EMAIL_FROM_ADDRESS]));
} else {
$this->embeddedServerEmailFromAddress = '';
}
#if (array_key_exists(self::EMBEDDED_SERVER_EMAIL_FROM_ADDRESS, $properties)) {
# $this->embeddedServerEmailFromAddress =
# trim(strip_tags($properties[self::EMBEDDED_SERVER_EMAIL_FROM_ADDRESS]));
#} else {
# $this->embeddedServerEmailFromAddress = '';
#}

# Set the log file for the embedded server
if (array_key_exists(self::EMBEDDED_SERVER_LOG_FILE, $properties)) {
$this->embeddedServerLogFile = trim(strip_tags($properties[self::EMBEDDED_SERVER_LOG_FILE]));
} else {
$this->embeddedServerLogFile = '';
}
#if (array_key_exists(self::EMBEDDED_SERVER_LOG_FILE, $properties)) {
# $this->embeddedServerLogFile = trim(strip_tags($properties[self::EMBEDDED_SERVER_LOG_FILE]));
#} else {
# $this->embeddedServerLogFile = '';
#}

# Set flag that indicates if users can run jobs on demand
if (array_key_exists(self::ALLOW_ON_DEMAND, $properties)) {
Expand Down Expand Up @@ -287,37 +287,37 @@ public function getLongTimeLabels()
return $labels;
}

public function getAllowEmbeddedServer()
{
return $this->allowEmbeddedServer;
}
#public function getAllowEmbeddedServer()
#{
# return $this->allowEmbeddedServer;
#}

public function setAllowEmbeddedServer($allowEmbeddedServer)
{
$this->allowEmbeddedServer = $allowEmbeddedServer;
}
#public function setAllowEmbeddedServer($allowEmbeddedServer)
#{
# $this->allowEmbeddedServer = $allowEmbeddedServer;
#}


public function getEmbeddedServerLogFile()
{
return $this->embeddedServerLogFile;
}
#public function getEmbeddedServerLogFile()
#{
# return $this->embeddedServerLogFile;
#}

public function setEmbeddedServerLogFile($logFile)
{
$this->embeddedServerLogFile = $logFile;
}
#public function setEmbeddedServerLogFile($logFile)
#{
# $this->embeddedServerLogFile = $logFile;
#}


public function getEmbeddedServerEmailFromAddress()
{
return $this->embeddedServerEmailFromAddress;
}
#public function getEmbeddedServerEmailFromAddress()
#{
# return $this->embeddedServerEmailFromAddress;
#}

public function setEmbeddedServerEmailFromAddress($fromEmail)
{
$this->embeddedServerEmailFromAddress = $fromEmail;
}
#public function setEmbeddedServerEmailFromAddress($fromEmail)
#{
# $this->embeddedServerEmailFromAddress = $fromEmail;
#}


public function getAllowOnDemand()
Expand Down
4 changes: 4 additions & 0 deletions classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Configuration implements \JsonSerializable

const DB_CONNECTION = 'db_connection';

const DB_SSL = 'db_ssl';
const DB_SSL_VERIFY = 'db_ssl_verify';
const CA_CERT_FILE = 'ca_cert_file';

const BATCH_SIZE = 'batch_size';

const TABLE_PREFIX = 'table_prefix';
Expand Down
Loading

0 comments on commit 05ec17d

Please sign in to comment.