source: branches/slurm-drmaa-1.2.0/slurm_drmaa/job.c @ 37

Revision 37, 19.0 KB checked in by pkopta, 11 years ago (diff)

code cleanup

  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
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
39static void
40slurmdrmaa_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
107static void
108slurmdrmaa_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
215static void
216slurmdrmaa_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
241fsd_job_t *
242slurmdrmaa_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
258void
259slurmdrmaa_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                int n_job /* ~job_step */
265                )
266{
267        fsd_expand_drmaa_ph_t *volatile expand = NULL;
268
269        TRY
270         {
271                expand = fsd_expand_drmaa_ph_new( NULL, NULL, fsd_asprintf("%d",n_job) );
272                slurmdrmaa_job_create( session, jt, envp, expand, job_desc, n_job);
273         }
274        EXCEPT_DEFAULT
275         {
276                fsd_exc_reraise();
277         }
278        FINALLY
279         {
280                if( expand )
281                        expand->destroy( expand );
282         }
283        END_TRY
284}
285
286static char *
287internal_map_file( fsd_expand_drmaa_ph_t *expand, const char *path,
288                bool *host_given, const char *name )
289{
290        const char *p;
291
292        for( p = path;  *p != ':';  p++ )
293                if( *p == '\0' )
294                        fsd_exc_raise_fmt( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT,
295                                                        "invalid format of drmaa_%s_path: missing colon", name );
296        if( host_given )
297                *host_given = ( p != path );
298
299        p++;
300
301        return expand->expand( expand, fsd_strdup(p), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR );
302}
303
304void
305slurmdrmaa_job_create(
306                fsd_drmaa_session_t *session,
307                const fsd_template_t *jt,
308                fsd_environ_t **envp,
309                fsd_expand_drmaa_ph_t *expand,
310                job_desc_msg_t * job_desc,
311                int n_job
312                )
313{
314        const char *input_path_orig = NULL;
315        const char *output_path_orig = NULL;
316        const char *error_path_orig = NULL;
317        char *volatile input_path = NULL;
318        char *volatile output_path = NULL;
319        char *volatile error_path = NULL;
320        bool input_host = false;
321        bool output_host = false;
322        bool error_host = false;
323        bool join_files = false;
324        const char *value;
325        const char *const *vector;
326        const char *job_category = "default";
327       
328        slurmdrmaa_init_job_desc( job_desc );
329
330        slurm_init_job_desc_msg( job_desc );
331       
332        job_desc->user_id = getuid();
333        job_desc->group_id = getgid();
334
335        job_desc->env_size = 0;
336       
337        /* job name */
338        value = jt->get_attr( jt, DRMAA_JOB_NAME );
339        if( value )
340        {
341                job_desc->name = fsd_strdup(value);
342                fsd_log_debug(("# job_name = %s",job_desc->name));
343        }
344       
345        /* job state at submit */
346        value = jt->get_attr( jt, DRMAA_JS_STATE );
347        if( value )
348        {
349                if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_ACTIVE ) )
350                {}
351                else if( 0 == strcmp( value, DRMAA_SUBMISSION_STATE_HOLD ) )
352                {
353                        job_desc->priority = 0;
354                        fsd_log_debug(("# hold = user"));
355                }
356                else
357                {
358                        fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "invalid value of drmaa_js_state attribute" );
359                }
360        }
361       
362        TRY
363        {
364                const char *command = NULL;
365                char *command_expanded = NULL;
366                char *temp_script_old = NULL;
367                char *temp_script = "";
368                const char *const *i;
369                int j;
370
371                /* remote command */
372                command = jt->get_attr( jt, DRMAA_REMOTE_COMMAND );
373                if( command == NULL )
374                        fsd_exc_raise_msg(
375                                        FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES,
376                                        "drmaa_remote_command not set for job template"
377                                        );
378
379                command_expanded = expand->expand( expand, fsd_strdup(command), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD );
380
381                temp_script = fsd_asprintf("#!/bin/bash\n%s",command_expanded);
382                fsd_free(command_expanded);
383
384                /* arguments list */
385                vector = jt->get_v_attr( jt, DRMAA_V_ARGV );
386
387                if( vector )
388                {
389                        for( i = vector, j = 2;  *i;  i++, j++ )
390                        {
391                                char *arg_expanded = expand->expand( expand, fsd_strdup(*i), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD );
392                               
393                                temp_script_old = fsd_strdup(temp_script);
394                               
395                                if (strcmp(temp_script, "") != 0) {
396                                        fsd_free(temp_script);
397                                }
398                                /* add too script */
399                                temp_script = fsd_asprintf("%s '%s'", temp_script_old, arg_expanded);
400                                fsd_free(temp_script_old);
401                                fsd_free(arg_expanded);
402                        }
403                }
404               
405                job_desc->script = fsd_asprintf("%s\n", temp_script);
406                fsd_log_debug(("# Script:\n%s", job_desc->script));
407                fsd_free(temp_script);
408        }
409        END_TRY
410       
411
412        /* start time */
413        value = jt->get_attr( jt, DRMAA_START_TIME );
414        if( value )
415        {
416                job_desc->begin_time = fsd_datetime_parse( value );
417                fsd_log_debug(( "\n  drmaa_start_time: %s -> %ld", value, (long)job_desc->begin_time));
418        }
419
420        /*  propagate all environment variables from submission host */
421        {
422                extern char **environ;
423                char **i;
424                unsigned j = 0;
425
426                for ( i = environ; *i; i++) {
427                        job_desc->env_size++;
428                }
429               
430                fsd_log_debug(("environ env_size = %d",job_desc->env_size));
431                fsd_calloc(job_desc->environment, job_desc->env_size+1, char *);
432               
433                for ( i = environ; *i; i++,j++ ) {
434                        job_desc->environment[j] = fsd_strdup(*i);
435                }
436        }
437
438        /* environment */
439       
440        vector = jt->get_v_attr( jt, DRMAA_V_ENV );
441        if( vector )
442        {
443                const char *const *i;
444                unsigned j = 0;
445                unsigned env_offset = job_desc->env_size;
446
447                for( i = vector;  *i;  i++ )
448                {
449                        job_desc->env_size++;
450                }
451                fsd_log_debug(("jt env_size = %d",job_desc->env_size));
452
453                fsd_log_debug(("# environment ="));
454                fsd_realloc(job_desc->environment, job_desc->env_size+1, char *);
455
456                for( i = vector;  *i;  i++,j++ )
457                {
458                        job_desc->environment[j + env_offset] = fsd_strdup(*i);
459                        fsd_log_debug((" %s", job_desc->environment[j+ env_offset]));
460                }
461         }
462       
463        /* wall clock time hard limit */
464        value = jt->get_attr( jt, DRMAA_WCT_HLIMIT );
465        if (value)
466        {
467                job_desc->time_limit = slurmdrmaa_datetime_parse( value );
468                fsd_log_debug(("# wct_hlimit = %s -> %ld",value, (long int)slurmdrmaa_datetime_parse( value )));
469        }
470
471               
472        /*expand->set(expand, FSD_DRMAA_PH_INCR,fsd_asprintf("%d", n_job));*/ /* set current value */
473        /* TODO: test drmaa_ph_incr */
474        /* job working directory */
475        value = jt->get_attr( jt, DRMAA_WD );
476        if( value )
477        {
478                char *cwd_expanded = expand->expand( expand, fsd_strdup(value), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR );
479
480                expand->set( expand, FSD_DRMAA_PH_WD, fsd_strdup(cwd_expanded));
481
482                fsd_log_debug(("# work_dir = %s",cwd_expanded));
483                job_desc->work_dir = fsd_strdup(cwd_expanded);
484                fsd_free(cwd_expanded);
485        }
486        else
487        {
488                char cwdbuf[4096] = "";
489
490                if ((getcwd(cwdbuf, 4095)) == NULL) {
491                        char errbuf[256] = "InternalError";
492                        (void)strerror_r(errno, errbuf, 256); /*on error the default message would be returned */
493                        fsd_log_error(("getcwd failed: %s", errbuf));
494                        job_desc->work_dir = fsd_strdup(".");
495                } else {
496                        job_desc->work_dir = fsd_strdup(cwdbuf);
497                }
498
499                fsd_log_debug(("work_dir(default:CWD) %s", job_desc->work_dir));
500        }
501
502        TRY
503        {
504                /* input path */
505                input_path_orig = jt->get_attr( jt, DRMAA_INPUT_PATH );
506                if( input_path_orig )
507                {
508                        input_path = internal_map_file( expand, input_path_orig, &input_host,"input" );
509                        fsd_log_debug(( "\n  drmaa_input_path: %s -> %s", input_path_orig, input_path ));
510                }
511
512                /* output path */
513                output_path_orig = jt->get_attr( jt, DRMAA_OUTPUT_PATH );
514                if( output_path_orig )
515                {
516                        output_path = internal_map_file( expand, output_path_orig, &output_host,"output" );
517                        fsd_log_debug(( "\n  drmaa_output_path: %s -> %s", output_path_orig, output_path ));
518                }
519
520                /* error path */
521                error_path_orig = jt->get_attr( jt, DRMAA_ERROR_PATH );
522                if( error_path_orig )
523                {
524                        error_path = internal_map_file( expand, error_path_orig, &error_host,"error" );
525                        fsd_log_debug(( "\n  drmaa_error_path: %s -> %s", error_path_orig, error_path ));
526                }
527
528                /* join files */
529                value = jt->get_attr( jt, DRMAA_JOIN_FILES );
530                if( value )
531                {
532                        if( (value[0] == 'y' || value[0] == 'Y')  &&  value[1] == '\0' )
533                                join_files = true;
534                        else if( (value[0] == 'n' || value[0] == 'N')  &&  value[1] == '\0' )
535                                join_files = false;
536                        else
537                                fsd_exc_raise_msg(
538                                                FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,
539                                                "invalid value of drmaa_join_files attribute" );
540                }
541
542                if( join_files )
543                {
544                        if( output_path == NULL )
545                                fsd_exc_raise_msg(FSD_DRMAA_ERRNO_CONFLICTING_ATTRIBUTE_VALUES, "drmaa_join_files is set and output file is not given" );
546                        if( error_path!=NULL && 0 != strcmp( output_path, error_path ) )
547                                fsd_log_warning(( "Error file was given but will be ignored since drmaa_join_files was set." ));
548
549                        if (error_path)
550                                fsd_free(error_path);
551
552                         error_path = fsd_strdup(output_path);
553                }
554                else
555                {
556                        if( error_path == NULL  &&  output_path )
557                                error_path = fsd_strdup( "/dev/null" );
558                        if( output_path == NULL  &&  error_path )
559                                output_path = fsd_strdup( "/dev/null" );
560                }
561
562
563                /* email addresses to send notifications */
564                vector = jt->get_v_attr( jt, DRMAA_V_EMAIL );
565                if( vector  &&  vector[0] )
566                {
567                        /* only to one email address message may be send */
568                        job_desc->mail_user = fsd_strdup(vector[0]);
569                        job_desc->mail_type = MAIL_JOB_BEGIN | MAIL_JOB_END |  MAIL_JOB_FAIL;
570                        fsd_log_debug(("# mail_user = %s\n",vector[0]));
571                        fsd_log_debug(("# mail_type = %o\n",job_desc->mail_type));
572                        if( vector[1] != NULL )
573                        {
574                                fsd_log_error(( "SLURM only supports one e-mail notification address" ));
575                                fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"SLURM only supports one e-mail notification address");
576                        }
577                }
578
579                /* block email */
580                value = jt->get_attr( jt, DRMAA_BLOCK_EMAIL );
581                if( value )
582                {
583                        bool block;
584                        if( strcmp(value, "0") == 0 )
585                        {
586                                block = true;
587                                fsd_log_debug(("# block_email = true"));
588                                fsd_log_debug(("# mail_user delated"));
589                                fsd_free(job_desc->mail_user);
590                                job_desc->mail_user = NULL;
591                        }
592                        else if( strcmp(value, "1") == 0 )
593                                block = false;
594                        else
595                                fsd_exc_raise_msg(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"invalid value of drmaa_block_email attribute" );
596
597                        if( block && output_path == NULL )
598                        {
599                                fsd_log_debug(( "output path not set and we want to block e-mail, set to /dev/null" ));
600                                output_path = fsd_strdup( "/dev/null" );
601                        }
602                }
603
604                if( input_path )
605                {
606                        job_desc->std_in = fsd_strdup(input_path);
607                        fsd_log_debug(("# input = %s", input_path));
608                }
609
610                if( output_path )
611                {
612                        job_desc->std_out = fsd_strdup(output_path);
613                        fsd_log_debug(("# output = %s", output_path));
614                }
615
616                if( error_path )
617                {
618                        job_desc->std_err = fsd_strdup(error_path);
619                        fsd_log_debug(("# error = %s", error_path));
620                }
621         }
622        FINALLY
623        {
624                fsd_free( input_path );
625                fsd_free( output_path );
626                fsd_free( error_path );
627                input_path = NULL;
628                output_path = NULL;
629                error_path = NULL;
630        }
631        END_TRY                 
632       
633       
634        /* job category */
635        value = jt->get_attr( jt, DRMAA_JOB_CATEGORY );
636        if( value )
637                job_category = value;
638
639        {
640                fsd_conf_option_t *category_value = NULL;
641                category_value = fsd_conf_dict_get( session->job_categories, job_category );
642
643                if( category_value != NULL )
644                {
645                        if( category_value->type != FSD_CONF_STRING )
646                                fsd_exc_raise_fmt(
647                                                FSD_ERRNO_INTERNAL_ERROR,
648                                                "configuration error: job category should be string"
649                                                );
650
651                        fsd_log_debug(("# Job category %s : %s\n",value,category_value->val.string));                   
652                        slurmdrmaa_parse_native(job_desc,category_value->val.string);                   
653                }
654                else
655                {
656                        if( value != NULL )
657                                fsd_exc_raise_fmt(
658                                                FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,
659                                                "invalid job category: %s", job_category
660                                                );
661                }
662        }
663
664    /* set defaults for constraints - ref: slurm.h */
665    fsd_log_debug(("# Setting defaults for tasks and processors" ));
666    job_desc->num_tasks = 1;
667    job_desc->min_cpus = 0;
668    job_desc->cpus_per_task = 0;
669    job_desc->pn_min_cpus = 0;
670
671        /* native specification */
672        value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION );
673        if( value )
674        {
675                fsd_log_debug(("# Native specification: %s\n", value));
676                slurmdrmaa_parse_native(job_desc, value);
677        }
678       
679}
680
681
Note: See TracBrowser for help on using the repository browser.