[12] | 1 | /* $Id$ */ |
---|
[1] | 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 |
---|
[12] | 48 | = "$Id$"; |
---|
[1] | 49 | #endif |
---|
| 50 | |
---|
[48] | 51 | static void pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self ); |
---|
[1] | 52 | |
---|
[48] | 53 | static char *pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self ); |
---|
[1] | 54 | |
---|
[48] | 55 | static void pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self ); |
---|
[1] | 56 | |
---|
[48] | 57 | static void pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *pbs_attr, char *value, unsigned placeholders ); |
---|
[1] | 58 | |
---|
| 59 | static void pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self ); |
---|
| 60 | static void pbsdrmaa_submit_apply_job_script( pbsdrmaa_submit_t *self ); |
---|
| 61 | static void pbsdrmaa_submit_apply_job_state( pbsdrmaa_submit_t *self ); |
---|
| 62 | static void pbsdrmaa_submit_apply_job_files( pbsdrmaa_submit_t *self ); |
---|
| 63 | static void pbsdrmaa_submit_apply_file_staging( pbsdrmaa_submit_t *self ); |
---|
| 64 | static void pbsdrmaa_submit_apply_job_resources( pbsdrmaa_submit_t *self ); |
---|
| 65 | static void pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self ); |
---|
| 66 | static void pbsdrmaa_submit_apply_email_notification( pbsdrmaa_submit_t *self ); |
---|
| 67 | static void pbsdrmaa_submit_apply_job_category( pbsdrmaa_submit_t *self ); |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | pbsdrmaa_submit_t * |
---|
| 71 | pbsdrmaa_submit_new( fsd_drmaa_session_t *session, |
---|
| 72 | const fsd_template_t *job_template, int bulk_idx ) |
---|
| 73 | { |
---|
| 74 | pbsdrmaa_submit_t *volatile self = NULL; |
---|
| 75 | TRY |
---|
| 76 | { |
---|
| 77 | fsd_malloc( self, pbsdrmaa_submit_t ); |
---|
| 78 | self->session = session; |
---|
| 79 | self->job_template = job_template; |
---|
| 80 | self->script_filename = NULL; |
---|
| 81 | self->destination_queue = NULL; |
---|
| 82 | self->pbs_job_attributes = NULL; |
---|
| 83 | self->expand_ph = NULL; |
---|
| 84 | self->destroy = pbsdrmaa_submit_destroy; |
---|
| 85 | self->submit = pbsdrmaa_submit_submit; |
---|
| 86 | self->eval = pbsdrmaa_submit_eval; |
---|
| 87 | self->set = pbsdrmaa_submit_set; |
---|
| 88 | self->apply_defaults = pbsdrmaa_submit_apply_defaults; |
---|
| 89 | self->apply_job_category = pbsdrmaa_submit_apply_job_category; |
---|
| 90 | self->apply_job_script = pbsdrmaa_submit_apply_job_script; |
---|
| 91 | self->apply_job_state = pbsdrmaa_submit_apply_job_state; |
---|
| 92 | self->apply_job_files = pbsdrmaa_submit_apply_job_files; |
---|
| 93 | self->apply_file_staging = pbsdrmaa_submit_apply_file_staging; |
---|
| 94 | self->apply_job_resources = pbsdrmaa_submit_apply_job_resources; |
---|
| 95 | self->apply_job_environment = pbsdrmaa_submit_apply_job_environment; |
---|
| 96 | self->apply_email_notification = pbsdrmaa_submit_apply_email_notification; |
---|
[48] | 97 | self->apply_native_specification = pbsdrmaa_submit_apply_native_specification; |
---|
[1] | 98 | |
---|
| 99 | self->pbs_job_attributes = pbsdrmaa_pbs_template_new(); |
---|
| 100 | self->expand_ph = fsd_expand_drmaa_ph_new( NULL, NULL, |
---|
| 101 | (bulk_idx >= 0) ? fsd_asprintf("%d", bulk_idx) : NULL ); |
---|
| 102 | } |
---|
| 103 | EXCEPT_DEFAULT |
---|
| 104 | { |
---|
| 105 | if( self ) |
---|
| 106 | self->destroy( self ); |
---|
| 107 | } |
---|
| 108 | END_TRY |
---|
| 109 | return self; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | void |
---|
| 114 | pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self ) |
---|
| 115 | { |
---|
| 116 | if( self->script_filename ) |
---|
| 117 | { |
---|
| 118 | unlink( self->script_filename ); |
---|
| 119 | fsd_free( self->script_filename ); |
---|
| 120 | } |
---|
| 121 | if( self->pbs_job_attributes ) |
---|
| 122 | self->pbs_job_attributes->destroy( self->pbs_job_attributes ); |
---|
| 123 | if( self->expand_ph ) |
---|
| 124 | self->expand_ph->destroy( self->expand_ph ); |
---|
| 125 | fsd_free( self->destination_queue ); |
---|
| 126 | fsd_free( self ); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | char * |
---|
| 131 | pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self ) |
---|
| 132 | { |
---|
| 133 | volatile bool conn_lock = false; |
---|
| 134 | struct attrl *volatile pbs_attr = NULL; |
---|
| 135 | char *volatile job_id = NULL; |
---|
| 136 | TRY |
---|
| 137 | { |
---|
[48] | 138 | fsd_template_t *pbs_tmpl = self->pbs_job_attributes; |
---|
| 139 | int i; |
---|
[45] | 140 | int tries_left = ((pbsdrmaa_session_t *)self->session)->max_retries_count; |
---|
| 141 | int sleep_time = 1; |
---|
[1] | 142 | |
---|
[48] | 143 | for( i = PBSDRMAA_N_PBS_ATTRIBUTES - 1; i >= 0; i-- ) /* down loop -> start with custom resources */ |
---|
[1] | 144 | { |
---|
| 145 | const char *name = pbs_tmpl->by_code( pbs_tmpl, i )->name; |
---|
[48] | 146 | const char *value = pbs_tmpl->get_attr( pbs_tmpl, name ); |
---|
| 147 | |
---|
| 148 | if (!value) |
---|
| 149 | continue; |
---|
| 150 | |
---|
| 151 | if ( i == PBSDRMAA_ATTR_CUSTOM_RESOURCES) |
---|
[1] | 152 | { |
---|
[48] | 153 | char *value_copy = fsd_strdup(value); |
---|
| 154 | char *tok_comma_ctx = NULL; |
---|
| 155 | char *res_token = NULL; |
---|
| 156 | /* matlab:2,simulink:1 */ |
---|
[29] | 157 | |
---|
[48] | 158 | for (res_token = strtok_r(value_copy, ",", &tok_comma_ctx); res_token; res_token = strtok_r(NULL, ",", &tok_comma_ctx)) |
---|
| 159 | { |
---|
| 160 | char *value_p = strstr(res_token, ":"); |
---|
| 161 | |
---|
| 162 | if (value_p) |
---|
| 163 | { |
---|
| 164 | char *name_p = NULL; |
---|
| 165 | *value_p = '\0'; |
---|
| 166 | value_p++; |
---|
| 167 | name_p = fsd_asprintf("Resource_List.%s",res_token); |
---|
| 168 | pbs_attr = pbsdrmaa_add_attr( pbs_attr, name_p, value_p ); |
---|
| 169 | fsd_free(name_p); |
---|
| 170 | } |
---|
| 171 | else |
---|
| 172 | { |
---|
| 173 | fsd_exc_raise_code( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE ); |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | fsd_free(value_copy); |
---|
| 178 | } |
---|
| 179 | else if (i == PBSDRMAA_ATTR_NODE_PROPERTIES) |
---|
| 180 | { |
---|
| 181 | const char *nodes_value = pbs_tmpl->get_attr( pbs_tmpl, PBSDRMAA_NODES ); |
---|
| 182 | char *final_value = NULL; |
---|
| 183 | |
---|
[49] | 184 | if (nodes_value) |
---|
[48] | 185 | { |
---|
| 186 | final_value = fsd_asprintf("%s:%s",nodes_value, value); |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | final_value = fsd_asprintf("1:%s", value); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | pbs_tmpl->set_attr( pbs_tmpl, PBSDRMAA_NODES, final_value); |
---|
| 194 | fsd_free(final_value); |
---|
| 195 | } |
---|
| 196 | else |
---|
| 197 | { |
---|
[29] | 198 | pbs_attr = pbsdrmaa_add_attr( pbs_attr, name, value ); |
---|
[1] | 199 | } |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex ); |
---|
| 203 | retry: |
---|
| 204 | job_id = pbs_submit( ((pbsdrmaa_session_t*)self->session)->pbs_conn, |
---|
| 205 | (struct attropl*)pbs_attr, self->script_filename, |
---|
| 206 | self->destination_queue, NULL ); |
---|
[10] | 207 | |
---|
[16] | 208 | fsd_log_info(("pbs_submit(%s, %s) =%s", self->script_filename, self->destination_queue, job_id)); |
---|
[10] | 209 | |
---|
[1] | 210 | if( job_id == NULL ) |
---|
| 211 | { |
---|
| 212 | if (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED) |
---|
| 213 | { |
---|
| 214 | pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self->session; |
---|
[3] | 215 | if (pbsself->pbs_conn >= 0 ) |
---|
| 216 | pbs_disconnect( pbsself->pbs_conn ); |
---|
[45] | 217 | retry_connect: |
---|
| 218 | sleep(sleep_time++); |
---|
[1] | 219 | pbsself->pbs_conn = pbs_connect( pbsself->super.contact ); |
---|
[45] | 220 | if( pbsself->pbs_conn < 0) |
---|
| 221 | if (tries_left--) |
---|
| 222 | goto retry_connect; |
---|
| 223 | else |
---|
| 224 | pbsdrmaa_exc_raise_pbs( "pbs_connect" ); |
---|
[1] | 225 | else |
---|
| 226 | goto retry; |
---|
| 227 | } |
---|
| 228 | else |
---|
| 229 | { |
---|
| 230 | pbsdrmaa_exc_raise_pbs( "pbs_submit" ); |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex ); |
---|
| 234 | } |
---|
| 235 | EXCEPT_DEFAULT |
---|
| 236 | { |
---|
| 237 | fsd_free( job_id ); |
---|
| 238 | fsd_exc_reraise(); |
---|
| 239 | } |
---|
| 240 | FINALLY |
---|
| 241 | { |
---|
| 242 | if( conn_lock ) |
---|
| 243 | conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex ); |
---|
| 244 | if( pbs_attr ) |
---|
| 245 | pbsdrmaa_free_attrl( pbs_attr ); |
---|
| 246 | } |
---|
| 247 | END_TRY |
---|
| 248 | return job_id; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | void |
---|
| 253 | pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self ) |
---|
| 254 | { |
---|
| 255 | self->apply_defaults( self ); |
---|
| 256 | self->apply_job_category( self ); |
---|
| 257 | self->apply_job_script( self ); |
---|
| 258 | self->apply_job_state( self ); |
---|
| 259 | self->apply_job_files( self ); |
---|
| 260 | self->apply_file_staging( self ); |
---|
| 261 | self->apply_job_resources( self ); |
---|
| 262 | self->apply_job_environment( self ); |
---|
| 263 | self->apply_email_notification( self ); |
---|
| 264 | self->apply_native_specification( self, NULL ); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | void |
---|
| 269 | pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *name, |
---|
| 270 | char *value, unsigned placeholders ) |
---|
| 271 | { |
---|
| 272 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
| 273 | TRY |
---|
| 274 | { |
---|
| 275 | if( placeholders ) |
---|
| 276 | value = self->expand_ph->expand( |
---|
| 277 | self->expand_ph, value, placeholders ); |
---|
| 278 | pbs_attr->set_attr( pbs_attr, name, value ); |
---|
| 279 | } |
---|
| 280 | FINALLY |
---|
| 281 | { |
---|
| 282 | fsd_free( value ); |
---|
| 283 | } |
---|
| 284 | END_TRY |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | void |
---|
| 289 | pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self ) |
---|
| 290 | { |
---|
| 291 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
| 292 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_CHECKPOINT, "u" ); |
---|
| 293 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_KEEP_FILES, "n" ); |
---|
| 294 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_PRIORITY, "0" ); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | |
---|
| 298 | void |
---|
| 299 | pbsdrmaa_submit_apply_job_script( pbsdrmaa_submit_t *self ) |
---|
| 300 | { |
---|
| 301 | const fsd_template_t *jt = self->job_template; |
---|
| 302 | /* fsd_template_t *pbs_attr = self->pbs_job_attributes; */ |
---|
| 303 | fsd_expand_drmaa_ph_t *expand = self->expand_ph; |
---|
| 304 | char *script = NULL; |
---|
| 305 | size_t script_len; |
---|
| 306 | const char *executable; |
---|
| 307 | const char *wd; |
---|
| 308 | const char *const *argv; |
---|
| 309 | const char *input_path; |
---|
| 310 | const char *const *i; |
---|
| 311 | |
---|
| 312 | executable = jt->get_attr( jt, DRMAA_REMOTE_COMMAND ); |
---|
| 313 | wd = jt->get_attr( jt, DRMAA_WD ); |
---|
| 314 | argv = jt->get_v_attr( jt, DRMAA_V_ARGV ); |
---|
| 315 | input_path = jt->get_attr( jt, DRMAA_INPUT_PATH ); |
---|
| 316 | |
---|
| 317 | if( wd ) |
---|
| 318 | { |
---|
| 319 | char *cwd = NULL; |
---|
| 320 | cwd = expand->expand( expand, fsd_strdup(wd), |
---|
| 321 | FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR ); |
---|
| 322 | expand->set( expand, FSD_DRMAA_PH_WD, cwd ); |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | if( executable == NULL ) |
---|
| 326 | fsd_exc_raise_code( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE ); |
---|
| 327 | |
---|
| 328 | if( input_path != NULL ) |
---|
| 329 | { |
---|
| 330 | if( input_path[0] == ':' ) |
---|
| 331 | input_path++; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | { /* compute script length */ |
---|
| 335 | script_len = 0; |
---|
| 336 | if( wd != NULL ) |
---|
| 337 | script_len += strlen("cd ") + strlen(wd) + strlen("; "); |
---|
[56] | 338 | script_len += strlen("touch ") + strlen(((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix) + strlen("/$PBS_JOBID.started;"); |
---|
[53] | 339 | script_len += strlen(executable); |
---|
[1] | 340 | if( argv != NULL ) |
---|
| 341 | for( i = argv; *i != NULL; i++ ) |
---|
| 342 | script_len += 3+strlen(*i); |
---|
| 343 | if( input_path != NULL ) |
---|
| 344 | script_len += strlen(" <") + strlen(input_path); |
---|
[56] | 345 | |
---|
| 346 | script_len += strlen("; echo $? >") + strlen(((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix) + strlen("/$PBS_JOBID.exitcode"); |
---|
[1] | 347 | } |
---|
| 348 | |
---|
| 349 | fsd_calloc( script, script_len+1, char ); |
---|
| 350 | |
---|
| 351 | { |
---|
| 352 | char *s; |
---|
| 353 | s = script; |
---|
| 354 | if( wd != NULL ) |
---|
| 355 | s += sprintf( s, "cd %s; ", wd ); |
---|
[57] | 356 | s += sprintf( s, "touch %s/$PBS_JOBID.started;", ((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix); |
---|
[53] | 357 | s += sprintf( s, "%s", executable ); |
---|
[1] | 358 | if( argv != NULL ) |
---|
| 359 | for( i = argv; *i != NULL; i++ ) |
---|
| 360 | s += sprintf( s, " '%s'", *i ); |
---|
| 361 | if( input_path != NULL ) |
---|
| 362 | s += sprintf( s, " <%s", input_path ); |
---|
[52] | 363 | |
---|
[56] | 364 | s += sprintf( s, "; echo $? >%s/$PBS_JOBID.exitcode", ((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix); |
---|
| 365 | |
---|
[1] | 366 | fsd_assert( s == script+script_len ); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | script = expand->expand( expand, script, |
---|
| 370 | FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR ); |
---|
| 371 | |
---|
| 372 | /* pbs_attr->set_attr( pbs_attr, "!script", script ); */ |
---|
| 373 | |
---|
| 374 | self->script_filename = pbsdrmaa_write_tmpfile( script, strlen(script) ); |
---|
| 375 | fsd_free( script ); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | void |
---|
| 380 | pbsdrmaa_submit_apply_job_state( pbsdrmaa_submit_t *self ) |
---|
| 381 | { |
---|
| 382 | const fsd_template_t *jt = self->job_template; |
---|
| 383 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
| 384 | const char *job_name = NULL; |
---|
| 385 | const char *submit_state = NULL; |
---|
| 386 | const char *drmaa_start_time = NULL; |
---|
| 387 | |
---|
| 388 | job_name = jt->get_attr( jt, DRMAA_JOB_NAME ); |
---|
| 389 | submit_state = jt->get_attr( jt, DRMAA_JS_STATE ); |
---|
| 390 | drmaa_start_time = jt->get_attr( jt, DRMAA_START_TIME ); |
---|
| 391 | |
---|
| 392 | if( job_name != NULL ) |
---|
| 393 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOB_NAME, job_name ); |
---|
| 394 | |
---|
| 395 | if( submit_state != NULL ) |
---|
| 396 | { |
---|
| 397 | const char *hold_types; |
---|
| 398 | if( !strcmp(submit_state, DRMAA_SUBMISSION_STATE_ACTIVE) ) |
---|
| 399 | hold_types = "n"; |
---|
| 400 | else if( !strcmp(submit_state, DRMAA_SUBMISSION_STATE_HOLD) ) |
---|
| 401 | hold_types = "u"; |
---|
| 402 | else |
---|
| 403 | fsd_exc_raise_fmt( FSD_ERRNO_INVALID_VALUE, |
---|
| 404 | "invalid value of %s attribute (%s|%s)", |
---|
| 405 | DRMAA_JS_STATE, DRMAA_SUBMISSION_STATE_ACTIVE, |
---|
| 406 | DRMAA_SUBMISSION_STATE_HOLD ); |
---|
| 407 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_HOLD_TYPES, hold_types ); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | if( drmaa_start_time != NULL ) |
---|
| 411 | { |
---|
| 412 | time_t start_time; |
---|
| 413 | char pbs_start_time[20]; |
---|
| 414 | struct tm start_time_tm; |
---|
| 415 | start_time = fsd_datetime_parse( drmaa_start_time ); |
---|
| 416 | localtime_r( &start_time, &start_time_tm ); |
---|
| 417 | sprintf( pbs_start_time, "%04d%02d%02d%02d%02d.%02d", |
---|
| 418 | start_time_tm.tm_year + 1900, |
---|
| 419 | start_time_tm.tm_mon + 1, |
---|
| 420 | start_time_tm.tm_mday, |
---|
| 421 | start_time_tm.tm_hour, |
---|
| 422 | start_time_tm.tm_min, |
---|
| 423 | start_time_tm.tm_sec |
---|
| 424 | ); |
---|
| 425 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_EXECUTION_TIME, pbs_start_time ); |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | |
---|
| 430 | void |
---|
| 431 | pbsdrmaa_submit_apply_job_files( pbsdrmaa_submit_t *self ) |
---|
| 432 | { |
---|
| 433 | const fsd_template_t *jt = self->job_template; |
---|
| 434 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
| 435 | const char *join_files; |
---|
| 436 | bool b_join_files; |
---|
| 437 | int i; |
---|
| 438 | |
---|
| 439 | for( i = 0; i < 2; i++ ) |
---|
| 440 | { |
---|
| 441 | const char *drmaa_name; |
---|
| 442 | const char *pbs_name; |
---|
| 443 | const char *path; |
---|
| 444 | |
---|
| 445 | if( i == 0 ) |
---|
| 446 | { |
---|
| 447 | drmaa_name = DRMAA_OUTPUT_PATH; |
---|
| 448 | pbs_name = PBSDRMAA_OUTPUT_PATH; |
---|
| 449 | } |
---|
| 450 | else |
---|
| 451 | { |
---|
| 452 | drmaa_name = DRMAA_ERROR_PATH; |
---|
| 453 | pbs_name = PBSDRMAA_ERROR_PATH; |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | path = jt->get_attr( jt, drmaa_name ); |
---|
| 457 | if( path != NULL ) |
---|
| 458 | { |
---|
| 459 | if( path[0] == ':' ) |
---|
| 460 | path++; |
---|
| 461 | self->set(self, pbs_name, fsd_strdup(path), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR); |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | join_files = jt->get_attr( jt, DRMAA_JOIN_FILES ); |
---|
| 466 | b_join_files = join_files != NULL && !strcmp(join_files,"1"); |
---|
| 467 | pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOIN_FILES, (b_join_files ? "y" : "n") ); |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | |
---|
| 471 | void |
---|
| 472 | pbsdrmaa_submit_apply_file_staging( pbsdrmaa_submit_t *self ) |
---|
| 473 | { |
---|
| 474 | /* TODO */ |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | |
---|
| 478 | void |
---|
| 479 | pbsdrmaa_submit_apply_job_resources( pbsdrmaa_submit_t *self ) |
---|
| 480 | { |
---|
| 481 | const fsd_template_t *jt = self->job_template; |
---|
| 482 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
| 483 | const char *cpu_time_limit = NULL; |
---|
| 484 | const char *walltime_limit = NULL; |
---|
| 485 | |
---|
| 486 | cpu_time_limit = jt->get_attr( jt, DRMAA_DURATION_HLIMIT ); |
---|
| 487 | walltime_limit = jt->get_attr( jt, DRMAA_WCT_HLIMIT ); |
---|
| 488 | if( cpu_time_limit ) |
---|
| 489 | { |
---|
| 490 | pbs_attr->set_attr( pbs_attr, "Resource_List.pcput", cpu_time_limit ); |
---|
| 491 | pbs_attr->set_attr( pbs_attr, "Resource_List.cput", cpu_time_limit ); |
---|
| 492 | } |
---|
| 493 | if( walltime_limit ) |
---|
| 494 | pbs_attr->set_attr( pbs_attr, "Resource_List.walltime", walltime_limit ); |
---|
| 495 | } |
---|
| 496 | |
---|
[48] | 497 | |
---|
| 498 | |
---|
[1] | 499 | void |
---|
| 500 | pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self ) |
---|
| 501 | { |
---|
| 502 | const fsd_template_t *jt = self->job_template; |
---|
| 503 | const char *const *env_v; |
---|
[24] | 504 | const char *jt_wd; |
---|
| 505 | char *wd; |
---|
| 506 | char *env_c = NULL; |
---|
| 507 | int ii = 0, len = 0; |
---|
[1] | 508 | |
---|
| 509 | env_v = jt->get_v_attr( jt, DRMAA_V_ENV); |
---|
[24] | 510 | jt_wd = jt->get_attr( jt, DRMAA_WD ); |
---|
| 511 | |
---|
| 512 | if (!jt_wd) |
---|
| 513 | { |
---|
| 514 | wd = fsd_getcwd(); |
---|
| 515 | } |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | wd = fsd_strdup(jt_wd); |
---|
| 519 | } |
---|
[1] | 520 | |
---|
| 521 | if (env_v) |
---|
[48] | 522 | { |
---|
[1] | 523 | ii = 0; |
---|
[48] | 524 | while (env_v[ii]) |
---|
| 525 | { |
---|
[1] | 526 | len += strlen(env_v[ii]) + 1; |
---|
| 527 | ii++; |
---|
[48] | 528 | } |
---|
| 529 | } |
---|
[24] | 530 | |
---|
| 531 | len+= strlen("PBS_O_WORKDIR=") + strlen(wd); |
---|
[1] | 532 | |
---|
[24] | 533 | fsd_calloc(env_c, len + 1, char); |
---|
| 534 | env_c[0] = '\0'; |
---|
[1] | 535 | |
---|
[24] | 536 | if (env_v) |
---|
| 537 | { |
---|
[1] | 538 | ii = 0; |
---|
| 539 | while (env_v[ii]) { |
---|
| 540 | strcat(env_c, env_v[ii]); |
---|
| 541 | strcat(env_c, ","); |
---|
| 542 | ii++; |
---|
| 543 | } |
---|
| 544 | |
---|
[24] | 545 | } |
---|
| 546 | |
---|
| 547 | strcat(env_c, "PBS_O_WORKDIR="); |
---|
| 548 | strcat(env_c, wd); |
---|
[1] | 549 | |
---|
[24] | 550 | self->pbs_job_attributes->set_attr(self->pbs_job_attributes, "Variable_List", env_c); |
---|
[1] | 551 | |
---|
[24] | 552 | fsd_free(env_c); |
---|
| 553 | fsd_free(wd); |
---|
[1] | 554 | } |
---|
| 555 | |
---|
| 556 | |
---|
| 557 | void |
---|
| 558 | pbsdrmaa_submit_apply_email_notification( pbsdrmaa_submit_t *self ) |
---|
| 559 | { |
---|
| 560 | /* TODO */ |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | |
---|
| 564 | void |
---|
| 565 | pbsdrmaa_submit_apply_job_category( pbsdrmaa_submit_t *self ) |
---|
| 566 | { |
---|
| 567 | const char *job_category = NULL; |
---|
| 568 | const char *category_spec = NULL; |
---|
| 569 | fsd_conf_option_t *value = NULL; |
---|
| 570 | |
---|
| 571 | job_category = self->job_template->get_attr( |
---|
| 572 | self->job_template, DRMAA_JOB_CATEGORY ); |
---|
| 573 | if( job_category == NULL || job_category[0] == '\0' ) |
---|
| 574 | job_category = "default"; |
---|
| 575 | value = fsd_conf_dict_get( self->session->job_categories, |
---|
| 576 | job_category ); |
---|
| 577 | if( value != NULL && value->type == FSD_CONF_STRING ) |
---|
| 578 | category_spec = value->val.string; |
---|
| 579 | if( category_spec != NULL ) |
---|
| 580 | self->apply_native_specification( self, category_spec ); |
---|
| 581 | } |
---|
| 582 | |
---|
[48] | 583 | static const char *get_job_env(pbsdrmaa_submit_t *self, const char *env_name) |
---|
[1] | 584 | { |
---|
[48] | 585 | const fsd_template_t *jt = self->job_template; |
---|
| 586 | const char *const *env_v = jt->get_v_attr( jt, DRMAA_V_ENV); |
---|
| 587 | int ii = 0; |
---|
| 588 | |
---|
| 589 | while (env_v[ii]) |
---|
| 590 | { |
---|
| 591 | char *eq_p = strstr(env_v[ii], "="); |
---|
| 592 | |
---|
| 593 | if ((eq_p) && (strncmp(env_v[ii], env_name, eq_p - env_v[ii]) == 0)) |
---|
| 594 | return ++eq_p; |
---|
| 595 | |
---|
| 596 | ii++; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | return NULL; |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | static void parse_resources(pbsdrmaa_submit_t *self, fsd_template_t *pbs_attr,const char *resources) |
---|
| 603 | { |
---|
[1] | 604 | char * volatile name = NULL; |
---|
| 605 | char *arg = NULL; |
---|
| 606 | char *value = NULL; |
---|
| 607 | char *ctxt = NULL; |
---|
| 608 | char * volatile resources_copy = fsd_strdup(resources); |
---|
| 609 | |
---|
| 610 | TRY |
---|
| 611 | { |
---|
| 612 | for (arg = strtok_r(resources_copy, ",", &ctxt); arg; arg = strtok_r(NULL, ",",&ctxt) ) |
---|
| 613 | { |
---|
| 614 | char *psep = strchr(arg, '='); |
---|
| 615 | |
---|
| 616 | if (psep) |
---|
| 617 | { |
---|
| 618 | *psep = '\0'; |
---|
| 619 | name = fsd_asprintf("Resource_List.%s", arg); |
---|
| 620 | value = ++psep; |
---|
[48] | 621 | if (value[0] == '$' && get_job_env(self, value + 1)) |
---|
| 622 | pbs_attr->set_attr( pbs_attr, name , get_job_env(self, value + 1) ); /*get value from job env variable */ |
---|
| 623 | else |
---|
| 624 | pbs_attr->set_attr( pbs_attr, name , value ); |
---|
[1] | 625 | fsd_free(name); |
---|
| 626 | name = NULL; |
---|
| 627 | } |
---|
| 628 | else |
---|
| 629 | { |
---|
[12] | 630 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Invalid native specification: %s (Invalid resource specification: %s)", resources, arg); |
---|
[1] | 631 | } |
---|
| 632 | } |
---|
| 633 | } |
---|
| 634 | FINALLY |
---|
| 635 | { |
---|
| 636 | fsd_free(name); |
---|
| 637 | fsd_free(resources_copy); |
---|
| 638 | } |
---|
| 639 | END_TRY |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | static void parse_additional_attr(fsd_template_t *pbs_attr,const char *add_attr) |
---|
| 643 | { |
---|
| 644 | char * volatile name = NULL; |
---|
| 645 | char *arg = NULL; |
---|
| 646 | char *value = NULL; |
---|
| 647 | char *ctxt = NULL, *ctxt2 = NULL; |
---|
| 648 | char * volatile add_attr_copy = fsd_strdup(add_attr); |
---|
| 649 | |
---|
| 650 | TRY |
---|
| 651 | { |
---|
[12] | 652 | for (arg = strtok_r(add_attr_copy, ";", &ctxt); arg; arg = strtok_r(NULL, ";",&ctxt) ) |
---|
[1] | 653 | { |
---|
| 654 | name = fsd_strdup(strtok_r(arg, "=", &ctxt2)); |
---|
| 655 | value = strtok_r(NULL, "=", &ctxt2); |
---|
| 656 | pbs_attr->set_attr( pbs_attr, name , value ); |
---|
| 657 | fsd_free(name); |
---|
| 658 | name = NULL; |
---|
| 659 | } |
---|
| 660 | } |
---|
| 661 | FINALLY |
---|
| 662 | { |
---|
| 663 | fsd_free(name); |
---|
| 664 | fsd_free(add_attr_copy); |
---|
| 665 | } |
---|
| 666 | END_TRY |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | |
---|
| 670 | void |
---|
| 671 | pbsdrmaa_submit_apply_native_specification( pbsdrmaa_submit_t *self, |
---|
| 672 | const char *native_specification ) |
---|
| 673 | { |
---|
[48] | 674 | fsd_log_enter(( "({native_specification=%s})", native_specification )); |
---|
[16] | 675 | |
---|
[1] | 676 | if( native_specification == NULL ) |
---|
| 677 | native_specification = self->job_template->get_attr( |
---|
| 678 | self->job_template, DRMAA_NATIVE_SPECIFICATION ); |
---|
| 679 | if( native_specification == NULL ) |
---|
| 680 | return; |
---|
| 681 | |
---|
| 682 | { |
---|
| 683 | fsd_iter_t * volatile args_list = fsd_iter_new(NULL, 0); |
---|
| 684 | fsd_template_t *pbs_attr = self->pbs_job_attributes; |
---|
| 685 | char *arg = NULL; |
---|
| 686 | volatile char * native_spec_copy = fsd_strdup(native_specification); |
---|
| 687 | char * ctxt = NULL; |
---|
| 688 | int opt = 0; |
---|
| 689 | |
---|
| 690 | TRY |
---|
[12] | 691 | { |
---|
[45] | 692 | for (arg = strtok_r((char *)native_spec_copy, " \t", &ctxt); arg; arg = strtok_r(NULL, " \t",&ctxt) ) { |
---|
[12] | 693 | if (!opt) |
---|
| 694 | { |
---|
| 695 | if ( (arg[0] != '-') || (strlen(arg) != 2) ) |
---|
[1] | 696 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
[12] | 697 | "Invalid native specification: -o(ption) expected (arg=%s native=%s).", |
---|
| 698 | arg, native_specification); |
---|
| 699 | |
---|
| 700 | opt = arg[1]; |
---|
| 701 | |
---|
| 702 | /* handle NO-arg options */ |
---|
| 703 | |
---|
| 704 | switch (opt) { |
---|
| 705 | case 'h' : |
---|
| 706 | pbs_attr->set_attr( pbs_attr, "Hold_Types" , "u" ); |
---|
| 707 | break; |
---|
| 708 | default : |
---|
| 709 | continue; /*no NO-ARG option */ |
---|
[1] | 710 | } |
---|
[12] | 711 | |
---|
| 712 | opt = 0; |
---|
| 713 | } |
---|
| 714 | else |
---|
| 715 | { |
---|
[1] | 716 | switch (opt) { |
---|
| 717 | |
---|
| 718 | case 'W' : |
---|
| 719 | parse_additional_attr(pbs_attr, arg); |
---|
| 720 | break; |
---|
| 721 | case 'N' : |
---|
| 722 | pbs_attr->set_attr( pbs_attr, "Job_Name" , arg ); |
---|
| 723 | break; |
---|
| 724 | case 'o' : |
---|
| 725 | pbs_attr->set_attr( pbs_attr, "Output_Path" , arg ); |
---|
| 726 | break; |
---|
| 727 | case 'e' : |
---|
| 728 | pbs_attr->set_attr( pbs_attr, "Error_Path" , arg ); |
---|
| 729 | break; |
---|
| 730 | case 'j' : |
---|
| 731 | pbs_attr->set_attr( pbs_attr, "Join_Path" , arg ); |
---|
| 732 | break; |
---|
| 733 | case 'm' : |
---|
| 734 | pbs_attr->set_attr( pbs_attr, "Mail_Points" , arg ); |
---|
| 735 | break; |
---|
| 736 | case 'a' : |
---|
| 737 | pbs_attr->set_attr( pbs_attr, "Execution_Time" , arg ); |
---|
| 738 | break; |
---|
| 739 | case 'A' : |
---|
| 740 | pbs_attr->set_attr( pbs_attr, "Account_Name" , arg ); |
---|
| 741 | break; |
---|
| 742 | case 'c' : |
---|
| 743 | pbs_attr->set_attr( pbs_attr, "Checkpoint" , arg ); |
---|
| 744 | break; |
---|
| 745 | case 'k' : |
---|
| 746 | pbs_attr->set_attr( pbs_attr, "Keep_Files" , arg ); |
---|
| 747 | break; |
---|
| 748 | case 'p' : |
---|
| 749 | pbs_attr->set_attr( pbs_attr, "Priority" , arg ); |
---|
| 750 | break; |
---|
| 751 | case 'q' : |
---|
[37] | 752 | if (self->destination_queue) |
---|
| 753 | fsd_free(self->destination_queue); |
---|
| 754 | |
---|
[1] | 755 | self->destination_queue = fsd_strdup( arg ); |
---|
[16] | 756 | fsd_log_debug(("self->destination_queue = %s", self->destination_queue)); |
---|
[1] | 757 | break; |
---|
| 758 | case 'r' : |
---|
| 759 | pbs_attr->set_attr( pbs_attr, "Rerunable" , arg ); |
---|
| 760 | break; |
---|
| 761 | case 'S' : |
---|
| 762 | pbs_attr->set_attr( pbs_attr, "Shell_Path_List" , arg ); |
---|
| 763 | break; |
---|
| 764 | case 'u' : |
---|
| 765 | pbs_attr->set_attr( pbs_attr, "User_List" , arg ); |
---|
| 766 | break; |
---|
| 767 | case 'v' : |
---|
| 768 | pbs_attr->set_attr( pbs_attr, "Variable_List" , arg ); |
---|
| 769 | break; |
---|
| 770 | case 'M' : |
---|
| 771 | pbs_attr->set_attr( pbs_attr, "Mail_Users" , arg ); |
---|
| 772 | break; |
---|
| 773 | case 'l' : |
---|
[48] | 774 | parse_resources( self, pbs_attr, arg); |
---|
[1] | 775 | break; |
---|
| 776 | default : |
---|
| 777 | |
---|
| 778 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
| 779 | "Invalid native specification: %s (Unsupported option: -%c)", |
---|
| 780 | native_specification, opt); |
---|
| 781 | } |
---|
| 782 | opt = 0; |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | if (opt) /* option without optarg */ |
---|
| 787 | fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, |
---|
| 788 | "Invalid native specification: %s", |
---|
| 789 | native_specification); |
---|
| 790 | |
---|
| 791 | } |
---|
| 792 | FINALLY |
---|
| 793 | { |
---|
| 794 | #ifndef PBS_PROFESSIONAL |
---|
| 795 | pbs_attr->set_attr( pbs_attr, "submit_args", native_specification); |
---|
| 796 | #endif |
---|
| 797 | args_list->destroy(args_list); |
---|
[45] | 798 | fsd_free((char *)native_spec_copy); |
---|
[1] | 799 | } |
---|
| 800 | END_TRY |
---|
| 801 | } |
---|
| 802 | } |
---|
| 803 | |
---|