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

Commit 18721a1

Browse files
author
Michael Grauer
committed
BUG: refs #68. Added models for condor_dag and condor_job, and api addition.
1 parent 358ae08 commit 18721a1

File tree

10 files changed

+287
-3
lines changed

10 files changed

+287
-3
lines changed

modules/batchmake/controllers/components/ApiComponent.php

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

13+
// Web API error codes
14+
define('MIDAS_BATCHMAKE_INVALID_POLICY', -151);
15+
define('MIDAS_BATCHMAKE_INVALID_PARAMETER', -150);
16+
1317
/** Component for api methods */
1418
class Batchmake_ApiComponent extends AppComponent
1519
{
@@ -28,6 +32,13 @@ private function _checkKeys($keys, $values)
2832
}
2933
}
3034
}
35+
/** Return the user dao */
36+
private function _getUser($args)
37+
{
38+
$componentLoader = new MIDAS_ComponentLoader();
39+
$authComponent = $componentLoader->loadComponent('Authentication', 'api');
40+
return $authComponent->getUser($args, $this->userSession->Dao);
41+
}
3142

3243

3344
/**
@@ -64,6 +75,122 @@ public function testconfig($params)
6475

6576

6677

78+
/**
79+
* Add a condorDag entry to the specified batchmake task
80+
* @param token Authentication token
81+
* @param batchmaketaskid The id of the batchmake task for this dag
82+
* @param dagfilename The filename of the dagfile
83+
* @param outfilename The filename of the dag processing output
84+
* @return The created CondorDagDao.
85+
*/
86+
public function addCondorDag($params)
87+
{
88+
$keys = array("batchmaketaskid" => "batchmaketaskid", "dagfilename" => "dagfilename", "outfilename" => "outfilename");
89+
$this->_checkKeys($keys, $params);
90+
91+
$userDao = $this->_getUser($params);
92+
if(!$userDao)
93+
{
94+
throw new Exception('Anonymous users may not add condor dags', MIDAS_BATCHMAKE_INVALID_POLICY);
95+
}
96+
97+
$modelLoader = new MIDAS_ModelLoader();
98+
$taskModel = $modelLoader->loadModel('Task', 'batchmake');
99+
$condorDagModel = $modelLoader->loadModel('CondorDag', 'batchmake');
100+
101+
$batchmakeTaskId = $params["batchmaketaskid"];
102+
$dagFilename = $params["dagfilename"];
103+
$outFilename = $params["outfilename"];
104+
105+
$taskDao = $taskModel->load($batchmakeTaskId);
106+
if(empty($taskDao))
107+
{
108+
throw new Exception('Invalid batchmaketaskid specified', MIDAS_BATCHMAKE_INVALID_PARAMETER);
109+
}
110+
if($taskDao->getUserId() !== $userDao->getUserId())
111+
{
112+
throw new Exception('You are not the owner of this batchmake task', MIDAS_BATCHMAKE_INVALID_POLICY);
113+
}
114+
115+
$data = array("batchmake_task_id" => $batchmakeTaskId, "dag_filename" => $dagFilename, "out_filename" => $outFilename);
116+
117+
$condorDagDao = $condorDagModel->initDao("CondorDag", $data, 'batchmake');
118+
$condorDagModel->save($condorDagDao);
119+
return $condorDagDao;
120+
}
121+
122+
123+
/**
124+
* Add a condorJob entry to the specified batchmake task
125+
* @param token Authentication token
126+
* @param batchmaketaskid The id of the batchmake task for this dag
127+
* @param outputfilename The filename of the output file for the job
128+
* @param errorfilename The filename of the error file for the job
129+
* @param logfilename The filename of the log file for the job
130+
* @param postfilename The filename of the post script log file for the job
131+
* @return The created CondorJobDao.
132+
*/
133+
public function addCondorJob($params)
134+
{
135+
$keys = array("batchmaketaskid" => "batchmaketaskid",
136+
"jobdefinitionfilename" => "jobdefinitionfilename",
137+
"outputfilename" => "outputfilename",
138+
"errorfilename" => "errorfilename",
139+
"logfilename" => "logfilename",
140+
"postfilename" => "postfilename");
141+
$this->_checkKeys($keys, $params);
142+
143+
$userDao = $this->_getUser($params);
144+
if(!$userDao)
145+
{
146+
throw new Exception('Anonymous users may not add condor jobs', MIDAS_BATCHMAKE_INVALID_POLICY);
147+
}
148+
149+
$modelLoader = new MIDAS_ModelLoader();
150+
$taskModel = $modelLoader->loadModel('Task', 'batchmake');
151+
$condorDagModel = $modelLoader->loadModel('CondorDag', 'batchmake');
152+
$condorJobModel = $modelLoader->loadModel('CondorJob', 'batchmake');
153+
154+
$batchmakeTaskId = $params["batchmaketaskid"];
155+
$jobdefinitionFilename = $params["jobdefinitionfilename"];
156+
$outputFilename = $params["outputfilename"];
157+
$errorFilename = $params["errorfilename"];
158+
$logFilename = $params["logfilename"];
159+
$postFilename = $params["postfilename"];
160+
161+
$taskDao = $taskModel->load($batchmakeTaskId);
162+
if(empty($taskDao))
163+
{
164+
throw new Exception('Invalid batchmaketaskid specified', MIDAS_BATCHMAKE_INVALID_PARAMETER);
165+
}
166+
if($taskDao->getUserId() !== $userDao->getUserId())
167+
{
168+
throw new Exception('You are not the owner of this batchmake task', MIDAS_BATCHMAKE_INVALID_POLICY);
169+
}
170+
171+
// get the dag via the batchmaketask
172+
$condorDags = $condorDagModel->findBy("batchmake_task_id", $batchmakeTaskId);
173+
if(empty($condorDags) || sizeof($condorDags) === 0)
174+
{
175+
throw new Exception('There is no condor dag for this batchmaketaskid', MIDAS_BATCHMAKE_INVALID_PARAMETER);
176+
}
177+
// take the first if there are multiple
178+
$condorDagDao = $condorDags[0];
179+
$condorDagId = $condorDagDao->getCondorDagId();
180+
181+
$data = array("condor_dag_id" => $condorDagId,
182+
"jobdefinition_filename" => $jobdefinitionFilename,
183+
"output_filename" => $outputFilename,
184+
"error_filename" => $errorFilename,
185+
"log_filename" => $logFilename,
186+
"post_filename" => $postFilename);
187+
188+
$condorJobDao = $condorJobModel->initDao("CondorJob", $data, 'batchmake');
189+
$condorJobModel->save($condorJobDao);
190+
return $condorJobDao;
191+
}
192+
193+
67194

