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

Commit 1416fc0

Browse files
author
Michael Grauer
committed
BUG: Refs #212. Initial work towards better default configuration of batchmake
1 parent c1b78de commit 1416fc0

File tree

5 files changed

+129
-10
lines changed

5 files changed

+129
-10
lines changed

modules/batchmake/Notification.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
12+
require_once BASE_PATH . '/modules/api/library/APIEnabledNotification.php';
1213

1314
/** notification manager*/
14-
class Batchmake_Notification extends MIDAS_Notification
15+
class Batchmake_Notification extends ApiEnabled_Notification
1516
{
16-
public $_moduleComponents=array('KWBatchmake');
1717
public $moduleName = 'batchmake';
18-
public $_components = array('Utility', 'Internationalization');
18+
public $_components = array('Utility', 'Internationalization');
19+
public $_moduleComponents=array('KWBatchmake','Api');
1920

2021
/** init notification process*/
2122
public function init()
2223
{
24+
$this->enableWebAPI($this->moduleName);
2325
$this->addCallBack('CALLBACK_CORE_GET_DASHBOARD', 'getDashboard');
2426
$this->addCallBack('CALLBACK_CORE_GET_LEFT_LINKS', 'getLeftLink');
2527
}//end init

modules/batchmake/constant/module.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363

6464
// config paths
6565
define("MIDAS_BATCHMAKE_MODULE", "batchmake");
66-
define("MIDAS_BATCHMAKE_CONFIGS_PATH", BASE_PATH . "/modules/" . MIDAS_BATCHMAKE_MODULE . "/configs/");
67-
define("MIDAS_BATCHMAKE_MODULE_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.ini");
68-
define("MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.local.ini");
69-
define("MIDAS_BATCHMAKE_MODULE_LOCAL_OLD_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.local.ini.old");
66+
define("MIDAS_BATCHMAKE_CONFIGS_PATH", BASE_PATH . "/core/configs/" . MIDAS_BATCHMAKE_MODULE);
67+
//define("MIDAS_BATCHMAKE_MODULE_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . "module.ini");
68+
define("MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . ".local.ini");
69+
define("MIDAS_BATCHMAKE_MODULE_LOCAL_OLD_CONFIG", MIDAS_BATCHMAKE_CONFIGS_PATH . ".local.ini.old");
7070

7171

7272
// submit button name for config

modules/batchmake/controllers/ConfigController.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,46 @@ protected function archiveOldModuleLocal()
5050
}
5151
}
5252

53-
53+
54+
55+
/**
56+
* will create default paths in the midas temp directory
57+
* for any properties not already set, except for the
58+
* condor bin dir; imposing a firmer hand on the user
59+
* @param type $currentConfig
60+
*/
61+
protected function createDefaultConfig($currentConfig)
62+
{
63+
$tmpDir = $this->getTempDirectory();
64+
$defaultConfigDirs = array(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => $tmpDir.'/batchmake/tmp',
65+
MIDAS_BATCHMAKE_BIN_DIR_PROPERTY => $tmpDir.'/batchmake/bin',
66+
MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY => $tmpDir.'/batchmake/script',
67+
MIDAS_BATCHMAKE_APP_DIR_PROPERTY => $tmpDir.'/batchmake/bin',
68+
MIDAS_BATCHMAKE_DATA_DIR_PROPERTY => $tmpDir.'/batchmake/data');
69+
$returnedConfig = array();
70+
foreach($currentConfig as $configProp => $configDir)
71+
{
72+
if(!isset($configProp) || !isset($configDir) || $configDir == "")
73+
{
74+
$configDir = $defaultConfigDirs[$configProp];
75+
$returnedConfig[$configProp] = $configDir;
76+
// also create this directory to be sure it exists
77+
if(!KWUtils::mkDir($configDir))
78+
{
79+
throw new Zend_Exception("Cannot create directory ".$configDir);
80+
}
81+
}
82+
else
83+
{
84+
$returnedConfig[$configProp] = $configDir;
85+
}
86+
}
87+
return $returnedConfig;
88+
}
89+
90+
91+
92+
5493

5594
/**
5695
* @method indexAction(), will test the configuration that the user has set
@@ -60,6 +99,7 @@ public function indexAction()
6099
{
61100

62101
$applicationConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties();
102+
$applicationConfig = $this->createDefaultConfig($applicationConfig);
63103
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements();
64104
$configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements);
65105
$formArray = $this->getFormAsArray($configForm);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
/** Component for api methods */
14+
class Batchmake_ApiComponent extends AppComponent
15+
{
16+
17+
18+
/**
19+
* Helper function for verifying keys in an input array
20+
*/
21+
private function _checkKeys($keys, $values)
22+
{
23+
foreach($keys as $key)
24+
{
25+
if(!array_key_exists($key, $values))
26+
{
27+
throw new Exception('Parameter '.$key.' must be set.', -1);
28+
}
29+
}
30+
}
31+
32+
33+
/**
34+
* @param tmp_dir the path to the batchmake temp dir
35+
* @param bin_dir the path to the batchmake bin dir, should have BatchMake exe
36+
* @param script_dir the path to the batchmake script dir, where bms files live
37+
* @param app_dir the path to the dir housing executables
38+
* @param data_dir the path to the data export dir
39+
* @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
41+
* if the config is correct, the second value is a list of individual
42+
* config values and their status.
43+
*/
44+
public function testConfig($value)
45+
{
46+
// any values that aren't filled in, fill them in with a blank
47+
$expectedKeys = array("tmp_dir", "bin_dir", "script_dir", "app_dir", "data_dir", "condor_bin_dir");
48+
$replacements = array();
49+
foreach($value as $key=>$value)
50+
{
51+
if(!isset($key))
52+
{
53+
$replacements[$key] = "";
54+
}
55+
}
56+
foreach($replacements as $replacement=>$val)
57+
{
58+
$value[$replacement] = $val;
59+
}
60+
61+
62+
$this->_checkKeys(array('item_id', 'metric_name'), $value);
63+
64+
$componentLoader = new MIDAS_ComponentLoader();
65+
$kwbatchmakeComponent = $componentLoader->loadComponent('KWBatchmake', 'batchmake');
66+
return array($kwbatchmakeComponent->testconfig($value));
67+
}
68+
69+
70+
71+
72+
} // end class
73+
74+
75+
76+

modules/batchmake/controllers/components/KWBatchmakeComponent.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,18 @@ public function __construct($alternateConfig = null, $executor = null)
9191
*/
9292
protected function loadConfig()
9393
{
94+
$path = MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG;
9495
if(file_exists(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG))
9596
{
9697
$config = parse_ini_file(MIDAS_BATCHMAKE_MODULE_LOCAL_CONFIG, false);
9798
}
9899
else
99100
{
100-
$config = parse_ini_file(MIDAS_BATCHMAKE_MODULE_CONFIG);
101+
throw new Zend_Exception("The Batchmake module has not been enabled. Enable it through the Midas administration tab");
101102
}
102103
return $config;
103104
}
104-
105+
105106
/**
106107
* @method loadConfigProperties
107108
* will load the configuration property values for this module, and filter

0 commit comments

Comments
 (0)