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

Commit d476677

Browse files
Michael GraueryuzhengZ
authored andcommitted
BUG: Refs #212. Better default configuration of batchmake.
When using the Config controller through the midas application, batchmake now provides default paths and creates those directories for the config variables it needs. These dirs get created under the midas tmp dir. Furthermore, the ajax call to test the config that the user has entered has been moved to the more standard ajax libary methods, and an ApiComponent has been created to provide web-api calls.
1 parent 972d7c5 commit d476677

File tree

11 files changed

+195
-234
lines changed

11 files changed

+195
-234
lines changed

modules/batchmake/controllers/ConfigController.php

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ protected function archiveOldModuleLocal()
5050
}
5151
}
5252

53-
54-
53+
54+
5555
/**
5656
* will create default paths in the midas temp directory
5757
* for any properties not already set, except for the
5858
* condor bin dir; imposing a firmer hand on the user
59-
* @param type $currentConfig
59+
* @param type $currentConfig
6060
*/
6161
protected function createDefaultConfig($currentConfig)
6262
{
@@ -72,7 +72,7 @@ protected function createDefaultConfig($currentConfig)
7272
if((!isset($configProp) || !isset($configDir) || $configDir == "") && array_key_exists($configProp, $defaultConfigDirs))
7373
{
7474
$configDir = $defaultConfigDirs[$configProp];
75-
$returnedConfig[$configProp] = $configDir;
75+
$returnedConfig[$configProp] = $configDir;
7676
// also create this directory to be sure it exists
7777
if(!KWUtils::mkDir($configDir))
7878
{
@@ -84,12 +84,12 @@ protected function createDefaultConfig($currentConfig)
8484
$returnedConfig[$configProp] = $configDir;
8585
}
8686
}
87-
return $returnedConfig;
87+
return $returnedConfig;
8888
}
89-
90-
91-
92-
89+
90+
91+
92+
9393

9494
/**
9595
* @method indexAction(), will test the configuration that the user has set
@@ -98,15 +98,14 @@ protected function createDefaultConfig($currentConfig)
9898
public function indexAction()
9999
{
100100
// get all the properties, not just the batchmake config
101-
$fullConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null,false);
101+
$fullConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null, false);
102102
// now get just the batchmake ones
103103
$batchmakeConfig = $this->ModuleComponent->KWBatchmake->filterBatchmakeConfigProperties($fullConfig);
104-
105-
// $applicationConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties();
104+
// create these properties as default dir locations in tmp
106105
$batchmakeConfig = $this->createDefaultConfig($batchmakeConfig);
107106
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements();
108107

109-
108+
110109

111110
if($this->_request->isPost())
112111
{
@@ -116,65 +115,32 @@ public function indexAction()
116115

117116
if(isset($submitConfig))
118117
{
118+
// user wants to save config
119119
$this->archiveOldModuleLocal();
120120
// save only those properties we are interested for local configuration
121121
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
122122
{
123123
$fullConfig[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
124124
}
125125
$this->Component->Utility->createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $fullConfig);
126-
// $newsaver = array();
127-
// foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
128-
// {
129-
// $newsaver[MIDAS_BATCHMAKE_GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
130-
// }
131-
// $this->Component->Utility->createInitFile(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, $newsaver);
132126
$msg = $this->t(MIDAS_BATCHMAKE_CHANGES_SAVED_STRING);
133127
echo JsonComponent::encode(array(true, $msg));
134128
}
135129
}
136130
else
137131
{
132+
// populate config form with values
138133
$configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements);
139134
$formArray = $this->getFormAsArray($configForm);
140135
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
141136
{
142137
$formArray[$configProperty]->setValue($batchmakeConfig[$configProperty]);
143138
}
144-
$this->view->configForm = $formArray;
139+
$this->view->configForm = $formArray;
145140
}
146141

147142
}
148143

149144

150145

151-
/**
152-
* @method testconfigAction()
153-
* ajax function which tests config setup, performing
154-
* validation on the current configuration set through the UI
155-
*/
156-
public function testconfigAction()
157-
{
158-
if(!$this->getRequest()->isXmlHttpRequest())
159-
{
160-
$ajaxDirectLoadErrorString = $this->t(MIDAS_BATCHMAKE_AJAX_DIRECT_LOAD_ERROR_STRING);
161-
throw new Zend_Exception($ajaxDirectLoadErrorString);
162-
}
163-
$this->_helper->layout->disableLayout();
164-
$this->_helper->viewRenderer->setNoRender();
165-
166-
167-
$configPropertiesParamVals = array();
168-
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements();
169-
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
170-
{
171-
$configPropertiesParamVals[$configProperty] = $this->_getParam($configProperty);
172-
}
173-
174-
$config_status = $this->ModuleComponent->KWBatchmake->testconfig($configPropertiesParamVals);
175-
$jsonout = JsonComponent::encode($config_status);
176-
echo $jsonout;
177-
}//end testconfigAction
178-
179-
180146
}//end class

