1 | /* $Id$ */ |
---|
2 | /* |
---|
3 | * FedStage DRMAA for PBS Pro |
---|
4 | * Copyright (C) 2006-2009 FedStage Systems |
---|
5 | * |
---|
6 | * This program is free software: you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation, either version 3 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifdef HAVE_CONFIG_H |
---|
21 | # include <config.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <unistd.h> |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | #include <pbs_ifl.h> |
---|
28 | #include <pbs_error.h> |
---|
29 | |
---|
30 | #include <drmaa_utils/conf.h> |
---|
31 | #include <drmaa_utils/drmaa.h> |
---|
32 | #include <drmaa_utils/drmaa_util.h> |
---|
33 | #include <drmaa_utils/datetime.h> |
---|
34 | #include <drmaa_utils/iter.h> |
---|
35 | #include <drmaa_utils/template.h> |
---|
36 | #include <pbs_drmaa/pbs_attrib.h> |
---|
37 | #include <pbs_drmaa/session.h> |
---|
38 | #include <pbs_drmaa/submit.h> |
---|
39 | #include <pbs_drmaa/util.h> |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | #ifndef lint |
---|
44 | static char rcsid[] |
---|
45 | # ifdef __GNUC__ |
---|
46 | __attribute__ ((unused)) |
---|
47 | # endif |
---|
48 | = "$Id$"; |
---|
49 | #endif |
---|
50 | |
---|
51 | static void |
---|
52 | pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self ); |
---|
53 | |
---|
54 | static char * |
---|
55 | pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self ); |
---|
56 | |
---|
57 | static void |
---|
58 | pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self ); |
---|
59 | |
---|
60 | |
---|
61 | static void |
---|
62 | pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *pbs_attr, |
---|
63 | char *value, unsigned placeholders ); |
---|
64 | |
---|
65 | static void pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self ); |
---|
66 | static void pbsdrmaa_submit_apply_job_script( pbsdrmaa_submit_t *self ); |
---|
67 | static void pbsdrmaa_submit_apply_job_state( pbsdrmaa_submit_t *self ); |
---|
68 | static void pbsdrmaa_submit_apply_job_files( pbsdrmaa_submit_t *self ); |
---|
69 | static void pbsdrmaa_submit_apply_file_staging( pbsdrmaa_submit_t *self ); |
---|
70 | static void pbsdrmaa_submit_apply_job_resources( pbsdrmaa_submit_t *self ); |
---|
71 | static void pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self ); |
---|
72 | static void pbsdrmaa_submit_apply_email_notification( pbsdrmaa_submit_t *self ); |
---|
73 | static void pbsdrmaa_submit_apply_job_category( pbsdrmaa_submit_t *self ); |
---|
74 | |
---|
75 | |
---|
76 | pbsdrmaa_submit_t * |
---|
77 | pbsdrmaa_submit_new( fsd_drmaa_session_t *session, |
---|
78 | const fsd_template_t *job_template, int bulk_idx ) |
---|
79 | { |
---|
80 | pbsdrmaa_submit_t *volatile self = NULL; |
---|
81 | TRY |
---|
82 | { |
---|
83 | fsd_malloc( self, pbsdrmaa_submit_t ); |
---|
84 | self->session = session; |
---|
85 | self->job_template = job_template; |
---|
86 | self->script_filename = NULL; |
---|
87 | self->destination_queue = NULL; |
---|
88 | self->pbs_job_attributes = NULL; |
---|
89 | self->expand_ph = NULL; |
---|
90 | self->destroy = pbsdrmaa_submit_destroy; |
---|
91 | self->submit = pbsdrmaa_submit_submit; |
---|
92 | self->eval = pbsdrmaa_submit_eval; |
---|
93 | self->set = pbsdrmaa_submit_set; |
---|
94 | self->apply_defaults = pbsdrmaa_submit_apply_defaults; |
---|
95 | self->apply_job_category = pbsdrmaa_submit_apply_job_category; |
---|
96 | self->apply_job_script = pbsdrmaa_submit_apply_job_script; |
---|
97 | self->apply_job_state = pbsdrmaa_submit_apply_job_state; |
---|
98 | self->apply_job_files = pbsdrmaa_submit_apply_job_files; |
---|
99 | self->apply_file_staging = pbsdrmaa_submit_apply_file_staging; |
---|
100 | self->apply_job_resources = pbsdrmaa_submit_apply_job_resources; |
---|
101 | self->apply_job_environment = pbsdrmaa_submit_apply_job_environment; |
---|
102 | self->apply_email_notification = pbsdrmaa_submit_apply_email_notification; |
---|
103 | self->apply_native_specification = |
---|
104 | pbsdrmaa_submit_apply_native_specification; |
---|
105 | |
---|
106 | self->pbs_job_attributes = pbsdrmaa_pbs_template_new(); |
---|
107 | self->expand_ph = fsd_expand_drmaa_ph_new( NULL, NULL, |
---|
108 | (bulk_idx >= 0) ? fsd_asprintf("%d", bulk_idx) : NULL ); |
---|
109 | } |
---|
110 | EXCEPT_DEFAULT |
---|
111 | { |
---|
112 | if( self ) |
---|
113 | self->destroy( self ); |
---|
114 | } |
---|
115 | END_TRY |
---|
116 | return self; |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | void |
---|
121 | pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self ) |
---|
122 | { |
---|
123 | if( self->script_filename ) |
---|
124 | { |
---|
125 | unlink( self->script_filename ); |
---|
126 | fsd_free( self->script_filename ); |
---|
127 | } |
---|
128 | if( self->pbs_job_attributes ) |
---|
129 | self->pbs_job_attributes->destroy( self->pbs_job_attributes ); |
---|
130 | if( self->expand_ph ) |
---|
131 | self->expand_ph->destroy( self->expand_ph ); |
---|
132 | fsd_free( self->destination_queue ); |
---|
133 | fsd_free( self ); |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | char * |
---|
138 | pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self ) |
---|
139 | { |
---|
140 | volatile bool conn_lock = false; |
---|
141 | struct attrl *volatile pbs_attr = NULL; |
---|
142 | char *volatile job_id = NULL; |
---|
143 | TRY |
---|
144 | { |
---|
145 | const fsd_template_t *pbs_tmpl = self->pbs_job_attributes; |
---|
146 | unsigned i; |
---|
147 | |
---|
148 | for( i = 0; i < PBSDRMAA_N_PBS_ATTRIBUTES; i++ ) |
---|
149 | { |
---|
150 | const char *name = pbs_tmpl->by_code( pbs_tmpl, i )->name; |
---|
151 | if( name && name[0] != '!' && pbs_tmpl->get_attr( pbs_tmpl, name ) ) |
---|
152 | { |
---|
153 | const char *value; |
---|
154 | |
---|
155 | value = pbs_tmpl->get_attr( pbs_tmpl, name ); |
---|
156 | pbs_attr = pbsdrmaa_add_attr( pbs_attr, name, value ); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex ); |
---|
161 | retry: |
---|
162 | job_id = pbs_submit( ((pbsdrmaa_session_t*)self->session)->pbs_conn, |
---|
163 | (struct attropl*)pbs_attr, self->script_filename, |
---|
164 | self->destination_queue, NULL ); |
---|
165 | |
---|
166 | fsd_log_info(("pbs_submit(%s, %s) =%s", self->script_filename, self->destination_queue, job_id)); |
---|
167 | |
---|
168 | if( job_id == NULL ) |
---|
169 | { |
---|
170 | if (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED) |
---|
171 | { |
---|
172 | pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self->session; |
---|
173 | if (pbsself->pbs_conn >= 0 ) |
---|
174 | pbs_disconnect( pbsself->pbs_conn ); |
---|
175 | sleep(1); |
---|
176 | pbsself->pbs_conn = pbs_connect( pbsself->super.contact ); |
---|
177 | if( pbsself->pbs_conn < 0 ) |
---|
178 | pbsdrmaa_exc_raise_pbs( "pbs_connect" ); |
---|
179 | else |
---|
180 | goto retry; |
---|
181 | } |
---|
182 | else |
---|
183 | { |
---|
184 | pbsdrmaa_exc_raise_pbs( "pbs_submit" ); |
---|
185 | } |
---|
186 | } |
---|
187 | conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex ); |
---|
188 | } |
---|
189 | EXCEPT_DEFAULT |
---|
190 | { |
---|
191 | fsd_free( job_id ); |
---|
192 | fsd_exc_reraise(); |
---|
193 | } |
---|
194 | FINALLY |
---|
195 | { |
---|
196 | if( conn_lock ) |
---|
197 | conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex ); |
---|
198 | if( pbs_attr ) |
---|
199 | pbsdrmaa_free_attrl( pbs_attr ); |
---|
200 | } |
---|
201 | END_TRY |
---|
202 | return job_id; |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | void |
---|
207 | pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self ) |
---|
208 | { |
---|
209 | self->apply_defaults( self ); |
---|
210 | self->apply_job_category( self ); |
---|
211 | self->apply_job_script( self ); |
---|
212 | self->apply_job_state( self ); |
---|
213 | self->apply_job_files( self ); |
---|
214 | self->apply_file_staging( self ); |
---|
215 | self->apply_job_resources( self ); |
---|
216 | self->apply_job_environment( self ); |
---|
217 | self->apply_email_notification( self ); |
---|
218 | self->apply_native_specification( self, NULL ); |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | void |
---|
223 | pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *name, |
---|
224 | char *value, unsigned placeholders ) |
---|
225 | { |
---|
226 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
227 | TRY |
---|
228 | { |
---|
229 | if( placeholders ) |
---|
230 | value = self->expand_ph->expand( |
---|
231 | self->expand_ph, value, placeholders ); |
---|
232 | pbs_attr->set_attr( pbs_attr, name, value ); |
---|
233 | } |
---|
234 | FINALLY |
---|
235 | { |
---|
236 | fsd_free( value ); |
---|
237 | } |
---|
238 | END_TRY |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | void |
---|
243 | pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self ) |
---|
244 | { |
---|
245 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
246 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_CHECKPOINT, "u" ); |
---|
247 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_KEEP_FILES, "n" ); |
---|
248 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_PRIORITY, "0" ); |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | void |
---|
253 | pbsdrmaa_submit_apply_job_script( pbsdrmaa_submit_t *self ) |
---|
254 | { |
---|
255 | const fsd_template_t *jt = self->job_template; |
---|
256 | /* fsd_template_t *pbs_attr = self->pbs_job_attributes; */ |
---|
257 | fsd_expand_drmaa_ph_t *expand = self->expand_ph; |
---|
258 | char *script = NULL; |
---|
259 | size_t script_len; |
---|
260 | const char *executable; |
---|
261 | const char *wd; |
---|
262 | const char *const *argv; |
---|
263 | const char *input_path; |
---|
264 | const char *const *i; |
---|
265 | |
---|
266 | executable = jt->get_attr( jt, DRMAA_REMOTE_COMMAND ); |
---|
267 | wd = jt->get_attr( jt, DRMAA_WD ); |
---|
268 | argv = jt->get_v_attr( jt, DRMAA_V_ARGV ); |
---|
269 | input_path = jt->get_attr( jt, DRMAA_INPUT_PATH ); |
---|
270 | |
---|
271 | if( wd ) |
---|
272 | { |
---|
273 | char *cwd = NULL; |
---|
274 | cwd = expand->expand( expand, fsd_strdup(wd), |
---|
275 | FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR ); |
---|
276 | expand->set( expand, FSD_DRMAA_PH_WD, cwd ); |
---|
277 | } |
---|
278 | |
---|
279 | if( executable == NULL ) |
---|
280 | fsd_exc_raise_code( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE ); |
---|
281 | |
---|
282 | if( input_path != NULL ) |
---|
283 | { |
---|
284 | if( input_path[0] == ':' ) |
---|
285 | input_path++; |
---|
286 | } |
---|
287 | |
---|
288 | { /* compute script length */ |
---|
289 | script_len = 0; |
---|
290 | if( wd != NULL ) |
---|
291 | script_len += strlen("cd ") + strlen(wd) + strlen("; "); |
---|
292 | script_len += strlen("exec ") + strlen(executable); |
---|
293 | if( argv != NULL ) |
---|
294 | for( i = argv; *i != NULL; i++ ) |
---|
295 | script_len += 3+strlen(*i); |
---|
296 | if( input_path != NULL ) |
---|
297 | script_len += strlen(" <") + strlen(input_path); |
---|
298 | } |
---|
299 | |
---|
300 | fsd_calloc( script, script_len+1, char ); |
---|
301 | |
---|
302 | { |
---|
303 | char *s; |
---|
304 | s = script; |
---|
305 | if( wd != NULL ) |
---|
306 | s += sprintf( s, "cd %s; ", wd ); |
---|
307 | s += sprintf( s, "exec %s", executable ); |
---|
308 | if( argv != NULL ) |
---|
309 | for( i = argv; *i != NULL; i++ ) |
---|
310 | s += sprintf( s, " '%s'", *i ); |
---|
311 | if( input_path != NULL ) |
---|
312 | s += sprintf( s, " <%s", input_path ); |
---|
313 | fsd_assert( s == script+script_len ); |
---|
314 | } |
---|
315 | |
---|
316 | script = expand->expand( expand, script, |
---|
317 | FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR ); |
---|
318 | |
---|
319 | /* pbs_attr->set_attr( pbs_attr, "!script", script ); */ |
---|
320 | |
---|
321 | self->script_filename = pbsdrmaa_write_tmpfile( script, strlen(script) ); |
---|
322 | fsd_free( script ); |
---|
323 | } |
---|
324 | |
---|
325 | |
---|
326 | void |
---|
327 | pbsdrmaa_submit_apply_job_state( pbsdrmaa_submit_t *self ) |
---|
328 | { |
---|
329 | const fsd_template_t *jt = self->job_template; |
---|
330 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
331 | const char *job_name = NULL; |
---|
332 | const char *submit_state = NULL; |
---|
333 | const char *drmaa_start_time = NULL; |
---|
334 | |
---|
335 | job_name = jt->get_attr( jt, DRMAA_JOB_NAME ); |
---|
336 | submit_state = jt->get_attr( jt, DRMAA_JS_STATE ); |
---|
337 | drmaa_start_time = jt->get_attr( jt, DRMAA_START_TIME ); |
---|
338 | |
---|
339 | if( job_name != NULL ) |
---|
340 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOB_NAME, job_name ); |
---|
341 | |
---|
342 | if( submit_state != NULL ) |
---|
343 | { |
---|
344 | const char *hold_types; |
---|
345 | if( !strcmp(submit_state, DRMAA_SUBMISSION_STATE_ACTIVE) ) |
---|
346 | hold_types = "n"; |
---|
347 | else if( !strcmp(submit_state, DRMAA_SUBMISSION_STATE_HOLD) ) |
---|
348 | hold_types = "u"; |
---|
349 | else |
---|
350 | fsd_exc_raise_fmt( FSD_ERRNO_INVALID_VALUE, |
---|
351 | "invalid value of %s attribute (%s|%s)", |
---|
352 | DRMAA_JS_STATE, DRMAA_SUBMISSION_STATE_ACTIVE, |
---|
353 | DRMAA_SUBMISSION_STATE_HOLD ); |
---|
354 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_HOLD_TYPES, hold_types ); |
---|
355 | } |
---|
356 | |
---|
357 | if( drmaa_start_time != NULL ) |
---|
358 | { |
---|
359 | time_t start_time; |
---|
360 | char pbs_start_time[20]; |
---|
361 | struct tm start_time_tm; |
---|
362 | start_time = fsd_datetime_parse( drmaa_start_time ); |
---|
363 | localtime_r( &start_time, &start_time_tm ); |
---|
364 | sprintf( pbs_start_time, "%04d%02d%02d%02d%02d.%02d", |
---|
365 | start_time_tm.tm_year + 1900, |
---|
366 | start_time_tm.tm_mon + 1, |
---|
367 | start_time_tm.tm_mday, |
---|
368 | start_time_tm.tm_hour, |
---|
369 | start_time_tm.tm_min, |
---|
370 | start_time_tm.tm_sec |
---|
371 | ); |
---|
372 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_EXECUTION_TIME, pbs_start_time ); |
---|
373 | } |
---|
374 | } |
---|
375 | |
---|
376 | |
---|
377 | void |
---|
378 | pbsdrmaa_submit_apply_job_files( pbsdrmaa_submit_t *self ) |
---|
379 | { |
---|
380 | const fsd_template_t *jt = self->job_template; |
---|
381 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
382 | const char *join_files; |
---|
383 | bool b_join_files; |
---|
384 | int i; |
---|
385 | |
---|
386 | for( i = 0; i < 2; i++ ) |
---|
387 | { |
---|
388 | const char *drmaa_name; |
---|
389 | const char *pbs_name; |
---|
390 | const char *path; |
---|
391 | |
---|
392 | if( i == 0 ) |
---|
393 | { |
---|
394 | drmaa_name = DRMAA_OUTPUT_PATH; |
---|
395 | pbs_name = PBSDRMAA_OUTPUT_PATH; |
---|
396 | } |
---|
397 | else |
---|
398 | { |
---|
399 | drmaa_name = DRMAA_ERROR_PATH; |
---|
400 | pbs_name = PBSDRMAA_ERROR_PATH; |
---|
401 | } |
---|
402 | |
---|
403 | path = jt->get_attr( jt, drmaa_name ); |
---|
404 | if( path != NULL ) |
---|
405 | { |
---|
406 | if( path[0] == ':' ) |
---|
407 | path++; |
---|
408 | self->set(self, pbs_name, fsd_strdup(path), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | join_files = jt->get_attr( jt, DRMAA_JOIN_FILES ); |
---|
413 | b_join_files = join_files != NULL && !strcmp(join_files,"1"); |
---|
414 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOIN_FILES, (b_join_files ? "y" : "n") ); |
---|
415 | } |
---|
416 | |
---|
417 | |
---|
418 | void |
---|
419 | pbsdrmaa_submit_apply_file_staging( pbsdrmaa_submit_t *self ) |
---|
420 | { |
---|
421 | /* TODO */ |
---|
422 | } |
---|
423 | |
---|
424 | |
---|
425 | void |
---|
426 | pbsdrmaa_submit_apply_job_resources( pbsdrmaa_submit_t *self ) |
---|
427 | { |
---|
428 | const fsd_template_t *jt = self->job_template; |
---|
429 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
430 | const char *cpu_time_limit = NULL; |
---|
431 | const char *walltime_limit = NULL; |
---|
432 | |
---|
433 | cpu_time_limit = jt->get_attr( jt, DRMAA_DURATION_HLIMIT ); |
---|
434 | walltime_limit = jt->get_attr( jt, DRMAA_WCT_HLIMIT ); |
---|
435 | if( cpu_time_limit ) |
---|
436 | { |
---|
437 | pbs_attr->set_attr( pbs_attr, "Resource_List.pcput", cpu_time_limit ); |
---|
438 | pbs_attr->set_attr( pbs_attr, "Resource_List.cput", cpu_time_limit ); |
---|
439 | } |
---|
440 | if( walltime_limit ) |
---|
441 | pbs_attr->set_attr( pbs_attr, "Resource_List.walltime", walltime_limit ); |
---|
442 | } |
---|
443 | |
---|
444 | void |
---|
445 | pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self ) |
---|
446 | { |
---|
447 | const fsd_template_t *jt = self->job_template; |
---|
448 | const char *const *env_v; |
---|
449 | const char *jt_wd; |
---|
450 | char *wd; |
---|
451 | char *env_c = NULL; |
---|
452 | int ii = 0, len = 0; |
---|
453 | |
---|
454 | env_v = jt->get_v_attr( jt, DRMAA_V_ENV); |
---|
455 | jt_wd = jt->get_attr( jt, DRMAA_WD ); |
---|
456 | |
---|
457 | if (!jt_wd) |
---|
458 | { |
---|
459 | wd = fsd_getcwd(); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | wd = fsd_strdup(jt_wd); |
---|
464 | } |
---|
465 | |
---|
466 | if (env_v) |
---|
467 | { |
---|
468 | ii = 0; |
---|
469 | while (env_v[ii]) { |
---|
470 | len += strlen(env_v[ii]) + 1; |
---|
471 | ii++; |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | len+= strlen("PBS_O_WORKDIR=") + strlen(wd); |
---|
476 | |
---|
477 | fsd_calloc(env_c, len + 1, char); |
---|
478 | env_c[0] = '\0'; |
---|
479 | |
---|
480 | if (env_v) |
---|
481 | { |
---|
482 | ii = 0; |
---|
483 | while (env_v[ii]) { |
---|
484 | strcat(env_c, env_v[ii]); |
---|
485 | strcat(env_c, ","); |
---|
486 | ii++; |
---|
487 | } |
---|
488 | |
---|
489 | } |
---|
490 | |
---|
491 | strcat(env_c, "PBS_O_WORKDIR="); |
---|
492 | strcat(env_c, wd); |
---|
493 | |
---|
494 | self->pbs_job_attributes->set_attr(self->pbs_job_attributes, "Variable_List", env_c); |
---|
495 | |
---|
496 | fsd_free(env_c); |
---|
497 | fsd_free(wd); |
---|
498 | } |
---|
499 | |
---|
500 | |
---|
501 | void |
---|
502 | pbsdrmaa_submit_apply_email_notification( pbsdrmaa_submit_t *self ) |
---|
503 | { |
---|
504 | /* TODO */ |
---|
505 | } |
---|
506 | |
---|
507 | |
---|
508 | void |
---|
509 | pbsdrmaa_submit_apply_job_category( pbsdrmaa_submit_t *self ) |
---|
510 | { |
---|
511 | const char *job_category = NULL; |
---|
512 | const char *category_spec = NULL; |
---|
513 | fsd_conf_option_t *value = NULL; |
---|
514 | |
---|
515 | job_category = self->job_template->get_attr( |
---|
516 | self->job_template, DRMAA_JOB_CATEGORY ); |
---|
517 | if( job_category == NULL || job_category[0] == '\0' ) |
---|
518 | job_category = "default"; |
---|
519 | value = fsd_conf_dict_get( self->session->job_categories, |
---|
520 | job_category ); |
---|
521 | if( value != NULL && value->type == FSD_CONF_STRING ) |
---|
522 | category_spec = value->val.string; |
---|
523 | if( category_spec != NULL ) |
---|
524 | self->apply_native_specification( self, category_spec ); |
---|
525 | } |
---|
526 | |
---|
527 | static void parse_resources(fsd_template_t *pbs_attr,const char *resources) |
---|
528 | { |
---|
529 | char * volatile name = NULL; |
---|
530 | char *arg = NULL; |
---|
531 | char *value = NULL; |
---|
532 | char *ctxt = NULL; |
---|
533 | char * volatile resources_copy = fsd_strdup(resources); |
---|
534 | |
---|
535 | TRY |
---|
536 | { |
---|
537 | for (arg = strtok_r(resources_copy, ",", &ctxt); arg; arg = strtok_r(NULL, ",",&ctxt) ) |
---|
538 | { |
---|
539 | char *psep = strchr(arg, '='); |
---|
540 | |
---|
541 | if (psep) |
---|
542 | { |
---|
543 | *psep = '\0'; |
---|
544 | name = fsd_asprintf("Resource_List.%s", arg); |
---|
545 | value = ++psep; |
---|
546 | pbs_attr->set_attr( pbs_attr, name , value ); |
---|
547 | fsd_free(name); |
---|
548 | name = NULL; |
---|
549 | } |
---|
550 | else |
---|
551 | { |
---|
552 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Invalid native specification: %s (Invalid resource specification: %s)", resources, arg); |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | FINALLY |
---|
557 | { |
---|
558 | fsd_free(name); |
---|
559 | fsd_free(resources_copy); |
---|
560 | } |
---|
561 | END_TRY |
---|
562 | } |
---|
563 | |
---|
564 | static void parse_additional_attr(fsd_template_t *pbs_attr,const char *add_attr) |
---|
565 | { |
---|
566 | char * volatile name = NULL; |
---|
567 | char *arg = NULL; |
---|
568 | char *value = NULL; |
---|
569 | char *ctxt = NULL, *ctxt2 = NULL; |
---|
570 | char * volatile add_attr_copy = fsd_strdup(add_attr); |
---|
571 | |
---|
572 | TRY |
---|
573 | { |
---|
574 | for (arg = strtok_r(add_attr_copy, ";", &ctxt); arg; arg = strtok_r(NULL, ";",&ctxt) ) |
---|
575 | { |
---|
576 | name = fsd_strdup(strtok_r(arg, "=", &ctxt2)); |
---|
577 | value = strtok_r(NULL, "=", &ctxt2); |
---|
578 | pbs_attr->set_attr( pbs_attr, name , value ); |
---|
579 | fsd_free(name); |
---|
580 | name = NULL; |
---|
581 | } |
---|
582 | } |
---|
583 | FINALLY |
---|
584 | { |
---|
585 | fsd_free(name); |
---|
586 | fsd_free(add_attr_copy); |
---|
587 | } |
---|
588 | END_TRY |
---|
589 | } |
---|
590 | |
---|
591 | |
---|
592 | void |
---|
593 | pbsdrmaa_submit_apply_native_specification( pbsdrmaa_submit_t *self, |
---|
594 | const char *native_specification ) |
---|
595 | { |
---|
596 | fsd_log_enter(( "({native_specification=%s})", native_specification )); |
---|
597 | |
---|
598 | if( native_specification == NULL ) |
---|
599 | native_specification = self->job_template->get_attr( |
---|
600 | self->job_template, DRMAA_NATIVE_SPECIFICATION ); |
---|
601 | if( native_specification == NULL ) |
---|
602 | return; |
---|
603 | |
---|
604 | { |
---|
605 | fsd_iter_t * volatile args_list = fsd_iter_new(NULL, 0); |
---|
606 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
607 | char *arg = NULL; |
---|
608 | volatile char * native_spec_copy = fsd_strdup(native_specification); |
---|
609 | char * ctxt = NULL; |
---|
610 | int opt = 0; |
---|
611 | |
---|
612 | TRY |
---|
613 | { |
---|
614 | for (arg = strtok_r(native_spec_copy, " \t", &ctxt); arg; arg = strtok_r(NULL, " \t",&ctxt) ) { |
---|
615 | if (!opt) |
---|
616 | { |
---|
617 | if ( (arg[0] != '-') || (strlen(arg) != 2) ) |
---|
618 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
619 | "Invalid native specification: -o(ption) expected (arg=%s native=%s).", |
---|
620 | arg, native_specification); |
---|
621 | |
---|
622 | opt = arg[1]; |
---|
623 | |
---|
624 | /* handle NO-arg options */ |
---|
625 | |
---|
626 | switch (opt) { |
---|
627 | case 'h' : |
---|
628 | pbs_attr->set_attr( pbs_attr, "Hold_Types" , "u" ); |
---|
629 | break; |
---|
630 | default : |
---|
631 | continue; /*no NO-ARG option */ |
---|
632 | } |
---|
633 | |
---|
634 | opt = 0; |
---|
635 | } |
---|
636 | else |
---|
637 | { |
---|
638 | switch (opt) { |
---|
639 | |
---|
640 | case 'W' : |
---|
641 | parse_additional_attr(pbs_attr, arg); |
---|
642 | break; |
---|
643 | case 'N' : |
---|
644 | pbs_attr->set_attr( pbs_attr, "Job_Name" , arg ); |
---|
645 | break; |
---|
646 | case 'o' : |
---|
647 | pbs_attr->set_attr( pbs_attr, "Output_Path" , arg ); |
---|
648 | break; |
---|
649 | case 'e' : |
---|
650 | pbs_attr->set_attr( pbs_attr, "Error_Path" , arg ); |
---|
651 | break; |
---|
652 | case 'j' : |
---|
653 | pbs_attr->set_attr( pbs_attr, "Join_Path" , arg ); |
---|
654 | break; |
---|
655 | case 'm' : |
---|
656 | pbs_attr->set_attr( pbs_attr, "Mail_Points" , arg ); |
---|
657 | break; |
---|
658 | case 'a' : |
---|
659 | pbs_attr->set_attr( pbs_attr, "Execution_Time" , arg ); |
---|
660 | break; |
---|
661 | case 'A' : |
---|
662 | pbs_attr->set_attr( pbs_attr, "Account_Name" , arg ); |
---|
663 | break; |
---|
664 | case 'c' : |
---|
665 | pbs_attr->set_attr( pbs_attr, "Checkpoint" , arg ); |
---|
666 | break; |
---|
667 | case 'k' : |
---|
668 | pbs_attr->set_attr( pbs_attr, "Keep_Files" , arg ); |
---|
669 | break; |
---|
670 | case 'p' : |
---|
671 | pbs_attr->set_attr( pbs_attr, "Priority" , arg ); |
---|
672 | break; |
---|
673 | case 'q' : |
---|
674 | self->destination_queue = fsd_strdup( arg ); |
---|
675 | fsd_log_debug(("self->destination_queue = %s", self->destination_queue)); |
---|
676 | break; |
---|
677 | case 'r' : |
---|
678 | pbs_attr->set_attr( pbs_attr, "Rerunable" , arg ); |
---|
679 | break; |
---|
680 | case 'S' : |
---|
681 | pbs_attr->set_attr( pbs_attr, "Shell_Path_List" , arg ); |
---|
682 | break; |
---|
683 | case 'u' : |
---|
684 | pbs_attr->set_attr( pbs_attr, "User_List" , arg ); |
---|
685 | break; |
---|
686 | case 'v' : |
---|
687 | pbs_attr->set_attr( pbs_attr, "Variable_List" , arg ); |
---|
688 | break; |
---|
689 | case 'M' : |
---|
690 | pbs_attr->set_attr( pbs_attr, "Mail_Users" , arg ); |
---|
691 | break; |
---|
692 | case 'l' : |
---|
693 | parse_resources(pbs_attr, arg); |
---|
694 | break; |
---|
695 | default : |
---|
696 | |
---|
697 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
698 | "Invalid native specification: %s (Unsupported option: -%c)", |
---|
699 | native_specification, opt); |
---|
700 | } |
---|
701 | opt = 0; |
---|
702 | } |
---|
703 | } |
---|
704 | |
---|
705 | if (opt) /* option without optarg */ |
---|
706 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
707 | "Invalid native specification: %s", |
---|
708 | native_specification); |
---|
709 | |
---|
710 | } |
---|
711 | FINALLY |
---|
712 | { |
---|
713 | #ifndef PBS_PROFESSIONAL |
---|
714 | pbs_attr->set_attr( pbs_attr, "submit_args", native_specification); |
---|
715 | #endif |
---|
716 | args_list->destroy(args_list); |
---|
717 | fsd_free(native_spec_copy); |
---|
718 | } |
---|
719 | END_TRY |
---|
720 | } |
---|
721 | } |
---|
722 | |
---|