Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 7f602ff

Browse files
author
Michael Grauer
committed
BUG: Refs #209. Fixed a failing test, and made other improvements from Charles.
There was a failing test because I was referring to "global" from the ini file, where the "global" key didn't exist. Charles gave me many good suggestions in QAing this original work, some of which I have added in. Also, I've moved some functionality from the ConfigController to the KWBatchmakeComponent in an attempt to allow them to be reused from other places in the module.
1 parent e5dd0b3 commit 7f602ff

File tree

5 files changed

+331
-187
lines changed

5 files changed

+331
-187
lines changed

modules/batchmake/Notification.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@
1313
/** notification manager*/
1414
class Batchmake_Notification extends MIDAS_Notification
1515
{
16-
public $_models=array('User');
17-
18-
16+
public $_moduleComponents=array('KWBatchmake');
17+
public $moduleName = 'batchmake';
18+
public $_components = array('Utility', 'Internationalization');
19+
1920
/** init notification process*/
2021
public function init()
2122
{
22-
$this->addCallBack('CALLBACK_CORE_GET_DASHBOARD', 'getDasboard');
23-
$this->addTask('TASK_BATCHMAKE_TEST', 'testMethod', 'test');
24-
$this->addEvent('EVENT_CORE_CREATE_THUMBNAIL', 'TASK_BATCHMAKE_TEST');
23+
$this->addCallBack('CALLBACK_CORE_GET_DASHBOARD', 'getDashboard');
2524
}//end init
2625

2726

28-
/** generate Dasboard information */
29-
public function getDasboard()
27+
/** generate Dashboard information */
28+
public function getDashboard()
3029
{
31-
$config = Zend_Registry::get('configsModules');
32-
3330
$return = array();
34-
$return['notice'] = 'This notification needs to be improved';
35-
31+
if($this->ModuleComponent->KWBatchmake->isConfigCorrect())
32+
{
33+
$return[$this->Component->Internationalization->translate(MIDAS_BATCHMAKE_CONFIG_CORRECT)] = 1;
34+
}
35+
else
36+
{
37+
$return[$this->Component->Internationalization->translate(MIDAS_BATCHMAKE_CONFIG_ERROR)] = 0;
38+
}
3639
return $return;
3740
}
3841
} //end class

modules/batchmake/constant/module.php

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,98 @@
99
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
12-
define("CHECK_IF_READABLE", 0x2);
13-
define("CHECK_IF_WRITABLE", 0x4);
14-
define("CHECK_IF_RW", 0x6); // 0x2 + 0x4;
15-
define("CHECK_IF_EXECUTABLE", 0x8);
16-
define("CHECK_IF_CHMODABLE", 0x10);
17-
define("CHECK_IF_CHMODABLE_RW", 0x16); // 0x10 + 0x6
12+
define("MIDAS_BATCHMAKE_CHECK_IF_READABLE", 0x2);
13+
define("MIDAS_BATCHMAKE_CHECK_IF_WRITABLE", 0x4);
14+
define("MIDAS_BATCHMAKE_CHECK_IF_RW", 0x6); // 0x2 + 0x4;
15+
define("MIDAS_BATCHMAKE_CHECK_IF_EXECUTABLE", 0x8);
16+
define("MIDAS_BATCHMAKE_CHECK_IF_CHMODABLE", 0x10);
17+
define("MIDAS_BATCHMAKE_CHECK_IF_CHMODABLE_RW", 0x16); // 0x10 + 0x6
1818

19-
define("DEFAULT_MKDIR_MODE", 0775);
19+
define("MIDAS_BATCHMAKE_DEFAULT_MKDIR_MODE", 0775);
2020

2121
// Condor executables
22-
define("CONDOR_STATUS", "condor_status");
23-
define("CONDOR_QUEUE", "condor_q");
24-
define("CONDOR_SUBMIT", "condor_submit");
25-
define("CONDOR_SUBMIT_DAG", "condor_submit_dag");
22+
define("MIDAS_BATCHMAKE_CONDOR_STATUS", "condor_status");
23+
define("MIDAS_BATCHMAKE_CONDOR_QUEUE", "condor_q");
24+
define("MIDAS_BATCHMAKE_CONDOR_SUBMIT", "condor_submit");
25+
define("MIDAS_BATCHMAKE_CONDOR_SUBMIT_DAG", "condor_submit_dag");
2626