68195
} // end class
69196

modules/batchmake/database/mysql/0.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS batchmake_itemmetric (
1515
CREATE TABLE IF NOT EXISTS condor_dag (
1616
condor_dag_id bigint(20) NOT NULL AUTO_INCREMENT,
1717
batchmake_task_id bigint(20) NOT NULL,
18-
log_filename text NOT NULL,
18+
out_filename text NOT NULL,
1919
PRIMARY KEY (condor_dag_id)
2020
) DEFAULT CHARSET=utf8;
2121

modules/batchmake/database/pgsql/0.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CREATE TABLE batchmake_itemmetric (
1414
CREATE TABLE condor_dag (
1515
condor_dag_id serial PRIMARY KEY,
1616
batchmake_task_id bigint NOT NULL,
17-
log_filename text NOT NULL
17+
out_filename text NOT NULL
1818
);
1919

2020
CREATE TABLE condor_job (
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
include_once BASE_PATH . '/modules/batchmake/constant/module.php';
13+
/** CondorDag Base class */
14+
class Batchmake_CondorDagModelBase extends Batchmake_AppModel {
15+
16+
17+
18+
19+
/** constructor */
20+
public function __construct()
21+
{
22+
parent::__construct();
23+
$this->_name = 'condor_dag';
24+
$this->_daoName = 'CondorDagDao';
25+
$this->_key = 'condor_dag_id';
26+
27+
$this->_mainData = array(
28+
'condor_dag_id' => array('type' => MIDAS_DATA),
29+
'batchmake_task_id' => array('type' => MIDAS_DATA),
30+
'out_filename' => array('type' => MIDAS_DATA),
31+
'dag_filename' => array('type' => MIDAS_DATA));
32+
$this->initialize(); // required
33+
}
34+
35+
36+
37+
38+
39+
40+
} // end class Batchmake_CondorDagModelBase
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
include_once BASE_PATH . '/modules/batchmake/constant/module.php';
13+
/** CondorJob Base class */
14+
class Batchmake_CondorJobModelBase extends Batchmake_AppModel {
15+
16+
17+
18+
19+
/** constructor */
20+
public function __construct()
21+
{
22+
parent::__construct();
23+
$this->_name = 'condor_job';
24+
$this->_daoName = 'CondorJobDao';
25+
$this->_key = 'condor_job_id';
26+
27+
$this->_mainData = array(
28+
'condor_job_id' => array('type' => MIDAS_DATA),
29+
'condor_dag_id' => array('type' => MIDAS_DATA),
30+
'jobdefinition_filename' => array('type' => MIDAS_DATA),
31+
'output_filename' => array('type' => MIDAS_DATA),
32+
'error_filename' => array('type' => MIDAS_DATA),
33+
'log_filename' => array('type' => MIDAS_DATA),
34+
'post_filename' => array('type' => MIDAS_DATA));
35+
$this->initialize(); // required
36+
}
37+
38+
39+
40+
41+
} // end class Batchmake_CondorJobModelBase

modules/batchmake/models/base/TaskModelBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct()
2424

2525
$this->_mainData = array(
2626
'batchmake_task_id' => array('type' => MIDAS_DATA),
27-
'user_id' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'User', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
27+
'user_id' => array('type' => MIDAS_DATA),
2828
'work_dir' => array('type' => MIDAS_DATA));
2929
$this->initialize(); // required
3030
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
/** CondorDagDao class */
13+
class Batchmake_CondorDagDao extends AppDao {
14+
15+
public $_model = 'CondorDag';
16+
public $_module = 'batchmake';
17+
18+
}
19+
20+
?>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
/** CondorJobDao class */
13+
class Batchmake_CondorJobDao extends AppDao {
14+
15+
public $_model = 'CondorJob';
16+
public $_module = 'batchmake';
17+
18+
}
19+
20+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
require_once BASE_PATH . '/modules/batchmake/models/base/CondorDagModelBase.php';
13+
14+
/** CondorDag class */
15+
class Batchmake_CondorDagModel extends Batchmake_CondorDagModelBase {
16+
17+
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
require_once BASE_PATH . '/modules/batchmake/models/base/CondorJobModelBase.php';
13+
14+
/** CondorJob class */
15+
class Batchmake_CondorJobModel extends Batchmake_CondorJobModelBase {
16+
17+
18+
}

0 commit comments

Comments
 (0)