10
10
PURPOSE. See the above copyright notices for more information.
11
11
=========================================================================*/
12
12
13
+ // Web API error codes
14
+ define ('MIDAS_BATCHMAKE_INVALID_POLICY ' , -151 );
15
+ define ('MIDAS_BATCHMAKE_INVALID_PARAMETER ' , -150 );
16
+
13
17
/** Component for api methods */
14
18
class Batchmake_ApiComponent extends AppComponent
15
19
{
@@ -28,6 +32,13 @@ private function _checkKeys($keys, $values)
28
32
}
29
33
}
30
34
}
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
+ }
31
42
32
43
33
44
/**
@@ -64,6 +75,122 @@ public function testconfig($params)
64
75
65
76
66
77
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
+
67
194
68
195
} // end class
69
196
0 commit comments