From cf52fc06d32ae5b66e8e2392385b982bba200869 Mon Sep 17 00:00:00 2001 From: Michael Grauer Date: Fri, 16 Sep 2011 18:04:44 -0400 Subject: [PATCH] BUG: Refs #212. Rewrite of KWBatchmakeComponent.php, and reworking of tests. Rewrote KWBatchmakeComponent.php to be more sensible, rewrote tests and other code that depending on this. Also added a README to the batchmake module for testing, and a switch in CMakeLists.txt for the batchmake module to have batchmake module testing be off by default, since a certain amount of config is required to have the batchmake tests pass. --- .../controllers/ConfigController.php | 42 +- .../components/KWBatchmakeComponent.php | 357 ++++++------ modules/batchmake/tests/CMakeLists.txt | 8 +- modules/batchmake/tests/README | 31 + .../controllers/ConfigControllerTest.php | 547 +----------------- .../components/KWBatchmakeComponentTest.php | 205 ++----- 6 files changed, 291 insertions(+), 899 deletions(-) create mode 100644 modules/batchmake/tests/README diff --git a/modules/batchmake/controllers/ConfigController.php b/modules/batchmake/controllers/ConfigController.php index 1f5f413a6..7b8ee56bf 100644 --- a/modules/batchmake/controllers/ConfigController.php +++ b/modules/batchmake/controllers/ConfigController.php @@ -13,33 +13,14 @@ /** * Batchmake_ConfigController * @todo TODO list for ConfigController and batchmake module - * - add phpdocumenter style comments - * - rework Notification - * - add tests - * - clean UI layout - * - repititions/redundancy in controller - * - repititions/redundancy in index.pthml - * - translations/centralized string resources - * - centralize constants - * - ? how to sync PHP, javascript, and css constants? info, error, warning among them - * - ? how to internationalize javascript strings? * - better way of loading internationalization component in component and form - * - For now, have a KWBatchmakeComponent, which includes kwutils stuff and kwbatchmake - * - separate kw utils, where does this go? - * - separate kwbatchmake, where does this go? - * - clean component, internationalize strings * - look into zend internationalization/translate - * - look into cmake infinite loop * - for web api, there is a json wrapper , ajax_web_api.js in midas2 * - an element: ajax_web_api.thtml look in assetstore for usage * - should need to put the "writing" of the auth token info in some common controller code * - then include the element in any view * - then the json .js wrapper will automaticially negotiate - * - ? how to use web api in a module? - * - want to namaespace constants MIDAS_BATCHMAKE - * - for imports have a static var for one time class loading - * - change ajax callst o be through web api - * - kwutils, try to use zend framework + * - change ajax callst o be through web api, and standard ajax */ class Batchmake_ConfigController extends Batchmake_AppController { @@ -72,18 +53,19 @@ protected function archiveOldModuleLocal() /** - * @method indexAction() + * @method indexAction(), will test the configuration that the user has set + * and return validation info for the passed in properties. */ - function indexAction() + public function indexAction() { - $applicationConfig = $this->ModuleComponent->KWBatchmake->loadApplicationConfig(); + $applicationConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties(); $configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements(); $configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements); $formArray = $this->getFormAsArray($configForm); foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement) { - $formArray[$configProperty]->setValue($applicationConfig[$this->moduleName.'.'.$configProperty]); + $formArray[$configProperty]->setValue($applicationConfig[$configProperty]); } $this->view->configForm = $formArray; @@ -129,7 +111,7 @@ public function testconfigAction() $configPropertiesParamVals = array(); - $configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->GetConfigPropertiesRequirements(); + $configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements(); foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement) { $configPropertiesParamVals[$configProperty] = $this->_getParam($configProperty); @@ -138,17 +120,7 @@ public function testconfigAction() $config_status = $this->ModuleComponent->KWBatchmake->testconfig($configPropertiesParamVals); $jsonout = JsonComponent::encode($config_status); echo $jsonout; -// echo JsonComponent::encode($config_status); }//end testconfigAction - - - - - - - - - }//end class diff --git a/modules/batchmake/controllers/components/KWBatchmakeComponent.php b/modules/batchmake/controllers/components/KWBatchmakeComponent.php index dd75832b3..9139359e6 100644 --- a/modules/batchmake/controllers/components/KWBatchmakeComponent.php +++ b/modules/batchmake/controllers/components/KWBatchmakeComponent.php @@ -18,79 +18,118 @@ */ class Batchmake_KWBatchmakeComponent extends AppComponent { - //@TODO want to set config properties as instance variables rather than passing them around - //probably make some static factory methods that take in a config set - protected $configPropertiesRequirements = array(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_CHMODABLE_RW, + protected static $configPropertiesRequirements = array(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_CHMODABLE_RW, MIDAS_BATCHMAKE_BIN_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_READABLE, MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_READABLE, MIDAS_BATCHMAKE_APP_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_READABLE, MIDAS_BATCHMAKE_DATA_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_CHMODABLE_RW, MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_READABLE); - protected $applicationsPaths = array(MIDAS_BATCHMAKE_CONDOR_STATUS => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, - MIDAS_BATCHMAKE_CONDOR_QUEUE => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, - MIDAS_BATCHMAKE_CONDOR_SUBMIT => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, - MIDAS_BATCHMAKE_CONDOR_SUBMIT_DAG => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, - MIDAS_BATCHMAKE_EXE => MIDAS_BATCHMAKE_BIN_DIR_PROPERTY); - - protected $alternateConfig = false; - - /** will allow an alterate config bundle to be passed in. */ - public function setAlternateConfig($alternate) - { - $this->alternateConfig = $alternate; - } - - /** - * @method getConfigPropertiesRequirements() - * accessor method for set of config properties and their requirements. + * accessor functin to return the names of the config propeties, and + * their filesystem requirements; */ public function getConfigPropertiesRequirements() { - return $this->configPropertiesRequirements; + return self::$configPropertiesRequirements; } + + protected static $applicationsPaths = array(MIDAS_BATCHMAKE_CONDOR_STATUS => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, + MIDAS_BATCHMAKE_CONDOR_QUEUE => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, + MIDAS_BATCHMAKE_CONDOR_SUBMIT => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, + MIDAS_BATCHMAKE_CONDOR_SUBMIT_DAG => MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY, + MIDAS_BATCHMAKE_EXE => MIDAS_BATCHMAKE_BIN_DIR_PROPERTY); + + + + // component configuration settings + protected $componentConfig; + // individual config properties, for convenience + protected $configScriptDir; + protected $configAppDir; + protected $configTmpDir; + protected $configBinDir; + protected $configDataDir; + protected $configCondorBinDir; + /** - * @method getApplicationsPaths() - * accessor method for set of application paths needed by batchmake module. + * Constructor, loads ini from standard config location, unless a + * supplied alternateConfig. + * @param string $alternateConfig path to alternative config ini file */ - public function getApplicationsPaths() + public function __construct($alternateConfig = null) { - return $this->applicationsPaths; - } - - + $this->loadConfigProperties($alternateConfig); + } // end __construct($alternateConfig) + + /** - * @method loadApplicationConfig() - * written in the hope of being reusable + * helper function to load the correct config file + * @param string $alternateConfig path to alternative config ini file + * @return config array with config properties */ - function loadApplicationConfig() + protected function loadConfig($alternateConfig = null) { - if($this->alternateConfig) + if($alternateConfig) { - $applicationConfig = parse_ini_file($this->alternateConfig, false); + $config = parse_ini_file($alternateConfig, false); } elseif(file_exists(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG)) { - $applicationConfig = parse_ini_file(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, false); + $config = parse_ini_file(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, false); } else { - $applicationConfig = parse_ini_file(MIDAS_BATCHMAKE_MODULE_CONFIG); + $config = parse_ini_file(MIDAS_BATCHMAKE_MODULE_CONFIG); } - return $applicationConfig; + return $config; } - - - + /** + * @method loadConfigProperties + * will load the configuration property values for this module, and filter + * out only those properties that are in the 'batchmake.' config namespace, + * removing the 'batchmake.' from the key name. + * @param string $alternateConfig a path to an alternate config ini file + * @return array of batchmake module specific config properties + */ + public function loadConfigProperties($alternateConfig = null) + { + $configPropertiesParamVals = array(); + $rawConfig = $this->loadConfig($alternateConfig); + + $modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.'; + foreach($rawConfig as $configProperty => $configPropertyVal) + { + $ind = strpos($configProperty, $modulePropertyNamespace); + if($ind !== false && $ind == 0) + { + $reducedKey = substr($configProperty, strpos($configProperty, '.') + 1); + $configPropertiesParamVals[$reducedKey] = $configPropertyVal; + } + } + + $this->componentConfig = $configPropertiesParamVals; + $this->configScriptDir = $this->componentConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; + $this->configAppDir = $this->componentConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; + $this->configTmpDir = $this->componentConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY]; + $this->configBinDir = $this->componentConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; + $this->configDataDir = $this->componentConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY]; + $this->configCondorBinDir = $this->componentConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY]; + return $this->componentConfig; + } + + // above here is config setup + // below here is config testing + /** * @method checkFileFlag() + * @TODO from KWUtils, may need to be moved, but first tested * checks whether the file at the passed in path has the passed in options. */ - public function checkFileFlag($file, $options = 0x0) + protected function checkFileFlag($file, $options = 0x0) { $exist = file_exists($file); Zend_Loader::loadClass("InternationalizationComponent", BASE_PATH.'/core/controllers/components'); @@ -125,20 +164,15 @@ public function checkFileFlag($file, $options = 0x0) return array($ret, $status); } - - - - - /** * @method isChmodable * Check if current PHP process has permission to change the mode * of $fileOrDirectory. - * @TODO from KWUtils, may need to be moved. + * @TODO from KWUtils, may need to be moved, but first tested * Note: If return true, the mode of the file will be MIDAS_BATCHMAKE_DEFAULT_MKDIR_MODE * On windows, return always True */ - function isChmodable($fileOrDirectory) + protected function isChmodable($fileOrDirectory) { if(KWUtils::isWindows()) { @@ -154,9 +188,7 @@ function isChmodable($fileOrDirectory) // Get permissions of the file // TODO On CIFS filesytem, even if the function GetFilePermissions call clearstatcache(), the value returned can be wrong - //self::Debug("File permissions: [file: $fileOrDirectory, mode: ".decoct($current_perms)."]"); - //$current_perms = self::GetFilePermissions( $fileOrDirectory ); - $current_perms = KWUtils::DEFAULT_MKDIR_MODE;//MIDAS_BATCHMAKE_DEFAULT_MKDIR_MODE; + $current_perms = KWUtils::DEFAULT_MKDIR_MODE; if($current_perms === false) { return false; @@ -174,56 +206,30 @@ function isChmodable($fileOrDirectory) return $return; } - /** - * @method getApplicationConfigProperties - * will load the configuration property values for this module, and filter - * out only those properties that are in the 'batchmake.' config namespace, - * removing the 'batchmake.' from the key name. - * @return array of batchmake module specific config properties - */ - public function getApplicationConfigProperties() - { - $configPropertiesParamVals = array(); - $applicationConfig = $this->loadApplicationConfig(); - - $modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.'; - foreach($applicationConfig as $configProperty => $configPropertyVal) - { - $ind = strpos($configProperty, $modulePropertyNamespace); - if($ind !== false && $ind == 0) - { - $reducedKey = substr($configProperty, strpos($configProperty, '.') + 1); - $configPropertiesParamVals[$reducedKey] = $configPropertyVal; - } - } - - return $configPropertiesParamVals; - } - - - /** * @method testconfig() - * @param $configPropertiesParamVals a set of parameter values to test - * performs validation on $configPropertiesParamVals, or if that is empty, - * on the current saved configuration. + * @param array $alternateConfigValues an alternative set of values to test, + * usually testing a possible configuration set to be saved. + * performs validation on current config setup. */ - public function testconfig($configPropertiesParamVals = NULL) + public function testconfig($alternateConfigValues = null) { //default to correct config $total_config_correct = 1; $configStatus = array(); - - // if the passed in config is empty, load it from the config file - if(empty($configPropertiesParamVals)) + + if($alternateConfigValues) { - $configPropertiesParamVals = $this->getApplicationConfigProperties(); + $configToTest = $alternateConfigValues; } - - $configPropertiesRequirements = $this->getConfigPropertiesRequirements(); - foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement) + else + { + $configToTest = $this->componentConfig; + } + + foreach(self::$configPropertiesRequirements as $configProperty => $configPropertyRequirement) { - $configPropertyVal = $configPropertiesParamVals[$configProperty]; + $configPropertyVal = $configToTest[$configProperty]; if($configPropertyVal) { // if the property exists, check its configuration @@ -245,10 +251,9 @@ public function testconfig($configPropertiesParamVals = NULL) // for now assuming will run via condor, so require all of the condor setup - $appsPaths = $this->getApplicationsPaths(); - foreach($appsPaths as $app => $pathProperty) + foreach(self::$applicationsPaths as $app => $pathProperty) { - $appPath = $configPropertiesParamVals[$pathProperty] ."/" . KWUtils::formatAppName($app); + $appPath = $configToTest[$pathProperty] ."/" . KWUtils::formatAppName($app); list($result, $status) = $this->checkFileFlag($appPath, MIDAS_BATCHMAKE_CHECK_IF_EXECUTABLE); Zend_Loader::loadClass("InternationalizationComponent", BASE_PATH.'/core/controllers/components'); @@ -295,20 +300,25 @@ public function testconfig($configPropertiesParamVals = NULL) return array($total_config_correct, $configStatus); - } - + } + /** * @method isConfigCorrect * helper method to return true if the config is correct, false otherwise + * @param array $alternateConfigValues an alternative set of values to test, + * usually testing a possible configuration set to be saved. * @return true if config correct, false otherwise */ - public function isConfigCorrect() + public function isConfigCorrect($alternateConfigValues = null) { - $applicationConfig = $this->testconfig(); + $applicationConfig = $this->testconfig($alternateConfigValues); return $applicationConfig[0] == 1; } - + // above here is config testing + // below here is execution functionality + + /** * @method getBatchmakeScripts * will create a list of Batchmake scripts that exist in the MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY @@ -317,9 +327,7 @@ public function isConfigCorrect() */ public function getBatchmakeScripts() { - $config = $this->getApplicationConfigProperties(); - $scriptDir = $config[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $globPattern = $scriptDir . '/*' . MIDAS_BATCHMAKE_BATCHMAKE_EXTENSION; + $globPattern = $this->configScriptDir . '/*' . MIDAS_BATCHMAKE_BATCHMAKE_EXTENSION; $scripts = glob($globPattern); $scriptNames = array(); foreach($scripts as $scriptPath) @@ -331,26 +339,40 @@ public function getBatchmakeScripts() } - - + /** + * will createa new batchmake task, along with a work directory + * @param type $userDao + * @return string the path to the workDir for this batchmake task + */ + public function createTask($userDao) + { + $modelLoad = new MIDAS_ModelLoader(); + $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); + $taskDao = $batchmakeTaskModel->createTask($userDao); + $userId = $taskDao->getUserId(); + $taskId = $taskDao->getKey(); + $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); + // create a workDir based on the task and user + $workDir = KWUtils::createSubDirectories($this->configTmpDir . "/", $subdirs); + return $workDir; + } /** - * @method findAndSymLinkDependentBatchmakeScripts - * will look in the tmpDir for a batchmake script and symlink it to the - * tmpDir, will then find any batchmake scripts that need to be included - * other than a config script, and symlink them in from the scriptdir, + * @method preparePipelineScripts + * will look in the scriptDir for a batchmake script and symlink it to the + * workDir, will then find any batchmake scripts that need to be included + * other than a config script, and symlink them in from the scriptDir, * and for each of these additional scripts, will perform the same * operation (symlinking included batchmake scripts), * will throw a Zend_Exception if any symlink fails or if a target file * doesn't exist. - * @param $scriptDir the batchmake script dir - * @param $tmpDir the temporary work dir + * @param $workDir the temporary work dir * @param $scriptName the original batchmake script * @param $processed a list of those scripts already processed * @return the array of scripts processed */ - public function findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName, $processed = array(), &$currentPath = array()) + public function preparePipelineScripts($workDir, $scriptName, $processed = array(), &$currentPath = array()) { // check for cycles if(array_search($scriptName, $currentPath) !== false) @@ -363,8 +385,8 @@ public function findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scrip if(!array_key_exists($scriptName, $processed)) { // symlink the top level scrip - $scriptLink = $tmpDir . '/' . $scriptName; - $scriptTarget = $scriptDir . '/' . $scriptName; + $scriptLink = $workDir . '/' . $scriptName; + $scriptTarget = $this->configScriptDir . '/' . $scriptName; if(!file_exists($scriptTarget) || !symlink($scriptTarget, $scriptLink)) { throw new Zend_Exception($scriptTarget . ' could not be sym-linked to ' . $scriptLink); @@ -374,7 +396,7 @@ public function findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scrip } // read through the script looking for includes - $contents = file_get_contents($scriptDir . '/' . $scriptName); + $contents = file_get_contents($this->configScriptDir . '/' . $scriptName); // looking for lines like // Include(PixelCounter.config.bms) // /i means case insensitive search @@ -396,7 +418,7 @@ public function findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scrip // essentially performing depth first search in a graph // there could be a problem with a cycle in the include graph, // so pass along the currentPath - $processed = $this->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $includeName, $processed, $currentPath); + $processed = $this->preparePipelineScripts($workDir, $includeName, $processed, $currentPath); } } } @@ -405,53 +427,27 @@ public function findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scrip // return the processed list return $processed; } - - - - - - - - - - - - - - - - - - - - - - - - - /** - * @method findAndSymLinkDependentBmms - * will look in the $tmpDir for all batchmake scripts that are passed + * @method preparePipelineBmms + * will look in the $workDir for all batchmake scripts that are passed * in the array $bmScripts, for each of these, it will find all of the apps * included in them using the SetApp Batchmake command, and sym link the * corresponding bmm file to the tmpDir, these bmm files are expected to be * in the $binDir, will throw a Zend_Exception if any symlink fails or if a * bmm file doesn't exist, or if one of the batchmake scripts doesn't exist. - * @param $binDir the bin dir with the bmm files - * @param $tmpDir the temporary work dir + * @param $workDir the temporary work dir * @param $bmScripts the array of Batchmake scripts in the $tmpDir to process * @return an array of [ bmmfile => bmScript where bmmfile first found ] */ - public function findAndSymLinkDependentBmms($binDir, $tmpDir, $bmScripts) + public function preparePipelineBmms($workDir, $bmScripts) { // initialize the list of bmms that have been processed $processed = array(); foreach($bmScripts as $bmScript) { - $scriptPath = $tmpDir . '/' . $bmScript; + $scriptPath = $workDir . '/' . $bmScript; if(!file_exists($scriptPath)) { throw new Zend_Exception($scriptPath . ' could not be found'); @@ -473,8 +469,8 @@ public function findAndSymLinkDependentBmms($binDir, $tmpDir, $bmScripts) { if(!array_key_exists($appName, $processed)) { - $bmmTarget = $binDir . '/' . $appName . '.bmm'; - $bmmLink = $tmpDir . '/' . $appName . '.bmm'; + $bmmTarget = $this->configBinDir . '/' . $appName . '.bmm'; + $bmmLink = $workDir . '/' . $appName . '.bmm'; if(!file_exists($bmmTarget) || !symlink($bmmTarget, $bmmLink)) { throw new Zend_Exception($bmmTarget . ' could not be sym-linked to ' . $bmmLink); @@ -488,50 +484,29 @@ public function findAndSymLinkDependentBmms($binDir, $tmpDir, $bmScripts) return $processed; } - - - - - - - - - - - - - - - - - - - /** * @method compileBatchMakeScript will check that the passed in $batchmakescript - * in the passed in $tmpDir will compile without errors. - * @param string $appDir directory where binary applications are located - * @param string $binDir directory where the BatchMake binary is located - * @param string $tmpDir directory where the work for SSP should be done + * in the passed in $workDir will compile without errors. + * @param string $workDir directory where the work for SSP should be done * @param string $bmScript name of the script, should be in $tmpDir * @return type */ - public function compileBatchMakeScript($appDir, $binDir, $tmpDir, $bmScript) + public function compileBatchMakeScript($workDir, $bmScript) { // Prepare command $params = array( - '-ap', $appDir, - '-p', $tmpDir, - '-c', $tmpDir.$bmScript, + '-ap', $this->configAppDir, + '-p', $workDir, + '-c', $workDir.$bmScript, ); - $cmd = KWUtils::prepareExecCommand($binDir . '/'. MIDAS_BATCHMAKE_EXE, $params); + $cmd = KWUtils::prepareExecCommand($this->configBinDir . '/'. MIDAS_BATCHMAKE_EXE, $params); if($cmd === false) { return false; } // Run command - KWUtils::exec($cmd, $output, $tmpDir, $returnVal); + KWUtils::exec($cmd, $output, $workDir, $returnVal); if($returnVal !== 0) { @@ -563,27 +538,25 @@ public function compileBatchMakeScript($appDir, $binDir, $tmpDir, $bmScript) /** * @method generateCondorDag will create condor scripts and a condor dag - * from the batchmake script $bmScript, in the directory $tmpDir. - * @param type $appDir - * @param type $tmpDir - * @param type $binDir + * from the batchmake script $bmScript, in the directory $workDir. + * @param type $workDir * @param type $bmScript */ - public function generateCondorDag($appDir, $tmpDir, $binDir, $bmScript) + public function generateCondorDag($workDir, $bmScript) { $dagName = $bmScript.'.dagjob'; // Prepare command $params = array( - '-ap', $appDir, - '-p', $tmpDir, - '--condor', $tmpDir.$bmScript, $tmpDir.$dagName, + '-ap', $this->configAppDir, + '-p', $workDir, + '--condor', $workDir.$bmScript, $workDir.$dagName, ); - $cmd = KWUtils::prepareExecCommand($binDir . '/'. MIDAS_BATCHMAKE_EXE, $params); + $cmd = KWUtils::prepareExecCommand($this->configBinDir . '/'. MIDAS_BATCHMAKE_EXE, $params); // Run command - KWUtils::exec($cmd, $output, $tmpDir, $returnVal); + KWUtils::exec($cmd, $output, $workDir, $returnVal); if($returnVal !== 0) { @@ -593,20 +566,20 @@ public function generateCondorDag($appDir, $tmpDir, $binDir, $bmScript) } /** - * @method condorSubmitDag will - * @param type $condorBinDir - * @param type $tmpDir + * @method condorSubmitDag will submit the passed in $dagScript to condor, + * executing in the passed in $workDir + * @param type $workDir * @param type $dagScript */ - public function condorSubmitDag($condorBinDir, $tmpDir, $dagScript) + public function condorSubmitDag($workDir, $dagScript) { // Prepare command $params = array($dagScript); - $cmd = KWUtils::prepareExecCommand($condorBinDir . '/'. MIDAS_BATCHMAKE_CONDOR_SUBMIT_DAG, $params); + $cmd = KWUtils::prepareExecCommand($this->configCondorBinDir . '/'. MIDAS_BATCHMAKE_CONDOR_SUBMIT_DAG, $params); // Run command - KWUtils::exec($cmd, $output, $tmpDir, $returnVal); + KWUtils::exec($cmd, $output, $workDir, $returnVal); if($returnVal !== 0) { diff --git a/modules/batchmake/tests/CMakeLists.txt b/modules/batchmake/tests/CMakeLists.txt index c8a32196f..7fa081ce4 100644 --- a/modules/batchmake/tests/CMakeLists.txt +++ b/modules/batchmake/tests/CMakeLists.txt @@ -1,4 +1,6 @@ -add_subdirectory( controllers ) - -add_midas_style_test( StyleTestsBatchmakeControllers ${CMAKE_SOURCE_DIR}/modules/batchmake/tests/controllers ) +option( MIDAS_RUN_BATCHMAKE_TESTS "Should MIDAS run BatchMake tests? Specific configuration is required, see modules/batchmake/tests/README." ) +if(MIDAS_RUN_BATCHMAKE_TESTS) + add_subdirectory( controllers ) + add_midas_style_test( StyleTestsBatchmakeControllers ${CMAKE_SOURCE_DIR}/modules/batchmake/tests/controllers ) +endif() diff --git a/modules/batchmake/tests/README b/modules/batchmake/tests/README new file mode 100644 index 000000000..c5be884c8 --- /dev/null +++ b/modules/batchmake/tests/README @@ -0,0 +1,31 @@ +To run the Batchmake module tests, you must setup the correct config paths in + + +$MIDAS_ROOT/modules/batchmake/tests/configs/module.local.ini + + + +$MIDAS_ROOT points to the location of your top level Midas directory. + + + +point the config values to the following locations: + +batchmake.tmp_dir=$MIDAS_ROOT/modules/batchmake/tests/testfiles/midas3batchmake/tmp +batchmake.bin_dir=$MIDAS_ROOT/modules/batchmake/tests/testfiles/midas3batchmake/bin +batchmake.script_dir=$MIDAS_ROOT/modules/batchmake/tests/testfiles/midas3batchmake/script +batchmake.app_dir=$MIDAS_ROOT/modules/batchmake/tests/testfiles/midas3batchmake/bin +batchmake.data_dir=$MIDAS_ROOT/modules/batchmake/tests/testfiles/midas3batchmake/data +batchmake.condor_bin_dir= Location of your condor bin directory + + + +Chown the directories recursively from + +$MIDAS_ROOT/modules/batchmake/tests/testfilesconfigs/midas3batchmake + +to be owned by whichever user will run the tests. + + + +You must copy or symlink a BatchMake executable to the batchmake.bin_dir . \ No newline at end of file diff --git a/modules/batchmake/tests/controllers/ConfigControllerTest.php b/modules/batchmake/tests/controllers/ConfigControllerTest.php index 271325b9f..d30d97cd1 100644 --- a/modules/batchmake/tests/controllers/ConfigControllerTest.php +++ b/modules/batchmake/tests/controllers/ConfigControllerTest.php @@ -10,14 +10,14 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -// need to include the module constant for this test -require_once str_replace('tests', 'constant', str_replace('controllers', 'module.php', dirname(__FILE__))); +// need to include the module constant for this test +require_once BASE_PATH.'/modules/batchmake/constant/module.php'; + /** config controller tests*/ class ConfigControllerTest extends ControllerTestCase { protected $kwBatchmakeComponent; - protected $applicationConfig; /** set up tests*/ @@ -28,14 +28,8 @@ public function setUp() //$this->_daos = array('User');// //$this->_moduleModels = array('Task');// $this->enabledModules = array('batchmake'); - - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $this->kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $this->kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $this->applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - - + $this->kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); parent::setUp(); } @@ -47,523 +41,32 @@ public function testIndexAction() $this->dispatchUrI("/batchmake/config/index"); $body = $this->getBody(); - $this->assertAction("index"); $this->assertModule("batchmake"); + $this->assertController('config'); + $this->assertAction("index"); if(strpos($body, "Batchmake Configuration") === false) { $this->fail('Unable to find body element'); } - /* - // - $usersFile = $this->loadData('User', 'default'); - var_dump($usersFile); - $userDao = $this->User->load($usersFile[0]->getKey()); - echo $userDao->getKey(); - echo 'admin='.$userDao->getAdmin(); - $userDao->setAdmin(1); - echo 'admin='.$userDao->getAdmin(); - $this->User->save($userDao); - $userDao = $this->User->load($usersFile[0]->getKey()); - echo 'admin='.$userDao->getAdmin(); - - - - - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $taskDao = $batchmakeTaskModel->createTask($userDao); - //$preKey = $userApiModel->getByAppAndUser('Default', $userDao)->getApikey(); - //$this->assertEquals(strlen($preKey), 32); - - - // create a task - //$taskDao = $this->Batchmake_Task->createTask($userDao); - // check for app, how? - // - // - // create a dir - // copy bms and bmm to dir - // - // - - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - echo "task:".$taskId." for user:".$userId; - */ - } - - // TEST KWBATCHMAKE COMPONENTS - // want a better way of doing this, but here is a start - - /** - * tests config setup, relies on an alternate testing config to be defined, - * these properties should all point to the batchmake module testfiles dirs. - */ - // should put the kwBatchmakeComponent as an instance variable? - // hopefully that would remove all of the redundant calls to setting it up - public function testIsConfigCorrect() - { - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $this->assertTrue($kwBatchmakeComponent->isConfigCorrect()); - } - - /** - * tests that all the bmScripts that have been entered for testing are found - */ - public function testGetBatchmakeScripts() - { - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $foundTestScripts = $kwBatchmakeComponent->getBatchmakeScripts(); - $expectedTestScripts = array("Myscript2.bms","PixelCounter.bms","anotherscript.bms", - "anotherscriptwitherrors.bms","bmmswitherrors.bms","myscript.bms","noscripts.bms"); - foreach($expectedTestScripts as $script) - { - $this->assertContains($script, $foundTestScripts); - } - } - - /** - * @TODO some model testing, and better ways of loading the models - * test creating a model and creating the right subdirs - */ - - public function testCreateSubDirectories() - { - // test creating directories, in the same setup as would be used for - // batchmake processing. so create a task, then create a nested - // set of directories based on the taskId - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $applicationConfig = $kwBatchmakeComponent->getApplicationConfigProperties(); - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - $tmpDir = $kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - // now check that all the subdirs have been created - $pathToCheck = $applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . '/'; - $this->assertFileExists($pathToCheck); - foreach($subdirs as $subdir) - { - $pathToCheck = $pathToCheck . '/' . $subdir; - $this->assertFileExists($pathToCheck); - $this->assertTrue(is_dir($pathToCheck)); - } - } - - - protected function clearDirFiles($dirToClear) - { - foreach(scandir($dirToClear) as $filename) - { - if($filename && $filename != '.' && $filename != '..') - { - unlink($dirToClear.'/'.$filename); - } - } - } - - protected function fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet) - { - // clear the directory of any existing files - $this->clearDirFiles($tmpDir); - - // try symlinking all the batchmake files starting with $scriptName - $bmScriptsProcessed = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir,$tmpDir,$scriptName); - - // check that the correct batchmake scripts are there, and only those - // easiest just to add '.' and '..' to expected list - $expectedSet[] = '..'; - $expectedSet[] = '.'; - sort($expectedSet); - - $foundScripts = scandir($tmpDir); - sort($foundScripts); - - $this->assertEquals($expectedSet, $foundScripts, "Expected batchmake scripts not found rooted from ".$scriptName); - - // add in '.' and '..' - $bmScriptsProcessed[] = '.'; - $bmScriptsProcessed[] = '..'; - sort($bmScriptsProcessed); - - // also check that the set of scripts returned from the method is this same set - $this->assertEquals($expectedSet, $bmScriptsProcessed, "Expected batchmake scripts not equal to those returned from processing ".$scriptName); - } - - protected function fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName) - { - try - { - // need to suppress error output to keep test from failing, despite exception being caught - $bmScripts = @$this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir,$tmpDir,$scriptName); - $this->fail('Expected an exception for $scriptName, but did not get one.'); - } - catch (Zend_Exception $ze) - { - // this is the correct behavior - } - } - - - - public function testFindAndSymLinkDependentBatchmakeScripts() - { - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $applicationConfig = $kwBatchmakeComponent->getApplicationConfigProperties(); - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $tmpDir = $kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - - - $scriptName = 'anotherscript.bms'; - $expectedSet = array("myscript.bms","Myscript2.bms", - "anotherscript.bms","noscripts.bms","PixelCounter.bms"); - $this->fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet); - - $scriptName = "noscripts.bms"; - $expectedSet = array("noscripts.bms"); - $this->fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet); - - // try symlinking all the batchmake files starting with anotherscriptwitherrors.bms - // expect an exception, as this script includes a non-existent script - $scriptName = 'anotherscriptwitherrors.bms'; - $this->fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName); - - // cycle detection tests - - // check a script with no cycle,1->2, 1->3, 3->2 - // clear the directory of the symlinked files - $scriptName = "nocycle1.bms"; - $expectedSet = array("nocycle1.bms","nocycle2.bms","nocycle3.bms"); - $this->fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet); - - // expect an exception, as this script has a simple cycle - // 1->1 - $scriptName = 'cycle1.bms'; - $this->fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName); - - // check a script with a more complex cycle, 1->2, 1->3, 2->3, 3->2 - $scriptName = 'cycle31.bms'; - $this->fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName); - } - - - public function xtestFindAndSymLinkDependentBmms() - { - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $applicationConfig = $kwBatchmakeComponent->getApplicationConfigProperties(); - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $tmpDir = $kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - - // now try symlinking all the batchmake files starting with anotherscript.bms - $scriptName = 'anotherscript.bms'; - $bmScripts_anotherscript = $kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScripts($scriptDir,$tmpDir,$scriptName); - - - $bmms = $kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts_anotherscript); - // these come as [ name of app => script where found ] - // convert them to a form useful for comparison - $processedBmms_anotherscript = array(); - foreach($bmms as $bmm=>$script) - { - $processedBmms_anotherscript[] = $bmm.'.bmm'; - } - sort($processedBmms_anotherscript); - - $globOutput = glob($tmpDir.'/*.bmm'); - // strip off the path - $foundBmms_anotherscript = array(); - foreach($globOutput as $bmm) - { - $foundBmms_anotherscript[] = basename($bmm); - } - sort( $foundBmms_anotherscript); - - $expectedBmms_anotherscript = array("AnotherApp.bmm","MyApp2.bmm", - "PixelCounter.bmm","TestApp1.bmm","TestApp2.bmm","myapp.bmm"); - sort($expectedBmms_anotherscript); - - // compare the three arrays - $this->assertEquals($processedBmms_anotherscript, $expectedBmms_anotherscript, "BMMs: processed != expected, for anotherscript.bms"); - $this->assertEquals($processedBmms_anotherscript, $foundBmms_anotherscript, "BMMs: processed != found, for anotherscript.bms"); - - } - - - - - - - - public function xtestExec() - { - // not sure how to test this exactly, for now create a tmp dir, check - // the value of pwd in it - require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $applicationConfig = $kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = $applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY]; - // delete any old files used by this test - $execDir = $tmpDir . '/' . 'exectmp'; - if(is_dir($execDir)) - { - rmdir($execDir); - } - mkdir($execDir); - $cmd = 'pwd'; - $chdir = $execDir; - $kwBatchmakeComponent->exec($cmd, $output, $chdir, $returnVal); - // $output should have one value, the same as execDir - $this->assertEquals($execDir, $output[0]); - // return_val should be 0 - $this->assertEquals($returnVal,0); - } - - public function xtestAppendStringIfNot() - { - // try one that doesn't have the suffix: - $subject = 'blah'; - $ext = '.exe'; - $subject = $this->kwBatchmakeComponent->appendStringIfNot($subject, $ext); - $this->assertEquals($subject,'blah.exe'); - // now try one that already has the suffix - $subject = 'blah'; - $ext = '.exe'; - $subject = $this->kwBatchmakeComponent->appendStringIfNot($subject, $ext); - $this->assertEquals($subject,'blah.exe'); - } - - public function xtestFindApp() - { - // first try something that should be in the path, php, and check that it - // is executable - $pathToApp = $this->kwBatchmakeComponent->findApp('php', true); - // now try something that is unlikely to be in the path - try - { - $pathToApp = $this->kwBatchmakeComponent->findApp('php_exe_that_is_vanishingly_likley_to_be_in_the_path', true); - $this->fail('Should have caught exception but did not, testFindApp'); - } - catch(Zend_Exception $ze) - { - // correct behavior - } - } - - public function xtestIsExecutable() - { - // this is tricky to test, as it is hard to make assumptions that hold - // up across platforms - // - // for now assume that 'pwd' will not be found - $this->assertFalse($this->kwBatchmakeComponent->isExecutable('pwd',false)); - // but 'pwd' will be found in the path - $this->assertTrue($this->kwBatchmakeComponent->isExecutable('pwd',true)); - } - - - - - public function xtestPrepareExecCommand() - { - $returnVal = $this->kwBatchmakeComponent->prepareExecCommand('php', array('blah1','blah2','blah3')); - $appPath = $this->kwBatchmakeComponent->findApp('php',true); - $this->assertEquals($returnVal,"'".$appPath."' 'blah1' 'blah2' 'blah3'"); - } - - public function xtestCompileBatchMakeScript() - { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = $this->kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - - // a script that compiles - $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScripts($scriptDir,$tmpDir,$scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); - - // first try with a bad path to BatchMake - $badBinDir = '/a/dir/not/likely/to/exist'; - try - { - $this->kwBatchmakeComponent->compileBatchMakeScript($appDir, $badBinDir, $tmpDir, $scriptName); - $this->fail('Should have not been able to find BatchMake, but did, testCompileBatchMakeScript'); - } - catch(Zend_Exception $ze) - { - // correct behavior - } - - // this one should work - $this->kwBatchmakeComponent->compileBatchMakeScript($appDir, $binDir, $tmpDir, $scriptName); - - // now try a script that doesn't compile - $scriptName = 'CompileErrors.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScripts($scriptDir,$tmpDir,$scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); - try - { - $this->kwBatchmakeComponent->compileBatchMakeScript($appDir, $binDir, $tmpDir, $scriptName); - $this->fail('Should have had a compile error but did not, testCompileBatchMakeScript'); - } - catch(Zend_Exception $ze) - { - // correct behavior - } - - } - - public function xtestGenerateCondorDag() - { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = $this->kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - // a script that compiles - $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScripts($scriptDir,$tmpDir,$scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); - - // try to generate the Condor script - $dagJobFile = $this->kwBatchmakeComponent->generateCondorDag($appDir, $tmpDir, $binDir, $scriptName); - $this->assertEquals($dagJobFile,'Compiles.bms.dagjob'); - // check that dag files and condor job files were created - $condorFiles = array($dagJobFile,'Compiles.1.bms.dagjob','Compiles.3.bms.dagjob','Compiles.5.bms.dagjob'); - foreach($condorFiles as $condorFile) - { - $this->assertFileExists($tmpDir.'/'.$condorFile); - } - // now look for some specific strings - $contents = file_get_contents($tmpDir.'/'. 'Compiles.bms.dagjob'); - $dagjobStrings = array('Job job3', 'Job job5','PARENT job1 CHILD job3', 'PARENT job3 CHILD job5'); - foreach($dagjobStrings as $string) - { - $this->assertTrue(preg_match("/".$string."/", $contents, $matches) === 1); - } - } - - - public function xtestCondorSubmitDag() - { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = $this->kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - $condorBinDir = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY]; - - // a script that compiles - $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScripts($scriptDir,$tmpDir,$scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); - - $dagScript = $this->kwBatchmakeComponent->generateCondorDag($appDir, $tmpDir, $binDir, $scriptName); - $this->kwBatchmakeComponent->condorSubmitDag($condorBinDir, $tmpDir, $dagScript); - // how to check this now? - } -/* - public function testSubmitCondorJob() - { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); - $usersFile = $this->loadData('User', 'default'); - $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = $this->kwBatchmakeComponent->createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - $condorBinDir = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY]; - // a script that compiles - $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScripts($scriptDir,$tmpDir,$scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); - - $submitFile = $this->kwBatchmakeComponent->generateCondorDagSubmit($condorBinDir, $appDir, $tmpDir, $binDir, $scriptName); - $this->kwBatchmakeComponent->submitCondorJob($condorBinDir, $tmpDir, $submitFile); - // now what to check for? - } - */ + $this->assertQuery("form#configForm"); + $applicationConfig = $this->kwBatchmakeComponent->loadConfigProperties(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); + // change a value to something bad + $this->params = array(); + $this->params[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY]; + $this->params[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; + $this->params[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; + $this->params[MIDAS_BATCHMAKE_APP_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; + $this->params[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY]; + $this->params[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY] = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY]; + // @TODO get these tests to a better state, testing more + // luckily, almost all of the functionality goes through KWBatchmakeComponent + // which is reasonably well tested + $this->params['submit'] = 'submitConfig'; + $this->request->setMethod('POST'); + $this->dispatchUrI("/batchmake/config", null, true); + } + + } diff --git a/modules/batchmake/tests/controllers/components/KWBatchmakeComponentTest.php b/modules/batchmake/tests/controllers/components/KWBatchmakeComponentTest.php index 16a69d765..e32fc26f5 100644 --- a/modules/batchmake/tests/controllers/components/KWBatchmakeComponentTest.php +++ b/modules/batchmake/tests/controllers/components/KWBatchmakeComponentTest.php @@ -27,9 +27,7 @@ public function __construct() // need to include the module constant for this test require_once BASE_PATH.'/modules/batchmake/constant/module.php'; require_once BASE_PATH.'/modules/batchmake/controllers/components/KWBatchmakeComponent.php'; - $this->kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(); - $this->kwBatchmakeComponent->setAlternateConfig(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); - $this->applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); + $this->kwBatchmakeComponent = new Batchmake_KWBatchmakeComponent(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); } /** set up tests*/ @@ -41,19 +39,18 @@ public function setUp() parent::setUp(); } - - // TEST KWBATCHMAKE COMPONENTS - // want a better way of doing this, but here is a start - /** * tests config setup, relies on an alternate testing config to be defined, * these properties should all point to the batchmake module testfiles dirs. */ - // should put the kwBatchmakeComponent as an instance variable? - // hopefully that would remove all of the redundant calls to setting it up public function testIsConfigCorrect() { $this->assertTrue($this->kwBatchmakeComponent->isConfigCorrect()); + // start out with know correct set + $badConfigVals = $this->kwBatchmakeComponent->loadConfigProperties(BASE_PATH.'/modules/batchmake/tests/configs/module.local.ini'); + // change a value to something bad + $badConfigVals[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY] = '/unlikely/to/work/right'; + $this->assertFalse($this->kwBatchmakeComponent->isConfigCorrect($badConfigVals)); } /** @@ -72,13 +69,6 @@ public function testGetBatchmakeScripts() $this->assertEquals($foundTestScripts, $expectedTestScripts); } - /** - * @TODO some model testing, and better ways of loading the models - * test creating a model and creating the right subdirs - */ - - - /** * helper function to clear out any files in a directory */ @@ -97,13 +87,13 @@ protected function clearDirFiles($dirToClear) /** * helper function to run a test case */ - protected function fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet) + protected function preparePipelineScriptsTestcase($workDir, $scriptName, $expectedSet) { // clear the directory of any existing files - $this->clearDirFiles($tmpDir); + $this->clearDirFiles($workDir); // try symlinking all the batchmake files starting with $scriptName - $bmScriptsProcessed = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); + $bmScriptsProcessed = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); // check that the correct batchmake scripts are there, and only those // easiest just to add '.' and '..' to expected list @@ -111,7 +101,7 @@ protected function fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expecte $expectedSet[] = '.'; sort($expectedSet); - $foundScripts = scandir($tmpDir); + $foundScripts = scandir($workDir); sort($foundScripts); $this->assertEquals($expectedSet, $foundScripts, @@ -130,12 +120,12 @@ protected function fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expecte /** * helper function to run a test case that is expected to throw an exception */ - protected function fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName) + protected function preparePipelineScriptsTestcaseException($workDir, $scriptName) { try { // need to suppress error output to keep test from failing, despite exception being caught - $bmScripts = @$this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); + $bmScripts = @$this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); $this->fail('Expected an exception for $scriptName, but did not get one.'); } catch(Zend_Exception $ze) @@ -146,38 +136,26 @@ protected function fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName) } - /** tests findAndSymLinkDependentBatchmakeScriptsWithCycleDetection. */ - public function testFindAndSymLinkDependentBatchmakeScriptsWithCycleDetection() + /** tests preparePipelineScripts, and exercises createTask. */ + public function testPreparePipelineScripts() { - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); $usersFile = $this->loadData('User', 'default'); $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $tmpDir = KWUtils::createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; + $workDir = $this->kwBatchmakeComponent->createTask($userDao); - $scriptName = 'anotherscript.bms'; $expectedSet = array("myscript.bms", "Myscript2.bms", "anotherscript.bms", "noscripts.bms", "PixelCounter.bms"); - $this->fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet); + $this->preparePipelineScriptsTestcase($workDir, $scriptName, $expectedSet); $scriptName = "noscripts.bms"; $expectedSet = array("noscripts.bms"); - $this->fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet); + $this->preparePipelineScriptsTestcase($workDir, $scriptName, $expectedSet); // try symlinking all the batchmake files starting with anotherscriptwitherrors.bms // expect an exception, as this script includes a non-existent script $scriptName = 'anotherscriptwitherrors.bms'; - $this->fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName); + $this->preparePipelineScriptsTestcaseException($workDir, $scriptName); // cycle detection tests @@ -185,44 +163,44 @@ public function testFindAndSymLinkDependentBatchmakeScriptsWithCycleDetection() // clear the directory of the symlinked files $scriptName = "nocycle1.bms"; $expectedSet = array("nocycle1.bms", "nocycle2.bms", "nocycle3.bms"); - $this->fASLDBSWCDtestcase($scriptDir, $tmpDir, $scriptName, $expectedSet); + $this->preparePipelineScriptsTestcase($workDir, $scriptName, $expectedSet); // expect an exception, as this script has a simple cycle // 1->1 $scriptName = 'cycle1.bms'; - $this->fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName); + $this->preparePipelineScriptsTestcaseException($workDir, $scriptName); // check a script with a more complex cycle, 1->2, 1->3, 2->3, 3->2 $scriptName = 'cycle31.bms'; - $this->fASLDBSWCDtestcaseException($scriptDir, $tmpDir, $scriptName); + $this->preparePipelineScriptsTestcaseException($workDir, $scriptName); } - /** tests findAndSymLinkDependentBmms */ - public function testFindAndSymLinkDependentBmms() + /** tests preparePipelineBmms */ + public function testPreparePipelineBmms() { - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); $usersFile = $this->loadData('User', 'default'); $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $tmpDir = KWUtils::createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); + $workDir = $this->kwBatchmakeComponent->createTask($userDao); - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; + // try a script that refers to a non-existant bmm + $scriptName = 'bmmswitherrors.bms'; + $bmScripts = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); + try + { + $bmms = $this->kwBatchmakeComponent->preparePipelineBmms($workDir, $bmScripts); + $this->fail('Expected an exception for '.$scriptName.', but did not get one.'); + } + catch(Zend_Exception $ze) + { + // if we got here, this is the correct behavior + $this->assertTrue(true); + } // now try symlinking all the batchmake files starting with anotherscript.bms $scriptName = 'anotherscript.bms'; - $bmScripts_anotherscript = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); - - - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts_anotherscript); + $bmScripts_anotherscript = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); + $bmms = $this->kwBatchmakeComponent->preparePipelineBmms($workDir, $bmScripts_anotherscript); // these come as [ name of app => script where found ] // convert them to a form useful for comparison $processedBmms_anotherscript = array(); @@ -232,7 +210,7 @@ public function testFindAndSymLinkDependentBmms() } sort($processedBmms_anotherscript); - $globOutput = glob($tmpDir.'/*.bmm'); + $globOutput = glob($workDir.'/*.bmm'); // strip off the path $foundBmms_anotherscript = array(); foreach($globOutput as $bmm) @@ -248,7 +226,6 @@ public function testFindAndSymLinkDependentBmms() // compare the three arrays $this->assertEquals($processedBmms_anotherscript, $expectedBmms_anotherscript, "BMMs: processed != expected, for anotherscript.bms"); $this->assertEquals($processedBmms_anotherscript, $foundBmms_anotherscript, "BMMs: processed != found, for anotherscript.bms"); - } @@ -260,51 +237,25 @@ public function testFindAndSymLinkDependentBmms() /** tests testCompileBatchMakeScript */ public function testCompileBatchMakeScript() { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); $usersFile = $this->loadData('User', 'default'); $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = KWUtils::createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); + $workDir = $this->kwBatchmakeComponent->createTask($userDao); - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - // a script that compiles $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); + $bmScripts = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); + $bmms = $this->kwBatchmakeComponent->preparePipelineBmms($workDir, $bmScripts); - // first try with a bad path to BatchMake - $badBinDir = '/a/dir/not/likely/to/exist'; - try - { - $this->kwBatchmakeComponent->compileBatchMakeScript($appDir, $badBinDir, $tmpDir, $scriptName); - $this->fail('Should have not been able to find BatchMake, but did, testCompileBatchMakeScript'); - } - catch(Zend_Exception $ze) - { - // if we got here, this is the correct behavior - $this->assertTrue(true); - } - // this one should work - $this->kwBatchmakeComponent->compileBatchMakeScript($appDir, $binDir, $tmpDir, $scriptName); + $this->kwBatchmakeComponent->compileBatchMakeScript($workDir, $scriptName); // now try a script that doesn't compile $scriptName = 'CompileErrors.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); + $bmScripts = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); + $bmms = $this->kwBatchmakeComponent->preparePipelineBmms($workDir, $bmScripts); try { - $this->kwBatchmakeComponent->compileBatchMakeScript($appDir, $binDir, $tmpDir, $scriptName); + $this->kwBatchmakeComponent->compileBatchMakeScript($workDir, $scriptName); $this->fail('Should have had a compile error but did not, testCompileBatchMakeScript'); } catch(Zend_Exception $ze) @@ -318,39 +269,26 @@ public function testCompileBatchMakeScript() /** tests generateCondorDag */ public function testGenerateCondorDag() { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); $usersFile = $this->loadData('User', 'default'); $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = KWUtils::createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); + $workDir = $this->kwBatchmakeComponent->createTask($userDao); - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - // a script that compiles $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); + $bmScripts = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); + $bmms = $this->kwBatchmakeComponent->preparePipelineBmms($workDir, $bmScripts); // try to generate the Condor script - $dagJobFile = $this->kwBatchmakeComponent->generateCondorDag($appDir, $tmpDir, $binDir, $scriptName); + $dagJobFile = $this->kwBatchmakeComponent->generateCondorDag($workDir, $scriptName); $this->assertEquals($dagJobFile, 'Compiles.bms.dagjob'); // check that dag files and condor job files were created $condorFiles = array($dagJobFile, 'Compiles.1.bms.dagjob', 'Compiles.3.bms.dagjob', 'Compiles.5.bms.dagjob'); foreach($condorFiles as $condorFile) { - $this->assertFileExists($tmpDir.'/'.$condorFile); + $this->assertFileExists($workDir.'/'.$condorFile); } // now look for some specific strings - $contents = file_get_contents($tmpDir.'/'. 'Compiles.bms.dagjob'); + $contents = file_get_contents($workDir.'/'. 'Compiles.bms.dagjob'); $dagjobStrings = array('Job job3', 'Job job5', 'PARENT job1 CHILD job3', 'PARENT job3 CHILD job5'); foreach($dagjobStrings as $string) { @@ -362,46 +300,19 @@ public function testGenerateCondorDag() /** tests function testCondorSubmitDag */ public function testCondorSubmitDag() { - // create a task - $modelLoad = new MIDAS_ModelLoader(); - $batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake'); $usersFile = $this->loadData('User', 'default'); $userDao = $this->User->load($usersFile[0]->getKey()); - $taskDao = $batchmakeTaskModel->createTask($userDao); - $userId = $taskDao->getUserId(); - $taskId = $taskDao->getKey(); - $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId); - // create a tmpDir based on the task and user - $applicationConfig = $this->kwBatchmakeComponent->getApplicationConfigProperties(); - $tmpDir = KWUtils::createSubDirectories($applicationConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY] . "/", $subdirs); - - $scriptDir = $applicationConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY]; - $binDir = $applicationConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY]; - $appDir = $applicationConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY]; - $condorBinDir = $applicationConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY]; + $workDir = $this->kwBatchmakeComponent->createTask($userDao); // a script that compiles $scriptName = 'Compiles.bms'; - $bmScripts = $this->kwBatchmakeComponent->findAndSymLinkDependentBatchmakeScriptsWithCycleDetection($scriptDir, $tmpDir, $scriptName); - $bmms = $this->kwBatchmakeComponent->findAndSymLinkDependentBmms($appDir, $tmpDir, $bmScripts); + $bmScripts = $this->kwBatchmakeComponent->preparePipelineScripts($workDir, $scriptName); + $bmms = $this->kwBatchmakeComponent->preparePipelineBmms($workDir, $bmScripts); - $dagScript = $this->kwBatchmakeComponent->generateCondorDag($appDir, $tmpDir, $binDir, $scriptName); - $this->kwBatchmakeComponent->condorSubmitDag($condorBinDir, $tmpDir, $dagScript); + $dagScript = $this->kwBatchmakeComponent->generateCondorDag($workDir, $scriptName); + $this->kwBatchmakeComponent->condorSubmitDag($workDir, $dagScript); // how to check this now? } - - - - - - - - - - - - - } // end class