modules/batchmake/controllers/components/ApiComponent.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
/** Component for api methods */
1414
class Batchmake_ApiComponent extends AppComponent
1515
{
16-
17-
16+
17+
1818
/**
1919
* Helper function for verifying keys in an input array
2020
*/
@@ -28,7 +28,7 @@ private function _checkKeys($keys, $values)
2828
}
2929
}
3030
}
31-
31+
3232

3333
/**
3434
* @param tmp_dir the path to the batchmake temp dir
@@ -37,7 +37,7 @@ private function _checkKeys($keys, $values)
3737
* @param app_dir the path to the dir housing executables
3838
* @param data_dir the path to the data export dir
3939
* @param condor_bin_dir the path to the location of the condor executables
40-
* @return an array, the first value is a 0 if the config is incorrect or 1
40+
* @return an array, the first value is a 0 if the config is incorrect or 1
4141
* if the config is correct, the second value is a list of individual config values and their statuses.
4242
*/
4343
public function testconfig($params)
@@ -49,24 +49,24 @@ public function testconfig($params)
4949
{
5050
if(!isset($params[$propKey]))
5151
{
52-
$configParams[$propKey] = "";
52+
$configParams[$propKey] = "";
5353
}
5454
else
5555
{
56-
$configParams[$propKey] = $params[$propKey];
56+
$configParams[$propKey] = $params[$propKey];
5757
}
58-
}
59-
60-
//$this->_checkKeys(array('item_id', 'metric_name'), $value);
61-
58+
}
59+
60+
//$this->_checkKeys(array('item_id', 'metric_name'), $value);
61+
6262
$componentLoader = new MIDAS_ComponentLoader();
6363
$kwbatchmakeComponent = $componentLoader->loadComponent('KWBatchmake', 'batchmake');
64-
return array($kwbatchmakeComponent->testconfig($configParams));
64+
return $kwbatchmakeComponent->testconfig($configParams);
6565
}
66-
67-
68-
69-
66+
67+
68+
69+
7070
} // end class
7171

7272

modules/batchmake/controllers/components/KWBatchmakeComponent.php

Lines changed: 24 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Batchmake_KWBatchmakeComponent extends AppComponent
2727
MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY => MIDAS_BATCHMAKE_CHECK_IF_READABLE);
2828

2929
/**
30-
* accessor functin to return the names of the config propeties, and
30+
* accessor function to return the names of the config propeties, and
3131
* their filesystem requirements;
3232
*/
3333
public static function getConfigPropertiesRequirements()
@@ -43,7 +43,7 @@ public static function getConfigPropertiesRequirements()
4343
MIDAS_BATCHMAKE_EXE => MIDAS_BATCHMAKE_BIN_DIR_PROPERTY);
4444

4545
/**
46-
* accessor functin to return the application names, along with their
46+
* accessor function to return the application names, along with their
4747
* expected location property.
4848
*/
4949
public static function getApplicationsPaths()
@@ -87,6 +87,8 @@ public function __construct($alternateConfig = null, $executor = null)
8787

