1 | /* $Id$ */ |
---|
2 | /* |
---|
3 | * PSNC DRMAA for SLURM |
---|
4 | * Copyright (C) 2011 Poznan Supercomputing and Networking Center |
---|
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 | #include <string.h> |
---|
20 | #include <stdlib.h> |
---|
21 | #include <unistd.h> |
---|
22 | #include <signal.h> |
---|
23 | |
---|
24 | #include <drmaa_utils/common.h> |
---|
25 | #include <drmaa_utils/conf.h> |
---|
26 | #include <drmaa_utils/datetime.h> |
---|
27 | #include <drmaa_utils/drmaa.h> |
---|
28 | #include <drmaa_utils/drmaa_util.h> |
---|
29 | #include <drmaa_utils/environ.h> |
---|
30 | #include <drmaa_utils/template.h> |
---|
31 | |
---|
32 | #include <slurm_drmaa/job.h> |
---|
33 | #include <slurm_drmaa/session.h> |
---|
34 | #include <slurm_drmaa/util.h> |
---|
35 | |
---|
36 | #include <slurm/slurm.h> |
---|
37 | #include <stdint.h> |
---|
38 | |
---|
39 | static void |
---|
40 | slurmdrmaa_job_control( fsd_job_t *self, int action ) |
---|
41 | { |
---|
42 | slurmdrmaa_job_t *slurm_self = (slurmdrmaa_job_t*)self; |
---|
43 | job_desc_msg_t job_desc; |
---|
44 | |
---|
45 | fsd_log_enter(( "({job_id=%s}, action=%d)", self->job_id, action )); |
---|
46 | |
---|
47 | fsd_mutex_lock( &self->session->drm_connection_mutex ); |
---|
48 | TRY |
---|
49 | { |
---|
50 | switch( action ) |
---|
51 | { |
---|
52 | case DRMAA_CONTROL_SUSPEND: |
---|
53 | if(slurm_suspend(fsd_atoi(self->job_id)) == -1) { |
---|
54 | fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR,"slurm_suspend error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id); |
---|
55 | } |
---|
56 | slurm_self->user_suspended = true; |
---|
57 | break; |
---|
58 | case DRMAA_CONTROL_HOLD: |
---|
59 | /* change priority to 0*/ |
---|
60 | slurm_init_job_desc_msg(&job_desc); |
---|
61 | slurm_self->old_priority = job_desc.priority; |
---|
62 | job_desc.job_id = atoi(self->job_id); |
---|
63 | job_desc.priority = 0; |
---|
64 | job_desc.alloc_sid = 0; |
---|
65 | if(slurm_update_job(&job_desc) == -1) { |
---|
66 | fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR,"slurm_update_job error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id); |
---|
67 | } |
---|
68 | break; |
---|
69 | case DRMAA_CONTROL_RESUME: |
---|
70 | if(slurm_resume(fsd_atoi(self->job_id)) == -1) { |
---|
71 | fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR,"slurm_resume error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id); |
---|
72 | } |
---|
73 | slurm_self->user_suspended = false; |
---|
74 | break; |
---|
75 | case DRMAA_CONTROL_RELEASE: |
---|
76 | /* change priority back*/ |
---|
77 | slurm_init_job_desc_msg(&job_desc); |
---|
78 | job_desc.priority = 1; |
---|
79 | job_desc.job_id = atoi(self->job_id); |
---|
80 | if(slurm_update_job(&job_desc) == -1) { |
---|
81 | fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR,"slurm_update_job error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id); |
---|
82 | } |
---|
83 | break; |
---|
84 | case DRMAA_CONTROL_TERMINATE: |
---|
85 | if(slurm_kill_job(fsd_atoi(self->job_id),SIGKILL,0) == -1) { |
---|
86 | fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR,"slurm_terminate_job error: %s,job_id: %s",slurm_strerror(slurm_get_errno()),self->job_id); |
---|
87 | } |
---|
88 | break; |
---|
89 | default: |
---|
90 | fsd_exc_raise_fmt( |
---|
91 | FSD_ERRNO_INVALID_ARGUMENT, |
---|
92 | "job::control: unknown action %d", action ); |
---|
93 | } |
---|
94 | |
---|
95 | fsd_log_debug(("job::control: successful")); |
---|
96 | } |
---|
97 | FINALLY |
---|
98 | { |
---|
99 | fsd_mutex_unlock( &self->session->drm_connection_mutex ); |
---|
100 | } |
---|
101 | END_TRY |
---|
102 | |
---|
103 | fsd_log_return(( "" )); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | static void |
---|
108 | slurmdrmaa_job_update_status( fsd_job_t *self ) |
---|
109 | { |
---|
110 | job_info_msg_t *job_info = NULL; |
---|
111 | slurmdrmaa_job_t * slurm_self = (slurmdrmaa_job_t *) self; |
---|
112 | fsd_log_enter(( "({job_id=%s})", self->job_id )); |
---|
113 | |
---|
114 | fsd_mutex_lock( &self->session->drm_connection_mutex ); |
---|
115 | TRY |
---|
116 | { |
---|
117 | if ( slurm_load_job( &job_info, fsd_atoi(self->job_id), SHOW_ALL) ) { |
---|
118 | int _slurm_errno = slurm_get_errno(); |
---|
119 | |
---|
120 | if (_slurm_errno == ESLURM_INVALID_JOB_ID) { |
---|
121 | self->on_missing(self); |
---|
122 | } else { |
---|
123 | fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"slurm_load_jobs error: %s,job_id: %s", slurm_strerror(slurm_get_errno()), self->job_id); |
---|
124 | } |
---|
125 | } |
---|
126 | if (job_info) { |
---|
127 | fsd_log_debug(("state = %d, state_reason = %d", job_info->job_array[0].job_state, job_info->job_array[0].state_reason)); |
---|
128 | |
---|
129 | switch(job_info->job_array[0].job_state & JOB_STATE_BASE) |
---|
130 | { |
---|
131 | |
---|
132 | case JOB_PENDING: |
---|
133 | switch(job_info->job_array[0].state_reason) |
---|
134 | { |
---|
135 | case WAIT_HELD_USER: /* job is held by user */ |
---|
136 | fsd_log_debug(("interpreting as DRMAA_PS_USER_ON_HOLD")); |
---|
137 | self->state = DRMAA_PS_USER_ON_HOLD; |
---|
138 | break; |
---|
139 | case WAIT_HELD: /* job is held by administrator */ |
---|
140 | fsd_log_debug(("interpreting as DRMAA_PS_SYSTEM_ON_HOLD")); |
---|
141 | self->state = DRMAA_PS_SYSTEM_ON_HOLD; |
---|
142 | break; |
---|
143 | default: |
---|
144 | fsd_log_debug(("interpreting as DRMAA_PS_QUEUED_ACTIVE")); |
---|
145 | self->state = DRMAA_PS_QUEUED_ACTIVE; |
---|
146 | } |
---|
147 | break; |
---|
148 | case JOB_RUNNING: |
---|
149 | fsd_log_debug(("interpreting as DRMAA_PS_RUNNING")); |
---|
150 | self->state = DRMAA_PS_RUNNING; |
---|
151 | break; |
---|
152 | case JOB_SUSPENDED: |
---|
153 | if(slurm_self->user_suspended == true) { |
---|
154 | fsd_log_debug(("interpreting as DRMAA_PS_USER_SUSPENDED")); |
---|
155 | self->state = DRMAA_PS_USER_SUSPENDED; |
---|
156 | } else { |
---|
157 | fsd_log_debug(("interpreting as DRMAA_PS_SYSTEM_SUSPENDED")); |
---|
158 | self->state = DRMAA_PS_SYSTEM_SUSPENDED; |
---|
159 | } |
---|
160 | break; |
---|
161 | case JOB_COMPLETE: |
---|
162 | fsd_log_debug(("interpreting as DRMAA_PS_DONE")); |
---|
163 | self->state = DRMAA_PS_DONE; |
---|
164 | self->exit_status = job_info->job_array[0].exit_code; |
---|
165 | fsd_log_debug(("exit_status = %d -> %d",self->exit_status, WEXITSTATUS(self->exit_status))); |
---|
166 | break; |
---|
167 | case JOB_CANCELLED: |
---|
168 | fsd_log_debug(("interpreting as DRMAA_PS_FAILED (aborted)")); |
---|
169 | self->state = DRMAA_PS_FAILED; |
---|
170 | self->exit_status = -1; |
---|
171 | case JOB_FAILED: |
---|
172 | case JOB_TIMEOUT: |
---|
173 | case JOB_NODE_FAIL: |
---|
174 | case JOB_PREEMPTED: |
---|
175 | fsd_log_debug(("interpreting as DRMAA_PS_FAILED")); |
---|
176 | self->state = DRMAA_PS_FAILED; |
---|
177 | self->exit_status = job_info->job_array[0].exit_code; |
---|
178 | fsd_log_debug(("exit_status = %d -> %d",self->exit_status, WEXITSTATUS(self->exit_status))); |
---|
179 | break; |
---|
180 | default: /*unknown state */ |
---|
181 | fsd_log_error(("Unknown job state: %d. Please send bug report: http://apps.man.poznan.pl/trac/slurm-drmaa", job_info->job_array[0].job_state)); |
---|
182 | } |
---|
183 | |
---|
184 | if (job_info->job_array[0].job_state & JOB_STATE_FLAGS & JOB_COMPLETING) { |
---|
185 | fsd_log_debug(("Epilog completing")); |
---|
186 | } |
---|
187 | |
---|
188 | if (job_info->job_array[0].job_state & JOB_STATE_FLAGS & JOB_CONFIGURING) { |
---|
189 | fsd_log_debug(("Nodes booting")); |
---|
190 | } |
---|
191 | |
---|
192 | if (self->exit_status == -1) /* input,output,error path failure etc*/ |
---|
193 | self->state = DRMAA_PS_FAILED; |
---|
194 | |
---|
195 | self->last_update_time = time(NULL); |
---|
196 | |
---|
197 | if( self->state >= DRMAA_PS_DONE ) { |
---|
198 | fsd_log_debug(("exit_status = %d, WEXITSTATUS(exit_status) = %d", self->exit_status, WEXITSTATUS(self->exit_status))); |
---|
199 | fsd_cond_broadcast( &self->status_cond ); |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | FINALLY |
---|
204 | { |
---|
205 | if(job_info != NULL) |
---|
206 | slurm_free_job_info_msg (job_info); |
---|
207 | |
---|
208 | fsd_mutex_unlock( &self->session->drm_connection_mutex ); |
---|
209 | } |
---|
210 | END_TRY |
---|
211 | |
---|
212 | fsd_log_return(( "" )); |
---|
213 | } |
---|
214 | |
---|
215 | static void |
---|
216 | slurmdrmaa_job_on_missing( fsd_job_t *self ) |
---|
217 | { |
---|
218 | |
---|
219 | fsd_log_enter(( "({job_id=%s})", self->job_id )); |
---|
220 | fsd_log_warning(( "Job %s missing from DRM queue", self->job_id )); |
---|
221 | |
---|
222 | fsd_log_info(( "job_on_missing: last job_ps: %s (0x%02x)", drmaa_job_ps_to_str(self->state), self->state)); |
---|
223 | |
---|
224 | if( self->state >= DRMAA_PS_RUNNING ) { /*if the job ever entered running state assume finished */ |
---|
225 | self->state = DRMAA_PS_DONE; |
---|
226 | self->exit_status = 0; |
---|
227 | } |
---|
228 | else { |
---|
229 | self->state = DRMAA_PS_FAILED; /* otherwise failed */ |
---|
230 | self->exit_status = -1; |
---|
231 | } |
---|
232 | |
---|
233 | fsd_log_info(("job_on_missing evaluation result: state=%d exit_status=%d", self->state, self->exit_status)); |
---|
234 | |
---|
235 | fsd_cond_broadcast( &self->status_cond); |
---|
236 | fsd_cond_broadcast( &self->session->wait_condition ); |
---|
237 | |
---|
238 | fsd_log_return(( "; job_ps=%s, exit_status=%d", drmaa_job_ps_to_str(self->state), self->exit_status )); |
---|
239 | } |
---|
240 | |
---|
241 | fsd_job_t * |
---|
242 | slurmdrmaa_job_new( char *job_id ) |
---|
243 | { |
---|
244 | slurmdrmaa_job_t *self = NULL; |
---|
245 | self = (slurmdrmaa_job_t*)fsd_job_new( job_id ); |
---|
246 | |
---|
247 | fsd_realloc( self, 1, slurmdrmaa_job_t ); |
---|
248 | |
---|
249 | self->super.control = slurmdrmaa_job_control; |
---|
250 | self->super.update_status = slurmdrmaa_job_update_status; |
---|
251 | self->super.on_missing = slurmdrmaa_job_on_missing; |
---|
252 | self->old_priority = UINT32_MAX; |
---|
253 | self->user_suspended = true; |
---|
254 | return (fsd_job_t*)self; |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | void |
---|
259 | slurmdrmaa_job_create_req( |
---|
260 | fsd_drmaa_session_t *session, |
---|
261 | const fsd_template_t *jt, |
---|
262 | fsd_environ_t **envp, |
---|
263 | job_desc_msg_t * job_desc) |
---|
264 | { |
---|
265 | fsd_expand_drmaa_ph_t *volatile expand = NULL; |
---|
266 | |
---|
267 | TRY |
---|
268 | { |
---|
269 | expand = fsd_expand_drmaa_ph_new( NULL, NULL, fsd_strdup("%a") ); |
---|
270 | slurmdrmaa_job_create( session, jt, envp, expand, job_desc ); |
---|
271 | } |
---|
272 | EXCEPT_DEFAULT |
---|
273 | { |
---|
274 | fsd_exc_reraise(); |
---|
275 | } |
---|
276 | FINALLY |
---|
277 | { |
---|
278 | if( expand ) |
---|
279 | expand->destroy( expand ); |
---|
280 | } |
---|
281 | END_TRY |
---|
282 | } |
---|
283 | |
---|
284 | static char * |
---|
285 | internal_map_file( fsd_expand_drmaa_ph_t *expand, const char *path, |
---|
286 | bool *host_given, const char *name ) |
---|
287 | { |
---|
288 | const char *p; |
---|
289 | |
---|
290 | for( p = path; *p != ':'; p++ ) |
---|
291 | if( *p == '\0' ) |
---|
292 | fsd_exc_raise_fmt( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT, |
---|
293 | "invalid format of drmaa_%s_path: missing colon", name ); |
---|
294 | if( host_given ) |
---|
295 | *host_given = ( p != path ); |
---|
296 | |
---|
297 | p++; |
---|
298 | |
---|
299 | return expand->expand( expand, fsd_strdup(p), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR ); |
---|
300 | } |
---|
301 | |
---|
302 | void |
---|
303 | slurmdrmaa_job_create( |
---|
304 | fsd_drmaa_session_t *session, |
---|
305 | const fsd_template_t *jt, |
---|
306 | fsd_environ_t **envp, |
---|
307 | fsd_expand_drmaa_ph_t *expand, |
---|
308 | job_desc_msg_t * job_desc |
---|
309 | ) |
---|
310 | { |
---|
311 | const char *input_path_orig = NULL; |
---|
312 | const char *output_path_orig = NULL; |
---|
313 | const char *error_path_orig = NULL; |
---|
314 | char *volatile input_path = NULL; |
---|
315 | char *volatile output_path = NULL; |
---|
316 | char *volatile error_path = NULL; |
---|
317 | bool input_host = false; |
---|
318 | bool output_host = false; |
---|
319 | bool error_host = false; |
---|
320 | bool join_files = false; |
---|
321 | const char *value; |
---|
322 | const char *const *vector; |
---|
323 | const char *job_category = "default"; |
---|
324 | |
---|
325 | job_desc->user_id = getuid(); |
---|
326 | job_desc->group_id = getgid(); |
---|
327 | |
---|
328 | job_desc->env_size = 0; |
---|
329 | |
---|
330 | /* job name */ |
---|
331 | value = jt->get_attr( jt, DRMAA_JOB_NAME ); |
---|
332 | if( value ) |
---|
333 | { |
---|
334 | job_desc->name = fsd_strdup(value); |
---|
335 | fsd_log_debug(("# job_name = %s",job_desc->name)); |
---|
336 | } |
---|
337 | |
---|
338 | /* job state at submit */ |
---|
339 | value = jt->get_attr( jt, DRMAA_JS_STATE ); |
---|
340 | if( value ) |
---|
341 | { |
---|
342 | if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_ACTIVE ) ) |
---|
343 | {} |
---|
344 | else if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_HOLD ) ) |
---|
345 | { |
---|
346 | job_desc->priority = 0; |
---|
347 | fsd_log_debug(("# hold = user")); |
---|
348 | } |
---|
349 | else |
---|
350 | { |
---|
351 | fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_js_state attribute" ); |
---|
352 | } |
---|
353 | } |
---|
354 | |
---|
355 | TRY |
---|
356 | { |
---|
357 | const char *command = NULL; |
---|
358 | char *command_expanded = NULL; |
---|
359 | char *temp_script_old = NULL; |
---|
360 | char *temp_script = ""; |
---|
361 | const char *const *i; |
---|
362 | int j; |
---|
363 | |
---|
364 | /* remote command */ |
---|
365 | command = jt->get_attr( jt, DRMAA_REMOTE_COMMAND ); |
---|
366 | if( command == NULL ) |
---|
367 | fsd_exc_raise_msg( |
---|
368 | FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, |
---|
369 | "drmaa_remote_command not set for job template" |
---|
370 | ); |
---|
371 | |
---|
372 | command_expanded = expand->expand( expand, fsd_strdup(command), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD ); |
---|
373 | |
---|
374 | temp_script = fsd_asprintf("#!/bin/bash\n%s",command_expanded); |
---|
375 | fsd_free(command_expanded); |
---|
376 | |
---|
377 | /* arguments list */ |
---|
378 | vector = jt->get_v_attr( jt, DRMAA_V_ARGV ); |
---|
379 | |
---|
380 | if( vector ) |
---|
381 | { |
---|
382 | for( i = vector, j = 2; *i; i++, j++ ) |
---|
383 | { |
---|
384 | char *arg_expanded = expand->expand( expand, fsd_strdup(*i), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD ); |
---|
385 | |
---|
386 | temp_script_old = fsd_strdup(temp_script); |
---|
387 | |
---|
388 | if (strcmp(temp_script, "") != 0) { |
---|
389 | fsd_free(temp_script); |
---|
390 | } |
---|
391 | /* add too script */ |
---|
392 | temp_script = fsd_asprintf("%s '%s'", temp_script_old, arg_expanded); |
---|
393 | fsd_free(temp_script_old); |
---|
394 | fsd_free(arg_expanded); |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | job_desc->script = fsd_asprintf("%s\n", temp_script); |
---|
399 | fsd_log_debug(("# Script:\n%s", job_desc->script)); |
---|
400 | fsd_free(temp_script); |
---|
401 | } |
---|
402 | END_TRY |
---|
403 | |
---|
404 | |
---|
405 | /* start time */ |
---|
406 | value = jt->get_attr( jt, DRMAA_START_TIME ); |
---|
407 | if( value ) |
---|
408 | { |
---|
409 | job_desc->begin_time = fsd_datetime_parse( value ); |
---|
410 | fsd_log_debug(( "\n drmaa_start_time: %s -> %ld", value, (long)job_desc->begin_time)); |
---|
411 | } |
---|
412 | |
---|
413 | /* propagate all environment variables from submission host */ |
---|
414 | { |
---|
415 | extern char **environ; |
---|
416 | char **i; |
---|
417 | unsigned j = 0; |
---|
418 | |
---|
419 | for ( i = environ; *i; i++) { |
---|
420 | job_desc->env_size++; |
---|
421 | } |
---|
422 | |
---|
423 | fsd_log_debug(("environ env_size = %d",job_desc->env_size)); |
---|
424 | fsd_calloc(job_desc->environment, job_desc->env_size+1, char *); |
---|
425 | |
---|
426 | for ( i = environ; *i; i++,j++ ) { |
---|
427 | job_desc->environment[j] = fsd_strdup(*i); |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | /* environment */ |
---|
432 | |
---|
433 | vector = jt->get_v_attr( jt, DRMAA_V_ENV ); |
---|
434 | if( vector ) |
---|
435 | { |
---|
436 | const char *const *i; |
---|
437 | unsigned j = 0; |
---|
438 | unsigned env_offset = job_desc->env_size; |
---|
439 | |
---|
440 | for( i = vector; *i; i++ ) |
---|
441 | { |
---|
442 | job_desc->env_size++; |
---|
443 | } |
---|
444 | fsd_log_debug(("jt env_size = %d",job_desc->env_size)); |
---|
445 | |
---|
446 | fsd_log_debug(("# environment =")); |
---|
447 | fsd_realloc(job_desc->environment, job_desc->env_size+1, char *); |
---|
448 | |
---|
449 | for( i = vector; *i; i++,j++ ) |
---|
450 | { |
---|
451 | job_desc->environment[j + env_offset] = fsd_strdup(*i); |
---|
452 | fsd_log_debug((" %s", job_desc->environment[j+ env_offset])); |
---|
453 | } |
---|
454 | } |
---|
455 | |
---|
456 | /* wall clock time hard limit */ |
---|
457 | value = jt->get_attr( jt, DRMAA_WCT_HLIMIT ); |
---|
458 | if (value) |
---|
459 | { |
---|
460 | job_desc->time_limit = slurmdrmaa_datetime_parse( value ); |
---|
461 | fsd_log_debug(("# wct_hlimit = %s -> %ld",value, (long int)slurmdrmaa_datetime_parse( value ))); |
---|
462 | } |
---|
463 | |
---|
464 | |
---|
465 | /*expand->set(expand, FSD_DRMAA_PH_INCR,fsd_asprintf("%d", n_job));*/ /* set current value */ |
---|
466 | /* TODO: test drmaa_ph_incr */ |
---|
467 | /* job working directory */ |
---|
468 | value = jt->get_attr( jt, DRMAA_WD ); |
---|
469 | if( value ) |
---|
470 | { |
---|
471 | char *cwd_expanded = expand->expand( expand, fsd_strdup(value), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR ); |
---|
472 | |
---|
473 | expand->set( expand, FSD_DRMAA_PH_WD, fsd_strdup(cwd_expanded)); |
---|
474 | |
---|
475 | fsd_log_debug(("# work_dir = %s",cwd_expanded)); |
---|
476 | job_desc->work_dir = fsd_strdup(cwd_expanded); |
---|
477 | fsd_free(cwd_expanded); |
---|
478 | } |
---|
479 | else |
---|
480 | { |
---|
481 | char cwdbuf[4096] = ""; |
---|
482 | |
---|
483 | if ((getcwd(cwdbuf, 4095)) == NULL) { |
---|
484 | char errbuf[256] = "InternalError"; |
---|
485 | (void)strerror_r(errno, errbuf, 256); /*on error the default message would be returned */ |
---|
486 | fsd_log_error(("getcwd failed: %s", errbuf)); |
---|
487 | job_desc->work_dir = fsd_strdup("."); |
---|
488 | } else { |
---|
489 | job_desc->work_dir = fsd_strdup(cwdbuf); |
---|
490 | } |
---|
491 | |
---|
492 | fsd_log_debug(("work_dir(default:CWD) %s", job_desc->work_dir)); |
---|
493 | } |
---|
494 | |
---|
495 | TRY |
---|
496 | { |
---|
497 | /* input path */ |
---|
498 | input_path_orig = jt->get_attr( jt, DRMAA_INPUT_PATH ); |
---|
499 | if( input_path_orig ) |
---|
500 | { |
---|
501 | input_path = internal_map_file( expand, input_path_orig, &input_host,"input" ); |
---|
502 | fsd_log_debug(( "\n drmaa_input_path: %s -> %s", input_path_orig, input_path )); |
---|
503 | } |
---|
504 | |
---|
505 | /* output path */ |
---|
506 | output_path_orig = jt->get_attr( jt, DRMAA_OUTPUT_PATH ); |
---|
507 | if( output_path_orig ) |
---|
508 | { |
---|
509 | output_path = internal_map_file( expand, output_path_orig, &output_host,"output" ); |
---|
510 | fsd_log_debug(( "\n drmaa_output_path: %s -> %s", output_path_orig, output_path )); |
---|
511 | } |
---|
512 | |
---|
513 | /* error path */ |
---|
514 | error_path_orig = jt->get_attr( jt, DRMAA_ERROR_PATH ); |
---|
515 | if( error_path_orig ) |
---|
516 | { |
---|
517 | error_path = internal_map_file( expand, error_path_orig, &error_host,"error" ); |
---|
518 | fsd_log_debug(( "\n drmaa_error_path: %s -> %s", error_path_orig, error_path )); |
---|
519 | } |
---|
520 | |
---|
521 | /* join files */ |
---|
522 | value = jt->get_attr( jt, DRMAA_JOIN_FILES ); |
---|
523 | if( value ) |
---|
524 | { |
---|
525 | if( (value[0] == 'y' || value[0] == 'Y') && value[1] == '\0' ) |
---|
526 | join_files = true; |
---|
527 | else if( (value[0] == 'n' || value[0] == 'N') && value[1] == '\0' ) |
---|
528 | join_files = false; |
---|
529 | else |
---|
530 | fsd_exc_raise_msg( |
---|
531 | FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
532 | "invalid value of drmaa_join_files attribute" ); |
---|
533 | } |
---|
534 | |
---|
535 | if( join_files ) |
---|
536 | { |
---|
537 | if( output_path == NULL ) |
---|
538 | fsd_exc_raise_msg(FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, "drmaa_join_files is set and output file is not given" ); |
---|
539 | if( error_path!=NULL && 0 != strcmp( output_path, error_path ) ) |
---|
540 | fsd_log_warning(( "Error file was given but will be ignored since drmaa_join_files was set." )); |
---|
541 | |
---|
542 | if (error_path) |
---|
543 | fsd_free(error_path); |
---|
544 | |
---|
545 | error_path = fsd_strdup(output_path); |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | if( error_path == NULL && output_path ) |
---|
550 | error_path = fsd_strdup( "/dev/null" ); |
---|
551 | if( output_path == NULL && error_path ) |
---|
552 | output_path = fsd_strdup( "/dev/null" ); |
---|
553 | } |
---|
554 | |
---|
555 | |
---|
556 | /* email addresses to send notifications */ |
---|
557 | vector = jt->get_v_attr( jt, DRMAA_V_EMAIL ); |
---|
558 | if( vector && vector[0] ) |
---|
559 | { |
---|
560 | /* only to one email address message may be send */ |
---|
561 | job_desc->mail_user = fsd_strdup(vector[0]); |
---|
562 | job_desc->mail_type = MAIL_JOB_BEGIN | MAIL_JOB_END | MAIL_JOB_FAIL; |
---|
563 | fsd_log_debug(("# mail_user = %s\n",vector[0])); |
---|
564 | fsd_log_debug(("# mail_type = %o\n",job_desc->mail_type)); |
---|
565 | if( vector[1] != NULL ) |
---|
566 | { |
---|
567 | fsd_log_error(( "SLURM only supports one e-mail notification address" )); |
---|
568 | fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"SLURM only supports one e-mail notification address"); |
---|
569 | } |
---|
570 | } |
---|
571 | |
---|
572 | /* block email */ |
---|
573 | value = jt->get_attr( jt, DRMAA_BLOCK_EMAIL ); |
---|
574 | if( value ) |
---|
575 | { |
---|
576 | bool block; |
---|
577 | if( strcmp(value, "0") == 0 ) |
---|
578 | { |
---|
579 | block = true; |
---|
580 | fsd_log_debug(("# block_email = true")); |
---|
581 | fsd_log_debug(("# mail_user delated")); |
---|
582 | fsd_free(job_desc->mail_user); |
---|
583 | job_desc->mail_user = NULL; |
---|
584 | } |
---|
585 | else if( strcmp(value, "1") == 0 ) |
---|
586 | block = false; |
---|
587 | else |
---|
588 | fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"invalid value of drmaa_block_email attribute" ); |
---|
589 | |
---|
590 | if( block && output_path == NULL ) |
---|
591 | { |
---|
592 | fsd_log_debug(( "output path not set and we want to block e-mail, set to /dev/null" )); |
---|
593 | output_path = fsd_strdup( "/dev/null" ); |
---|
594 | } |
---|
595 | } |
---|
596 | |
---|
597 | if( input_path ) |
---|
598 | { |
---|
599 | job_desc->std_in = fsd_strdup(input_path); |
---|
600 | fsd_log_debug(("# input = %s", input_path)); |
---|
601 | } |
---|
602 | |
---|
603 | if( output_path ) |
---|
604 | { |
---|
605 | job_desc->std_out = fsd_strdup(output_path); |
---|
606 | fsd_log_debug(("# output = %s", output_path)); |
---|
607 | } |
---|
608 | |
---|
609 | if( error_path ) |
---|
610 | { |
---|
611 | job_desc->std_err = fsd_strdup(error_path); |
---|
612 | fsd_log_debug(("# error = %s", error_path)); |
---|
613 | } |
---|
614 | } |
---|
615 | FINALLY |
---|
616 | { |
---|
617 | fsd_free( input_path ); |
---|
618 | fsd_free( output_path ); |
---|
619 | fsd_free( error_path ); |
---|
620 | input_path = NULL; |
---|
621 | output_path = NULL; |
---|
622 | error_path = NULL; |
---|
623 | } |
---|
624 | END_TRY |
---|
625 | |
---|
626 | |
---|
627 | /* job category */ |
---|
628 | value = jt->get_attr( jt, DRMAA_JOB_CATEGORY ); |
---|
629 | if( value ) |
---|
630 | job_category = value; |
---|
631 | |
---|
632 | { |
---|
633 | fsd_conf_option_t *category_value = NULL; |
---|
634 | category_value = fsd_conf_dict_get( session->job_categories, job_category ); |
---|
635 | |
---|
636 | if( category_value != NULL ) |
---|
637 | { |
---|
638 | if( category_value->type != FSD_CONF_STRING ) |
---|
639 | fsd_exc_raise_fmt( |
---|
640 | FSD_ERRNO_INTERNAL_ERROR, |
---|
641 | "configuration error: job category should be string" |
---|
642 | ); |
---|
643 | |
---|
644 | fsd_log_debug(("# Job category %s : %s\n",value,category_value->val.string)); |
---|
645 | slurmdrmaa_parse_native(job_desc,category_value->val.string); |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | if( value != NULL ) |
---|
650 | fsd_exc_raise_fmt( |
---|
651 | FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
652 | "invalid job category: %s", job_category |
---|
653 | ); |
---|
654 | } |
---|
655 | } |
---|
656 | |
---|
657 | /* set defaults for constraints - ref: slurm.h */ |
---|
658 | fsd_log_debug(("# Setting defaults for tasks and processors" )); |
---|
659 | job_desc->num_tasks = 1; |
---|
660 | job_desc->min_cpus = 0; |
---|
661 | job_desc->cpus_per_task = 0; |
---|
662 | job_desc->pn_min_cpus = 0; |
---|
663 | |
---|
664 | /* native specification */ |
---|
665 | value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION ); |
---|
666 | if( value ) |
---|
667 | { |
---|
668 | fsd_log_debug(("# Native specification: %s\n", value)); |
---|
669 | slurmdrmaa_parse_native(job_desc, value); |
---|
670 | } |
---|
671 | |
---|
672 | } |
---|
673 | |
---|
674 | |
---|