2727
// Batchmake executable
28-
define("BATCHMAKE_EXE", "BatchMake");
28+
define("MIDAS_BATCHMAKE_EXE", "BatchMake");
2929

3030
// Extension automatically appended to dagman
3131
// description file when 'condor_dag_submit' generates it
32-
define("CONDOR_DAGMAN_EXT", ".condor.sub");
32+
define("MIDAS_BATCHMAKE_CONDOR_DAGMAN_EXT", ".condor.sub");
3333

3434
// default extension for a dagjob
35-
define("CONDOR_SCRIPT_EXT", ".dagjob");
35+
define("MIDAS_BATCHMAKE_CONDOR_SCRIPT_EXT", ".dagjob");
36+
// extension for a batchmake script
37+
define("MIDAS_BATCHMAKE_BATCHMAKE_EXTENSION", ".bms");
3638

3739
// properties set in the configuration
38-
define("TMP_DIR_PROPERTY", "tmp_dir");
39-
define("BIN_DIR_PROPERTY", "bin_dir");
40-
define("SCRIPT_DIR_PROPERTY", "script_dir");
41-
define("APP_DIR_PROPERTY", "app_dir");
42-
define("DATA_DIR_PROPERTY", "data_dir");
43-
define("CONDOR_BIN_DIR_PROPERTY", "condor_bin_dir");
40+
define("MIDAS_BATCHMAKE_TMP_DIR_PROPERTY", "tmp_dir");
41+
define("MIDAS_BATCHMAKE_BIN_DIR_PROPERTY", "bin_dir");
42+
define("MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY", "script_dir");
43+
define("MIDAS_BATCHMAKE_APP_DIR_PROPERTY", "app_dir");
44+
define("MIDAS_BATCHMAKE_DATA_DIR_PROPERTY", "data_dir");
45+
define("MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY", "condor_bin_dir");
4446

4547
// key for global config
46-
define("GLOBAL_CONFIG_NAME", "global");
48+
define("MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME", "global");
4749

4850
// status types
49-
define("STATUS_TYPE_INFO", "info");
50-
define("STATUS_TYPE_WARNING", "warning");
51-
define("STATUS_TYPE_ERROR", "error");
52-
define("CONFIG_VALUE_MISSING", "config value missing");
51+
define("MIDAS_BATCHMAKE_STATUS_TYPE_INFO", "info");
52+
define("MIDAS_BATCHMAKE_STATUS_TYPE_WARNING", "warning");
53+
define("MIDAS_BATCHMAKE_STATUS_TYPE_ERROR", "error");
5354

5455

56+
// config states
57+
define("MIDAS_BATCHMAKE_CONFIG_VALUE_MISSING", "config value missing");
58+
define("MIDAS_BATCHMAKE_CONFIG_CORRECT", "Configuration is correct");
59+
define("MIDAS_BATCHMAKE_CONFIG_ERROR", "Configuration is in error");
60+
5561
// config paths
56-
define("BATCHMAKE_MODULE", "batchmake");
57-
define("BATCHMAKE_CONFIGS_PATH", BASE_PATH . "/modules/" . BATCHMAKE_MODULE . "/configs/");
58-
define("BATCHMAKE_MODULE_CONFIG", BATCHMAKE_CONFIGS_PATH . "module.ini");
59-
define("BATCHMAKE_MODULE_LOCAL_CONFIG", BATCHMAKE_CONFIGS_PATH . "module.local.ini");
60-
define("BATCHMAKE_MODULE_LOCAL_OLD_CONFIG", BATCHMAKE_CONFIGS_PATH . "module.local.ini.old");
62+
define("MIDAS_BATCHMAKE_MODULE", "batchmake");
63+
define("MIDAS_BATCHMAKE_CONFIGS_PATH", BASE_PATH . "/modules/" . MIDAS_BATCHMAKE_MODULE . "/configs/");
64+
define("MIDAS_BATCHMAKE_MODULE_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.ini");
65+
define("MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.local.ini");
66+
define("MIDAS_BATCHMAKE_MODULE_LOCAL_OLD_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.local.ini.old");
67+
68+
69+
// submit button name for config
70+
define("MIDAS_BATCHMAKE_SUBMIT_CONFIG","submitConfig");
71+
6172