8888
/**
8989
* helper function to load the correct config file
90+
* @param bool $processSections param to be passed on to parse_ini_file,
91+
* default is false
9092
* @return config array with config properties
9193
*/
9294
protected function loadConfig($processSections = false)
@@ -102,9 +104,15 @@ protected function loadConfig($processSections = false)
102104
}
103105
return $config;
104106
}
105-
106-
107-
107+
108+
109+
/**
110+
* takes in an array read out of an ini file, looks in the 'global'
111+
* space, and returns an array of only those properties that begin
112+
* with batchmake.
113+
* @param type $fullConfig
114+
* @return type
115+
*/
108116
public function filterBatchmakeConfigProperties($fullConfig)
109117
{
110118
$batchmakeProps = array();
@@ -121,54 +129,41 @@ public function filterBatchmakeConfigProperties($fullConfig)
121129
}
122130
return $batchmakeProps;
123131
}
124-
125-
132+
133+
126134
/**
127135
* @method loadConfigProperties
128-
* will load the configuration property values for this module, and filter
129-
* out only those properties that are in the 'batchmake.' config namespace,
130-
* removing the 'batchmake.' from the key name.
136+
* will load the configuration property values for this module
131137
* @param string $alternateConfig an array of alternate config props
132138
* @param boolean $batchmakeOnly whether to get all properties or only config
139+
* properties that are in the 'batchmake.' config namespace,
140+
* removing the 'batchmake.' from the key name if true.
133141
* @return array of batchmake module specific config properties
134142
*/
135143
public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = true)
136144
{
137145
// load the full config
138146
$rawConfig = $this->loadConfig(true);
147+
// get the global namespace props
139148
$globalProps = $rawConfig['global'];
140-
// now set all the batchmake properties, except if we have any alternatives
149+
// now set all the batchmake properties if we have any alternatives
141150
$configPropertiesParamVals = array();
142151
if(isset($alternateConfig))
143152
{
144153
$configPropertiesParamVals = $alternateConfig;
145154
// set these properties in the rawConfig
146155
foreach($alternateConfig as $propKey => $propVal)
147156
{
148-
$globalProps[MIDAS_BATCHMAKE_MODULE . '.' . $propKey] = $propVal;
157+
$globalProps[MIDAS_BATCHMAKE_MODULE . '.' . $propKey] = $propVal;
149158
}
150159
$rawConfig['global'] = $globalProps;
151160
}
152-
// else
153-
// {
161+
// get out the batchmake props
154162
$batchmakeProps = $this->filterBatchmakeConfigProperties($rawConfig);
155163
foreach($batchmakeProps as $configProperty => $configPropertyVal)
156164
{
157-
$configPropertiesParamVals[$configProperty] = $configPropertyVal;
165+
$configPropertiesParamVals[$configProperty] = $configPropertyVal;
158166
}
159-
160-
/* $configPropertiesParamVals = array();
161-
$modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.';
162-
foreach($globalProps as $configProperty => $configPropertyVal)
163-
{
164-
$ind = strpos($configProperty, $modulePropertyNamespace);
165-
if($ind !== false && $ind == 0)
166-
{
167-
$reducedKey = substr($configProperty, strpos($configProperty, '.') + 1);
168-
$configPropertiesParamVals[$reducedKey] = $configPropertyVal;
169-
}
170-
}*/
171-
// }
172167
// set the member fields for config variables
173168
$this->componentConfig = $configPropertiesParamVals;
174169
$this->configScriptDir = $this->componentConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
@@ -184,44 +179,8 @@ public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = t
184179
}
185180
else
186181
{
187-
return $rawConfig;
188-
}
189-
190-
191-
/* if(!isset($alternateConfig))
192-
{
193-
$rawConfig = $this->loadConfig();
194-
195-
// batchmakeOnly option says to remove all other properties than those
196-
// prefixed with "batchmake."
197-
if($batchmakeOnly)
198-
{
199-
$modulePropertyNamespace = MIDAS_BATCHMAKE_MODULE . '.';
200-
foreach($rawConfig as $configProperty => $configPropertyVal)
201-
{
202-
$ind = strpos($configProperty, $modulePropertyNamespace);
203-
if($ind !== false && $ind == 0)
204-
{
205-
$reducedKey = substr($configProperty, strpos($configProperty, '.') + 1);
206-
$configPropertiesParamVals[$reducedKey] = $configPropertyVal;
207-
}
208-
}
209-
}
210-
}
211-
else
212-
{
213-
$configPropertiesParamVals = $alternateConfig;
182+
return $rawConfig;
214183
}
215-
216-
*/
217-
// $this->componentConfig = $configPropertiesParamVals;
218-
// $this->configScriptDir = $this->componentConfig[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
219-
// $this->configAppDir = $this->componentConfig[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
220-
// $this->configTmpDir = $this->componentConfig[MIDAS_BATCHMAKE_TMP_DIR_PROPERTY];
221-
// $this->configBinDir = $this->componentConfig[MIDAS_BATCHMAKE_BIN_DIR_PROPERTY];
222-
// $this->configDataDir = $this->componentConfig[MIDAS_BATCHMAKE_DATA_DIR_PROPERTY];
223-
// $this->configCondorBinDir = $this->componentConfig[MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY];
224-
// return $this->componentConfig;
225184
}
226185

227186
// above here is config setup

modules/batchmake/models/AppDao.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
12-
12+
/** AppDao class for batchmake module */
1313
class Batchmake_AppDao extends MIDAS_GlobalDao
1414
{
15-
public $moduleName='batchmake';
16-
15+
public $moduleName = 'batchmake';
16+
1717
} //end class
1818

1919
?>

modules/batchmake/models/AppModel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13+
/** AppModel class for batchmake module */
1314
class Batchmake_AppModel extends MIDASModel
1415
{
15-
public $moduleName='batchmake';
16+
public $moduleName = 'batchmake';
17+
1618

17-
1819
}
1920
?>

0 commit comments

Comments
 (0)