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