void fsd_job_destroy( fsd_job_t *self ) { fsd_log_enter(( "(%p={job_id=%s})", (void*)self, self->job_id )); fsd_cond_destroy( &self->status_cond ); fsd_cond_destroy( &self->destroy_cond ); fsd_mutex_destroy( &self->mutex ); fsd_free( self->job_id ); fsd_free( self ); fsd_log_return(( "" )); }
static void fsd_iter_destroy( fsd_iter_t *self ) { int i; if( self->_own_list && self->_list ) { for( i = 0; i < self->_length; i++ ) fsd_free( self->_list[i] ); fsd_free( self->_list ); } fsd_free( self ); }
void fsd_job_destroy( fsd_job_t *self ) { fsd_log_enter(( "(%p={job_id=%s})", (void*)self, self->job_id )); fsd_cond_destroy( &self->status_cond ); fsd_cond_destroy( &self->destroy_cond ); fsd_mutex_destroy( &self->mutex ); fsd_free( self->job_id ); fsd_free( self->execution_hosts ); fsd_free( self->queue ); fsd_free( self->project ); fsd_free( self ); fsd_log_return(( "" )); }
static void fsd_template_set_attr( fsd_template_t *self, const char *name, const char *value ) { const fsd_attribute_t *attr = NULL; fsd_log_enter(("(%s=%s)", name, value)); if( name == NULL ) fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); attr = self->by_name( self, name ); if( attr == NULL || attr->is_vector ) fsd_exc_raise_fmt( FSD_ERRNO_INVALID_ARGUMENT, "invalid scalar attribute name: %s", name ); if( value != NULL ) { if (strlen (value) > DRMAA_MAX_ATTR_LEN) fsd_exc_raise_fmt( FSD_ERRNO_INVALID_ARGUMENT, "Argument length exceeds max size: %d > %d", (int)strlen(value), DRMAA_MAX_ATTR_LEN ); if( self->attributes[ attr->code ] != NULL ) { fsd_free(self->attributes[ attr->code ]); } self->attributes[ attr->code ] = fsd_strdup( value ); } else self->attributes[ attr->code ] = NULL; }
static fsd_iter_t * fsd_iter_new_impl( char **list, int length, bool own ) { fsd_iter_t *volatile self = NULL; TRY { fsd_malloc( self, fsd_iter_t ); self->next = fsd_iter_next; self->reset = fsd_iter_reset; self->len = fsd_iter_len; self->append = fsd_iter_append; self->destroy = fsd_iter_destroy; self->_list = list; self->_position = 0; if( list == NULL ) self->_length = 0; else if( length >= 0 ) self->_length = length; else { char **i; int cnt = 0; for( i = self->_list; *i != NULL; i++ ) cnt++; self->_length = cnt; } self->_own_list = own; } EXCEPT_DEFAULT { if( own && list ) { if( length >= 0 ) { int i; for( i = 0; i < length; i++ ) fsd_free( list[i] ); fsd_free( list ); } else fsd_free_vector( list ); } fsd_exc_reraise(); } END_TRY return self; }
void fsd_drmaa_session_destroy_nowait( fsd_drmaa_session_t *self ) { fsd_log_enter(( "" )); fsd_conf_dict_destroy( self->configuration ); fsd_free( self->contact ); if( self->jobs ) self->jobs->destroy( self->jobs ); fsd_mutex_destroy( &self->mutex ); fsd_cond_destroy( &self->wait_condition ); fsd_cond_destroy( &self->destroy_condition ); fsd_mutex_destroy( &self->drm_connection_mutex ); fsd_free( self ); fsd_log_return(( "" )); }
void fsd_job_set_destroy( fsd_job_set_t *self ) { unsigned i; fsd_job_t *j; fsd_log_enter(( "()" )); for( i = 0; i < self->tab_size; i++ ) for( j = self->tab[i]; j != NULL; ) { fsd_job_t *job = j; j = j->next; fsd_mutex_lock( &job->mutex ); job->release( job ); } fsd_free( self->tab ); fsd_free( self ); fsd_log_return(( "" )); }
static void fsd_template_destroy( fsd_template_t *self ) { unsigned i; for( i = 0; i < self->n_attributes; i++ ) if( self->attributes[i] != NULL ) { const fsd_attribute_t *attr; attr = self->by_code( self, i ); if( attr ) { if( attr->is_vector ) fsd_free_vector( self->attributes[i] ); else fsd_free( self->attributes[i] ); } } fsd_free( self->attributes ); fsd_free( self ); }
static char * lsfdrmaa_job_quote_command( const char *const *argv ) { char *volatile result = NULL; TRY { size_t size = 0; const char *const *i; const char *j; char *s; for( i = argv; *i; i++ ) { if( i != argv ) size++; size += 2; for( j = *i; *j; j++ ) switch( *j ) { case '"': case '$': case '\\': case '`': size ++; default: size ++; break; } } fsd_calloc( result, size+1, char ); s = result; for( i = argv; *i; i++ ) { if( i != argv ) *s++ = ' '; *s++ = '"'; for( j = *i; *j; j++ ) switch( *j ) { case '"': case '$': case '\\': case '`': *s++ = '\\'; default: *s++ = *j; break; } *s++ = '"'; } *s++ = '\0'; } EXCEPT_DEFAULT { fsd_free( result ); fsd_exc_reraise(); } END_TRY return result; }
fsd_job_set_t * fsd_job_set_new(void) { fsd_job_set_t *volatile self = NULL; const size_t initial_size = 1024; fsd_log_enter(( "()" )); TRY { fsd_malloc( self, fsd_job_set_t ); self->destroy = fsd_job_set_destroy; self->add = fsd_job_set_add; self->remove = fsd_job_set_remove; self->get = fsd_job_set_get; self->empty = fsd_job_set_empty; self->find_terminated = fsd_job_set_find_terminated; self->get_all_job_ids = fsd_job_set_get_all_job_ids; self->signal_all = fsd_job_set_signal_all; self->tab = NULL; self->n_jobs = 0; fsd_calloc( self->tab, initial_size, fsd_job_t* ); self->tab_size = initial_size; self->tab_mask = self->tab_size - 1; fsd_mutex_init( &self->mutex ); } EXCEPT_DEFAULT { if( self ) { fsd_free( self->tab ); fsd_free( self ); } fsd_exc_reraise(); } END_TRY fsd_log_return(( " =%p", (void*)self )); return self; }
fsd_job_t * fsd_job_new( char *job_id ) { fsd_job_t *volatile self = NULL; fsd_log_enter(( "(%s)", job_id )); TRY { fsd_malloc( self, fsd_job_t ); self->release = fsd_job_release; self->destroy = fsd_job_destroy; self->control = fsd_job_control; self->update_status = fsd_job_update_status; self->get_termination_status = fsd_job_get_termination_status; self->on_missing = fsd_job_on_missing; self->next = NULL; self->ref_cnt = 1; self->job_id = job_id; self->session = NULL; self->last_update_time = 0; self->flags = 0; self->state = DRMAA_PS_UNDETERMINED; self->exit_status = 0; self->submit_time = 0; self->start_time = 0; self->end_time = 0; self->cpu_usage = 0; self->mem_usage = 0; self->vmem_usage = 0; self->walltime = 0; self->n_execution_hosts = 0; self->execution_hosts = NULL; self->retry_cnt = 0; fsd_mutex_init( &self->mutex ); fsd_cond_init( &self->status_cond ); fsd_cond_init( &self->destroy_cond ); fsd_mutex_lock( &self->mutex ); } EXCEPT_DEFAULT { if( self ) self->destroy( self ); else fsd_free( job_id ); fsd_exc_reraise(); } END_TRY fsd_log_return(( "=%p: ref_cnt=%d [lock %s]", (void*)self, self->ref_cnt, self->job_id )); return self; }
fsd_drmaa_session_t * slurmdrmaa_session_new( const char *contact ) { slurmdrmaa_session_t *volatile self = NULL; TRY { self = (slurmdrmaa_session_t*)fsd_drmaa_session_new(contact); fsd_realloc( self, 1, slurmdrmaa_session_t ); self->super.run_job = slurmdrmaa_session_run_job; self->super.run_bulk = slurmdrmaa_session_run_bulk; self->super.new_job = slurmdrmaa_session_new_job; self->super.load_configuration( &self->super, "slurm_drmaa" ); } EXCEPT_DEFAULT { fsd_free( self ); fsd_exc_reraise(); } END_TRY return (fsd_drmaa_session_t*)self; }
void lsfdrmaa_job_set_req( fsd_drmaa_session_t *session, fsd_expand_drmaa_ph_t *expand, const fsd_template_t *jt, struct submit *req, fsd_environ_t **envp ) { const char *input_path_orig = NULL; const char *output_path_orig = NULL; const char *error_path_orig = NULL; char *volatile input_path = NULL; char *volatile output_path = NULL; char *volatile error_path = NULL; bool input_host = false; bool output_host = false; bool error_host = false; bool join_files = false; bool transfer_input = false; bool transfer_output = false; bool transfer_error = false; const char *job_category = "default"; char **volatile argv = NULL; const char *value; const char *const *vector; /* set default lsf configs */ { int i = 0; req->options = 0; req->options2 = 0; for( i = 0; i < LSF_RLIM_NLIMITS; i++ ) req->rLimits[i] = DEFAULT_RLIMIT; req->beginTime = 0; req->termTime = 0; } /* job category */ value = jt->get_attr( jt, DRMAA_JOB_CATEGORY ); if( value ) job_category = value; { fsd_conf_option_t *category_value = NULL; category_value = fsd_conf_dict_get( session->job_categories, job_category ); if( category_value != NULL ) { if( category_value->type != FSD_CONF_STRING ) fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR, "configuration error: job category should be string" ); lsfdrmaa_native_parse( category_value->val.string, req ); } else { if( value != NULL ) fsd_exc_raise_fmt( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid job category: %s", job_category ); } } /* job working directory */ value = jt->get_attr( jt, DRMAA_WD ); if( value ) { char *cwd = NULL; cwd = expand->expand( expand, fsd_strdup(value), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR ); expand->set( expand, FSD_DRMAA_PH_WD, cwd ); #ifdef SUB3_CWD req->cwd = fsd_strdup( cwd ); req->options3 |= SUB3_CWD; #else fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR, "DRMAA_WD attribute is not supported in this version of LSF."); #endif } TRY { const char *command = NULL; unsigned n_args = 0; const char *const *i; int j; /* remote command */ command = jt->get_attr( jt, DRMAA_REMOTE_COMMAND ); if( command == NULL ) fsd_exc_raise_msg( FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, "drmaa_remote_command not set for job template" ); /* arguments list */ vector = jt->get_v_attr( jt, DRMAA_V_ARGV ); if( vector ) { for( i = vector; *i; i++ ) n_args++; } fsd_calloc( argv, n_args+3, char* ); argv[0] = fsd_strdup("exec"); argv[1] = expand->expand( expand, fsd_strdup(command), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD ); if( vector ) { for( i = vector, j = 2; *i; i++, j++ ) argv[j] = expand->expand( expand, fsd_strdup(*i), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD ); } req->command = lsfdrmaa_job_quote_command( (const char*const*)argv ); } FINALLY { fsd_free_vector( argv ); } END_TRY /* job name */ value = jt->get_attr( jt, DRMAA_JOB_NAME ); if( value ) { req->jobName = fsd_strdup(value); req->options |= SUB_JOB_NAME; } /* job state at submit */ value = jt->get_attr( jt, DRMAA_JS_STATE ); if( value ) { if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_ACTIVE ) ) req->options2 &= !SUB2_HOLD; else if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_HOLD ) ) req->options2 |= SUB2_HOLD; else fsd_exc_raise_msg( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_js_state attribute" ); } /* environment */ vector = jt->get_v_attr( jt, DRMAA_V_ENV ); if( vector ) { fsd_environ_t *env; *envp = env = fsd_environ_new( NULL ); env->update( env, vector ); } /* start time */ value = jt->get_attr( jt, DRMAA_START_TIME ); if( value ) { req->beginTime = fsd_datetime_parse( value ); fsd_log_debug(( "\n drmaa_start_time: %s -> %ld", value, (long)req->beginTime )); } TRY { /* input path */ input_path_orig = jt->get_attr( jt, DRMAA_INPUT_PATH ); if( input_path_orig ) { input_path = internal_map_file( expand, input_path_orig, &input_host, "input" ); fsd_log_debug(( "\n drmaa_input_path: %s -> %s", input_path_orig, input_path )); } /* output path */ output_path_orig = jt->get_attr( jt, DRMAA_OUTPUT_PATH ); if( output_path_orig ) { output_path = internal_map_file( expand, output_path_orig, &output_host, "output" ); fsd_log_debug(( "\n drmaa_output_path: %s -> %s", output_path_orig, output_path )); } /* error path */ error_path_orig = jt->get_attr( jt, DRMAA_ERROR_PATH ); if( error_path_orig ) { error_path = internal_map_file( expand, error_path_orig, &error_host, "error" ); fsd_log_debug(( "\n drmaa_error_path: %s -> %s", error_path_orig, error_path )); } /* join files */ value = jt->get_attr( jt, DRMAA_JOIN_FILES ); if( value ) { if( (value[0] == 'y' || value[0] == 'Y') && value[1] == '\0' ) join_files = true; else if( (value[0] == 'n' || value[0] == 'N') && value[1] == '\0' ) join_files = false; else fsd_exc_raise_msg( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_join_files attribute" ); } if( join_files ) { /* * LSF by default joins output and error streams * when error file is not set. */ if( error_path ) { if( output_path == NULL ) fsd_exc_raise_msg( FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, "drmaa_join_files is set and output file is not given" ); if( 0 != strcmp( output_path, error_path ) ) fsd_log_warning(( "Error file was given but will be ignored " "since drmaa_join_files was set." )); fsd_free( error_path ); error_path = NULL; } } else { /* * If error path is not set, we must set it to /dev/null * to prevent joining files. */ if( error_path == NULL && output_path ) error_path = fsd_strdup( "/dev/null" ); if( output_path == NULL && error_path ) output_path = fsd_strdup( "/dev/null" ); if( req->errFile == NULL ) { req->errFile = fsd_strdup( "/dev/null" ); req->options |= SUB_ERR_FILE; #ifdef SUB2_OVERWRITE_ERR_FILE req->options2 &= ~SUB2_OVERWRITE_ERR_FILE; #endif } } /* transfer files */ value = jt->get_attr( jt, DRMAA_TRANSFER_FILES ); if( value ) { const char *i; for( i = value; *i; i++ ) { switch( *i ) { case 'i': transfer_input = true; break; case 'o': transfer_output = true; break; case 'e': transfer_error = true; break; default: fsd_exc_raise_fmt( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid character '%c' in drmaa_transfer_files: %s", *i, value ); } } } # if 0 { /* * Input file is transfered by LSF from submission host whenever * it isn't found on execution host regardless of explicit file transfers. * When drmaa_transfer_files contains ``i`` input file is send * explicitly because it may be outdated or otherwise differ. */ static const char *name[3] = {"input", "output", "error"}; static const int options[3] = { XF_OP_SUB2EXEC, XF_OP_EXEC2SUB, XF_OP_EXEC2SUB }; const char *path[3]; bool host[3], transfer[3]; int i; path[i=0] = input_path; path[++i] = output_path; path[++i] = error_path; host[i=0] = input_host; host[++i] = output_host; host[++i] = error_host; transfer[i=0] = transfer_input; transfer[++i] = transfer_output; transfer[++i] = transfer_error; for( i = 0; i < 3; i++ ) { struct xFile *t; if( !(transfer[i] && path[i] != NULL) ) continue; if( 0 == strcmp( path[i], "/dev/null" ) ) continue; if( host[i] ) fsd_log_warning(( "hostname in drmaa_%s_path ignored", name[i] )); fsd_log_debug(( "setting transfer of %s file (%s) " "to execution host", name[i], path[i] )); fsd_realloc( req->xf, req->nxf+1, struct xFile ); t = &req->xf[ req->nxf++ ]; memset( t, 0, sizeof(struct xFile) ); if( sizeof(t->subFn) == MAXFILENAMELEN ) { /* LSF 6 */ strlcpy( t->subFn, path[i], MAXFILENAMELEN ); strlcpy( t->execFn, path[i], MAXFILENAMELEN ); } else { /* LSF 7 */ *(char**)&t->subFn = fsd_strdup( path[i] ); *(char**)&t->execFn = fsd_strdup( path[i] ); } t->options = options[i]; } if( req->nxf > 0 ) req->options |= SUB_OTHER_FILES; } # endif /* transfer files */ /* email addresses to send notifications */ vector = jt->get_v_attr( jt, DRMAA_V_EMAIL ); if( vector && vector[0] ) { /* only to one email address message may be send */ req->mailUser = fsd_strdup( vector[0] ); req->options |= SUB_MAIL_USER | SUB_NOTIFY_END; #if 0 if( vector[1] != NULL ) fsd_log_warning(( "LSF only supports one e-mail " "notification address" )); #endif } /* block email */ value = jt->get_attr( jt, DRMAA_BLOCK_EMAIL ); if( value ) { bool block; if( strcmp(value, "1") == 0 ) block = true; else if( strcmp(value, "0") == 0 ) block = false; else fsd_exc_raise_msg( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_block_email attribute" ); if( block ) { if( output_path == NULL ) { fsd_log_debug(( "output path not set and we want to block e-mail, " "set to /dev/null" )); output_path = fsd_strdup( "/dev/null" ); } req->options &= ~SUB_NOTIFY_END; } else { /* SUB_NOTIFY_END should force sending e-mail even if outfile is set */ req->options |= SUB_NOTIFY_END; } } if( !((lsfdrmaa_session_t*)session)->prepand_report_to_output && (req->options & SUB_NOTIFY_END) == 0 && output_path != NULL ) { req->options |= SUB_MAIL_USER | SUB_NOTIFY_END; fsd_free( req->mailUser ); /* when email was set but notification was blocked */ req->mailUser = fsd_strdup( "notexistent" ); } if( input_path ) { req->inFile = input_path; req->options |= SUB_IN_FILE; input_path = NULL; } if( output_path ) { req->outFile = output_path; req->options |= SUB_OUT_FILE; #ifdef SUB2_OVERWRITE_OUT_FILE if( 0 != strcmp( output_path, "/dev/null" ) ) req->options2 |= SUB2_OVERWRITE_OUT_FILE; #endif output_path = NULL; } if( error_path ) { req->errFile = error_path; req->options |= SUB_ERR_FILE; #ifdef SUB2_OVERWRITE_ERR_FILE if( 0 != strcmp( error_path, "/dev/null" ) ) req->options2 |= SUB2_OVERWRITE_ERR_FILE; #endif error_path = NULL; } } FINALLY { fsd_free( input_path ); fsd_free( output_path ); fsd_free( error_path ); } END_TRY /* deadline time */ value = jt->get_attr( jt, DRMAA_DEADLINE_TIME ); if( value ) req->termTime = fsd_datetime_parse( value ); /* wall clock time hard limit */ value = jt->get_attr( jt, DRMAA_WCT_HLIMIT ); if( value ) req->rLimits[ LSF_RLIMIT_RUN ] = fsd_parse_timedelta( value ); /* wall clock time soft limit */ #ifdef SUB3_RUNTIME_ESTIMATION value = jt->get_attr( jt, DRMAA_WCT_SLIMIT ); if( value ) { req->options3 = SUB3_RUNTIME_ESTIMATION; req->runtimeEstimation = fsd_parse_timedelta( value ); } #endif /* duration hard limit */ value = jt->get_attr( jt, DRMAA_DURATION_HLIMIT ); if( value ) req->rLimits[ LSF_RLIMIT_CPU ] = fsd_parse_timedelta( value ); /* native specification */ value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION ); if( value ) lsfdrmaa_native_parse( value, req ); lsfdrmaa_dump_submit_req(req); }
void slurmdrmaa_job_create( fsd_drmaa_session_t *session, const fsd_template_t *jt, fsd_environ_t **envp, fsd_expand_drmaa_ph_t *expand, job_desc_msg_t * job_desc, int n_job ) { const char *input_path_orig = NULL; const char *output_path_orig = NULL; const char *error_path_orig = NULL; char *volatile input_path = NULL; char *volatile output_path = NULL; char *volatile error_path = NULL; bool input_host = false; bool output_host = false; bool error_host = false; bool join_files = false; const char *value; const char *const *vector; const char *job_category = "default"; job_desc->user_id = getuid(); job_desc->group_id = getgid(); job_desc->env_size = 0; /* job name */ value = jt->get_attr( jt, DRMAA_JOB_NAME ); if( value ) { job_desc->name = fsd_strdup(value); fsd_log_debug(("# job_name = %s",job_desc->name)); } /* job state at submit */ value = jt->get_attr( jt, DRMAA_JS_STATE ); if( value ) { if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_ACTIVE ) ) {} else if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_HOLD ) ) { job_desc->priority = 0; fsd_log_debug(("# hold = user")); } else { fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_js_state attribute" ); } } TRY { const char *command = NULL; char *command_expanded = NULL; char *temp_script_old = NULL; char *temp_script = ""; const char *const *i; int j; /* remote command */ command = jt->get_attr( jt, DRMAA_REMOTE_COMMAND ); if( command == NULL ) fsd_exc_raise_msg( FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, "drmaa_remote_command not set for job template" ); command_expanded = expand->expand( expand, fsd_strdup(command), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD ); temp_script = fsd_asprintf("#!/bin/bash\n%s",command_expanded); fsd_free(command_expanded); /* arguments list */ vector = jt->get_v_attr( jt, DRMAA_V_ARGV ); if( vector ) { for( i = vector, j = 2; *i; i++, j++ ) { char *arg_expanded = expand->expand( expand, fsd_strdup(*i), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD ); temp_script_old = fsd_strdup(temp_script); if (strcmp(temp_script, "") != 0) { fsd_free(temp_script); } /* add too script */ temp_script = fsd_asprintf("%s '%s'", temp_script_old, arg_expanded); fsd_free(temp_script_old); fsd_free(arg_expanded); } } job_desc->script = fsd_asprintf("%s\n", temp_script); fsd_log_debug(("# Script:\n%s", job_desc->script)); fsd_free(temp_script); } END_TRY /* start time */ value = jt->get_attr( jt, DRMAA_START_TIME ); if( value ) { job_desc->begin_time = fsd_datetime_parse( value ); fsd_log_debug(( "\n drmaa_start_time: %s -> %ld", value, (long)job_desc->begin_time)); } /* propagate all environment variables from submission host */ { extern char **environ; char **i; unsigned j = 0; for ( i = environ; *i; i++) { job_desc->env_size++; } fsd_log_debug(("environ env_size = %d",job_desc->env_size)); fsd_calloc(job_desc->environment, job_desc->env_size+1, char *); for ( i = environ; *i; i++,j++ ) { job_desc->environment[j] = fsd_strdup(*i); } } /* environment */ vector = jt->get_v_attr( jt, DRMAA_V_ENV ); if( vector ) { const char *const *i; unsigned j = 0; unsigned env_offset = job_desc->env_size; for( i = vector; *i; i++ ) { job_desc->env_size++; } fsd_log_debug(("jt env_size = %d",job_desc->env_size)); fsd_log_debug(("# environment =")); fsd_realloc(job_desc->environment, job_desc->env_size+1, char *); for( i = vector; *i; i++,j++ ) { job_desc->environment[j + env_offset] = fsd_strdup(*i); fsd_log_debug((" %s", job_desc->environment[j+ env_offset])); } } /* wall clock time hard limit */ value = jt->get_attr( jt, DRMAA_WCT_HLIMIT ); if (value) { job_desc->time_limit = slurmdrmaa_datetime_parse( value ); fsd_log_debug(("# wct_hlimit = %s -> %ld",value, (long int)slurmdrmaa_datetime_parse( value ))); } /*expand->set(expand, FSD_DRMAA_PH_INCR,fsd_asprintf("%d", n_job));*/ /* set current value */ /* TODO: test drmaa_ph_incr */ /* job working directory */ value = jt->get_attr( jt, DRMAA_WD ); if( value ) { char *cwd_expanded = expand->expand( expand, fsd_strdup(value), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR ); expand->set( expand, FSD_DRMAA_PH_WD, fsd_strdup(cwd_expanded)); fsd_log_debug(("# work_dir = %s",cwd_expanded)); job_desc->work_dir = fsd_strdup(cwd_expanded); fsd_free(cwd_expanded); } else { char cwdbuf[4096] = ""; if ((getcwd(cwdbuf, 4095)) == NULL) { char errbuf[256] = "InternalError"; (void)strerror_r(errno, errbuf, 256); /*on error the default message would be returned */ fsd_log_error(("getcwd failed: %s", errbuf)); job_desc->work_dir = fsd_strdup("."); } else { job_desc->work_dir = fsd_strdup(cwdbuf); } fsd_log_debug(("work_dir(default:CWD) %s", job_desc->work_dir)); } TRY { /* input path */ input_path_orig = jt->get_attr( jt, DRMAA_INPUT_PATH ); if( input_path_orig ) { input_path = internal_map_file( expand, input_path_orig, &input_host,"input" ); fsd_log_debug(( "\n drmaa_input_path: %s -> %s", input_path_orig, input_path )); } /* output path */ output_path_orig = jt->get_attr( jt, DRMAA_OUTPUT_PATH ); if( output_path_orig ) { output_path = internal_map_file( expand, output_path_orig, &output_host,"output" ); fsd_log_debug(( "\n drmaa_output_path: %s -> %s", output_path_orig, output_path )); } /* error path */ error_path_orig = jt->get_attr( jt, DRMAA_ERROR_PATH ); if( error_path_orig ) { error_path = internal_map_file( expand, error_path_orig, &error_host,"error" ); fsd_log_debug(( "\n drmaa_error_path: %s -> %s", error_path_orig, error_path )); } /* join files */ value = jt->get_attr( jt, DRMAA_JOIN_FILES ); if( value ) { if( (value[0] == 'y' || value[0] == 'Y') && value[1] == '\0' ) join_files = true; else if( (value[0] == 'n' || value[0] == 'N') && value[1] == '\0' ) join_files = false; else fsd_exc_raise_msg( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_join_files attribute" ); } if( join_files ) { if( output_path == NULL ) fsd_exc_raise_msg(FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, "drmaa_join_files is set and output file is not given" ); if( error_path!=NULL && 0 != strcmp( output_path, error_path ) ) fsd_log_warning(( "Error file was given but will be ignored since drmaa_join_files was set." )); if (error_path) fsd_free(error_path); error_path = fsd_strdup(output_path); } else { if( error_path == NULL && output_path ) error_path = fsd_strdup( "/dev/null" ); if( output_path == NULL && error_path ) output_path = fsd_strdup( "/dev/null" ); } /* email addresses to send notifications */ vector = jt->get_v_attr( jt, DRMAA_V_EMAIL ); if( vector && vector[0] ) { /* only to one email address message may be send */ job_desc->mail_user = fsd_strdup(vector[0]); job_desc->mail_type = MAIL_JOB_BEGIN | MAIL_JOB_END | MAIL_JOB_FAIL; fsd_log_debug(("# mail_user = %s\n",vector[0])); fsd_log_debug(("# mail_type = %o\n",job_desc->mail_type)); if( vector[1] != NULL ) { fsd_log_error(( "SLURM only supports one e-mail notification address" )); fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"SLURM only supports one e-mail notification address"); } } /* block email */ value = jt->get_attr( jt, DRMAA_BLOCK_EMAIL ); if( value ) { bool block; if( strcmp(value, "0") == 0 ) { block = true; fsd_log_debug(("# block_email = true")); fsd_log_debug(("# mail_user delated")); fsd_free(job_desc->mail_user); job_desc->mail_user = NULL; } else if( strcmp(value, "1") == 0 ) block = false; else fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"invalid value of drmaa_block_email attribute" ); if( block && output_path == NULL ) { fsd_log_debug(( "output path not set and we want to block e-mail, set to /dev/null" )); output_path = fsd_strdup( "/dev/null" ); } } if( input_path ) { job_desc->std_in = fsd_strdup(input_path); fsd_log_debug(("# input = %s", input_path)); } if( output_path ) { job_desc->std_out = fsd_strdup(output_path); fsd_log_debug(("# output = %s", output_path)); } if( error_path ) { job_desc->std_err = fsd_strdup(error_path); fsd_log_debug(("# error = %s", error_path)); } } FINALLY { fsd_free( input_path ); fsd_free( output_path ); fsd_free( error_path ); input_path = NULL; output_path = NULL; error_path = NULL; } END_TRY /* job category */ value = jt->get_attr( jt, DRMAA_JOB_CATEGORY ); if( value ) job_category = value; { fsd_conf_option_t *category_value = NULL; category_value = fsd_conf_dict_get( session->job_categories, job_category ); if( category_value != NULL ) { if( category_value->type != FSD_CONF_STRING ) fsd_exc_raise_fmt( FSD_ERRNO_INTERNAL_ERROR, "configuration error: job category should be string" ); fsd_log_debug(("# Job category %s : %s\n",value,category_value->val.string)); slurmdrmaa_parse_native(job_desc,category_value->val.string); } else { if( value != NULL ) fsd_exc_raise_fmt( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid job category: %s", job_category ); } } /* set defaults for constraints - ref: slurm.h */ fsd_log_debug(("# Setting defaults for tasks and processors" )); job_desc->num_tasks = 1; job_desc->min_cpus = 0; job_desc->cpus_per_task = 0; job_desc->pn_min_cpus = 0; /* native specification */ value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION ); if( value ) { fsd_log_debug(("# Native specification: %s\n", value)); slurmdrmaa_parse_native(job_desc, value); } }
char * fsd_drmaa_session_wait_for_any_job( fsd_drmaa_session_t *self, const struct timespec *timeout, int *status, fsd_iter_t **rusage, bool dispose ) { fsd_job_set_t *set = self->jobs; fsd_job_t *volatile job = NULL; char *volatile job_id = NULL; volatile bool locked = false; fsd_log_enter(( "" )); TRY { while( job == NULL ) { bool signaled = true; if( self->destroy_requested ) fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION ); if( !self->enable_wait_thread ) self->update_all_jobs_status( self ); locked = fsd_mutex_lock( &self->mutex ); if( set->empty( set ) ) fsd_exc_raise_msg( FSD_DRMAA_ERRNO_INVALID_JOB, "No job found to be waited for" ); if( (job = set->find_terminated( set )) != NULL ) break; if( self->destroy_requested ) fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION ); if( self->enable_wait_thread ) { fsd_log_debug(( "wait_for_any_job: waiting for wait thread" )); if( timeout ) signaled = fsd_cond_timedwait( &self->wait_condition, &self->mutex, timeout ); else fsd_cond_wait( &self->wait_condition, &self->mutex ); } else { fsd_log_debug(( "wait_for_any_job: waiting for next check" )); self->wait_for_job_status_change( self, &self->wait_condition, &self->mutex, timeout ); } locked = fsd_mutex_unlock( &self->mutex ); fsd_log_debug(( "wait_for_any_job: woken up; signaled=%d", signaled )); if( !signaled ) fsd_exc_raise_code( FSD_DRMAA_ERRNO_EXIT_TIMEOUT ); } fsd_log_debug(( "wait_for_any_job: waiting finished" )); job_id = fsd_strdup( job->job_id ); job->get_termination_status( job, status, rusage ); } EXCEPT_DEFAULT { if( job_id ) fsd_free( job_id ); fsd_exc_reraise(); } FINALLY { if( job ) { if( fsd_exc_get() == NULL && dispose ) { set->remove( set, job ); job->flags |= FSD_JOB_DISPOSED; } job->release( job ); } if( locked ) fsd_mutex_unlock( &self->mutex ); } END_TRY fsd_log_return(( " =%s", job_id )); return job_id; }