6273

6374

6475
// strings
65-
define("CHANGES_SAVED_STRING", 'Changes saved');
66-
define("APPLICATION_STRING", 'Application:');
67-
define("PHP_PROCESS_STRING", 'PHP Process');
68-
define("PHP_PROCESS_USER_STRING", 'user');
69-
define("PHP_PROCESS_NAME_STRING", 'name');
70-
define("PHP_PROCESS_GROUP_STRING", 'group');
71-
define("PHP_PROCESS_HOME_STRING", 'home');
72-
define("PHP_PROCESS_SHELL_STRING", 'shell');
73-
define("UNKNOWN_STRING", 'unknown');
74-
define("AJAX_DIRECT_LOAD_ERROR_STRING", 'Why are you here ? Should be ajax.');
75-
define("SAVE_CONFIGURATION_STRING", 'Save configuration');
76-
define("EXIST_STRING", 'Exist');
77-
define("NOT_FOUND_ON_CURRENT_SYSTEM_STRING", 'Not found on the current system');
78-
define("FILE_OR_DIRECTORY_DOESNT_EXIST_STRING", "File or directory doesn't exist:");
76+
define("MIDAS_BATCHMAKE_CHANGES_SAVED_STRING", 'Changes saved');
77+
define("MIDAS_BATCHMAKE_APPLICATION_STRING", 'Application:');
78+
define("MIDAS_BATCHMAKE_PHP_PROCESS_STRING", 'PHP Process');
79+
define("MIDAS_BATCHMAKE_PHP_PROCESS_USER_STRING", 'user');
80+
define("MIDAS_BATCHMAKE_PHP_PROCESS_NAME_STRING", 'name');
81+
define("MIDAS_BATCHMAKE_PHP_PROCESS_GROUP_STRING", 'group');
82+
define("MIDAS_BATCHMAKE_PHP_PROCESS_HOME_STRING", 'home');
83+
define("MIDAS_BATCHMAKE_PHP_PROCESS_SHELL_STRING", 'shell');
84+
define("MIDAS_BATCHMAKE_UNKNOWN_STRING", 'unknown');
85+
define("MIDAS_BATCHMAKE_AJAX_DIRECT_LOAD_ERROR_STRING", 'Why are you here ? Should be ajax.');
86+
define("MIDAS_BATCHMAKE_SAVE_CONFIGURATION_STRING", 'Save configuration');
87+
define("MIDAS_BATCHMAKE_EXIST_STRING", 'Exist');
88+
define("MIDAS_BATCHMAKE_NOT_FOUND_ON_CURRENT_SYSTEM_STRING", 'Not found on the current system');
89+
define("MIDAS_BATCHMAKE_FILE_OR_DIRECTORY_DOESNT_EXIST_STRING", "File or directory doesn't exist:");
7990

8091

8192

8293

8394
// property keys
84-
define("DIR_KEY",'dir');
85-
define("PROPERTY_KEY",'property');
86-
define("STATUS_KEY",'status');
87-
define("TYPE_KEY",'type');
95+
define("MIDAS_BATCHMAKE_DIR_KEY",'dir');
96+
define("MIDAS_BATCHMAKE_PROPERTY_KEY",'property');
97+
define("MIDAS_BATCHMAKE_STATUS_KEY",'status');
98+
define("MIDAS_BATCHMAKE_TYPE_KEY",'type');
8899

89100

101+
// properties for the batchmake execution view
102+
define("MIDAS_BATCHMAKE_AVAILABLE_SCRIPTS",'Batchmake Scripts');
103+
define("MIDAS_BATCHMAKE_EDIT_CONFIG",'edit Batchmake configuration');
90104

91105

92-
93106
?>

modules/batchmake/controllers/ConfigController.php

Lines changed: 21 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ class Batchmake_ConfigController extends Batchmake_AppController
5959
*/
6060
protected function archiveOldModuleLocal()
6161
{
62-
if(file_exists(BATCHMAKE_MODULE_LOCAL_OLD_CONFIG))
62+
if(file_exists(MIDAS_BATCHMAKE_MODULE_LOCAL_OLD_CONFIG))
6363
{
64-
unlink(BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
64+
unlink(MIDAS_BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
6565
}
66-
if(file_exists(BATCHMAKE_MODULE_LOCAL_CONFIG))
66+
if(file_exists(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG))
6767
{
68-
rename(BATCHMAKE_MODULE_LOCAL_CONFIG, BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
68+
rename(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, MIDAS_BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
6969
}
7070
}
7171

@@ -79,126 +79,38 @@ function indexAction()
7979

8080
$applicationConfig = $this->ModuleComponent->KWBatchmake->loadApplicationConfig();
8181
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements();
82-
8382
$configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements);
8483
$formArray = $this->getFormAsArray($configForm);
8584
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
8685
{
87-
$formArray[$configProperty]->setValue($applicationConfig[GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty]);
86+
$formArray[$configProperty]->setValue($applicationConfig[$this->moduleName.'.'.$configProperty]);
8887
}
8988
$this->view->configForm = $formArray;
9089

9190
if($this->_request->isPost())
9291
{
9392
$this->_helper->layout->disableLayout();
9493
$this->_helper->viewRenderer->setNoRender();
95-
$submitConfig = $this->_getParam('submitConfig');
94+
$submitConfig = $this->_getParam(MIDAS_BATCHMAKE_SUBMIT_CONFIG);
9695

9796
if(isset($submitConfig))
9897
{
9998
$this->archiveOldModuleLocal();
99+
// save only those properties we are interested for local configuration
100+
$newsaver = array();
100101
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
101102
{
102-
$applicationConfig[GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
103+
$newsaver[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
103104
}
104-
$this->Component->Utility->createInitFile(BATCHMAKE_MODULE_LOCAL_CONFIG, $applicationConfig);
105-
$msg = $this->Component->Internationalization->translate(CHANGES_SAVED_STRING);
105+
$this->Component->Utility->createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $newsaver);
106+
$msg = $this->t(MIDAS_BATCHMAKE_CHANGES_SAVED_STRING);
106107
echo JsonComponent::encode(array(true, $msg));
107108
}
108109
}
109110

110111
}
111112

112113

113-
/**
114-
* @method testconfig()
115-
* performs validation on the current configuration set through the UI
116-
*/
117-
protected function testconfig()
118-
{
119-
120-
//default of correct config
121-
$total_config_correct = 1;
122-
// get the passed in config values to check
123-
$configStatus = array();
124-
125-
126-
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->GetConfigPropertiesRequirements();
127-
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
128-
{
129-
$configPropertyVal = $this->_getParam($configProperty);
130-
if($configPropertyVal)
131-
{
132-
// if the property exists, check its configuration
133-
list($result, $status) = $this->ModuleComponent->KWBatchmake->CheckFileFlag($configPropertyVal, $configPropertyRequirement);
134-
$configStatus[] = array(PROPERTY_KEY => $configProperty, STATUS_KEY => $status, TYPE_KEY => $result ? STATUS_TYPE_INFO : STATUS_TYPE_ERROR);
135-
// the property is in error, therefore so is the global config
136-
if(!$result)
137-
{
138-
$total_config_correct = 0;
139-
}
140-
}
141-
else
142-
{
143-
// property doesn't exist, both the property and global config are in error
144-
$configStatus[] = array(PROPERTY_KEY => $configProperty, STATUS_KEY => CONFIG_VALUE_MISSING, TYPE_KEY => STATUS_TYPE_ERROR);
145-
$total_config_correct = 0;
146-
}
147-
}
148-
149-
// for now assuming will run via condor, so require all of the condor setup
150-
151-
$appsPaths = $this->ModuleComponent->KWBatchmake->GetApplicationsPaths();
152-
foreach($appsPaths as $app => $pathProperty)
153-
{
154-
$appPath = $this->_getParam($pathProperty) ."/" . $this->ModuleComponent->KWBatchmake->FormatAppName($app);
155-
list($result, $status) = $this->ModuleComponent->KWBatchmake->CheckFileFlag($appPath, CHECK_IF_EXECUTABLE);
156-
$applicationString = $this->Component->Internationalization->translate(APPLICATION_STRING);
157-
$configStatus[] = array(PROPERTY_KEY => $applicationString . ' ' .$appPath, STATUS_KEY => $status, TYPE_KEY => $result ? STATUS_TYPE_INFO : STATUS_TYPE_ERROR);
158-
// the property is in error, therefore so is the global config
159-
if(!$result)
160-
{
161-
$total_config_correct = 0;
162-
}
163-
}
164-
165-
// Process web server user information
166-
167-
// TODO what should be done if there are warnings??
168-
$processUser = posix_getpwuid(posix_geteuid());
169-
$processGroup = posix_getgrgid(posix_geteuid());
170-
171-
$phpProcessString = $this->Component->Internationalization->translate(PHP_PROCESS_STRING);
172-
$phpProcessUserString = $phpProcessString . ' ' . $this->Component->Internationalization->translate(PHP_PROCESS_USER_STRING);
173-
$phpProcessNameString = $this->Component->Internationalization->translate(PHP_PROCESS_NAME_STRING);
174-
$phpProcessGroupString = $this->Component->Internationalization->translate(PHP_PROCESS_GROUP_STRING);
175-
$phpProcessHomeString = $this->Component->Internationalization->translate(PHP_PROCESS_HOME_STRING);
176-
$phpProcessShellString = $this->Component->Internationalization->translate(PHP_PROCESS_SHELL_STRING);
177-
$unknownString = $this->Component->Internationalization->translate(UNKNOWN_STRING);
178-
179-
$phpProcessUserNameString = $phpProcessUserString . '[' . $phpProcessNameString . ']';
180-
$phpProcessUserGroupString = $phpProcessUserString . '[' . $phpProcessGroupString . ']';
181-
$phpProcessUserHomeString = $phpProcessUserString . '[' . $phpProcessHomeString . ']';
182-
$phpProcessUserShellString = $phpProcessUserString . '[' . $phpProcessShellString . ']';
183-
184-
$processProperties = array($phpProcessUserNameString => !empty($processUser[PHP_PROCESS_NAME_STRING]) ? $processUser[PHP_PROCESS_NAME_STRING] : "",
185-
$phpProcessUserGroupString => !empty($processGroup[PHP_PROCESS_NAME_STRING]) ? $processGroup[PHP_PROCESS_NAME_STRING] : "",
186-
$phpProcessUserHomeString => !empty($processUser[DIR_KEY]) ? $processUser[DIR_KEY] : "",
187-
$phpProcessUserShellString => !empty($processUser[PHP_PROCESS_SHELL_STRING]) ? $processUser[PHP_PROCESS_SHELL_STRING] : "");
188-
189-
foreach($processProperties as $property => $value)
190-
{
191-
$status = !empty($value);
192-
$configStatus[] = array(PROPERTY_KEY => $property,
193-
STATUS_KEY => $status ? $value : $unknownString,
194-
TYPE_KEY => $status ? STATUS_TYPE_INFO : STATUS_TYPE_WARNING);
195-
}
196-
197-
198-
return array($total_config_correct, $configStatus);
199-
200-
}
201-
202114

203115
/**
204116
* @method testconfigAction()
@@ -209,13 +121,21 @@ public function testconfigAction()
209121
{
210122
if(!$this->getRequest()->isXmlHttpRequest())
211123
{
212-
$ajaxDirectLoadErrorString = $this->Component->Internationalization->translate(AJAX_DIRECT_LOAD_ERROR_STRING);
124+
$ajaxDirectLoadErrorString = $this->t(MIDAS_BATCHMAKE_AJAX_DIRECT_LOAD_ERROR_STRING);
213125
throw new Zend_Exception($ajaxDirectLoadErrorString);
214126
}
215127
$this->_helper->layout->disableLayout();
216128
$this->_helper->viewRenderer->setNoRender();
217129

218-
$config_status = $this->testconfig();
130+
131+
$configPropertiesParamVals = array();
132+
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->GetConfigPropertiesRequirements();
133+
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
134+
{
135+
$configPropertiesParamVals[$configProperty] = $this->_getParam($configProperty);
136+
}
137+
138+
$config_status = $this->ModuleComponent->KWBatchmake->testconfig($configPropertiesParamVals);
219139
echo JsonComponent::encode($config_status);
220140
}//end testconfigAction
221141

0 commit comments

Comments
 (0)