static struct jobcomp_info * _jobcomp_info_create (struct job_record *job) { enum job_states state; struct jobcomp_info * j = xmalloc (sizeof (*j)); j->jobid = job->job_id; j->uid = job->user_id; j->gid = job->group_id; j->name = xstrdup (job->name); j->array_job_id = job->array_job_id; j->array_task_id = job->array_task_id; if (IS_JOB_RESIZING(job)) { state = JOB_RESIZING; j->jobstate = xstrdup (job_state_string (state)); if (job->resize_time) j->start = job->resize_time; else j->start = job->start_time; j->end = time(NULL); } else { /* Job state will typically have JOB_COMPLETING or JOB_RESIZING * flag set when called. We remove the flags to get the eventual * completion state: JOB_FAILED, JOB_TIMEOUT, etc. */ state = job->job_state & JOB_STATE_BASE; j->jobstate = xstrdup (job_state_string (state)); if (job->resize_time) j->start = job->resize_time; else if (job->start_time > job->end_time) { /* Job cancelled while pending and * expected start time is in the future. */ j->start = 0; } else j->start = job->start_time; j->end = job->end_time; } j->partition = xstrdup (job->partition); if ((job->time_limit == NO_VAL) && job->part_ptr) j->limit = job->part_ptr->max_time; else j->limit = job->time_limit; j->submit = job->details ? job->details->submit_time:job->start_time; j->batch_flag = job->batch_flag; j->nodes = xstrdup (job->nodes); j->nprocs = job->total_cpus; j->nnodes = job->node_cnt; j->account = job->account ? xstrdup (job->account) : NULL; if (job->details && job->details->work_dir) j->work_dir = xstrdup(job->details->work_dir); else j->work_dir = xstrdup("unknown"); if (job->details) { if (job->details->std_in) j->std_in = xstrdup(job->details->std_in); if (job->details->std_out) j->std_out = xstrdup(job->details->std_out); if (job->details->std_err) j->std_err = xstrdup(job->details->std_err); } #ifdef HAVE_BG j->connect_type = select_g_select_jobinfo_xstrdup(job->select_jobinfo, SELECT_PRINT_CONNECTION); j->geometry = select_g_select_jobinfo_xstrdup(job->select_jobinfo, SELECT_PRINT_GEOMETRY); j->blockid = select_g_select_jobinfo_xstrdup(job->select_jobinfo, SELECT_PRINT_BG_ID); #endif return (j); }
extern int slurm_jobcomp_log_record(struct job_record *job_ptr) { int rc = SLURM_SUCCESS; char *usr_str = NULL, *grp_str = NULL, lim_str[32]; char *connect_type = NULL, *reboot = NULL, *rotate = NULL, *geometry = NULL, *start = NULL, *blockid = NULL; enum job_states job_state; char *query = NULL; uint32_t time_limit, start_time, end_time; if(!jobcomp_mysql_conn || mysql_db_ping(jobcomp_mysql_conn) != 0) { char *loc = slurm_get_jobcomp_loc(); if(slurm_jobcomp_set_location(loc) == SLURM_ERROR) { xfree(loc); return SLURM_ERROR; } xfree(loc); } usr_str = _get_user_name(job_ptr->user_id); grp_str = _get_group_name(job_ptr->group_id); if ((job_ptr->time_limit == NO_VAL) && job_ptr->part_ptr) time_limit = job_ptr->part_ptr->max_time; else time_limit = job_ptr->time_limit; if (time_limit == INFINITE) strcpy(lim_str, "UNLIMITED"); else { snprintf(lim_str, sizeof(lim_str), "%lu", (unsigned long) time_limit); } /* Job will typically be COMPLETING when this is called. * We remove the flags to get the eventual completion state: * JOB_FAILED, JOB_TIMEOUT, etc. */ if (IS_JOB_RESIZING(job_ptr)) { job_state = JOB_RESIZING; if (job_ptr->resize_time) start_time = job_ptr->resize_time; else start_time = job_ptr->start_time; end_time = time(NULL); } else { job_state = job_ptr->job_state & JOB_STATE_BASE; if (job_ptr->resize_time) start_time = job_ptr->resize_time; else if (job_ptr->start_time > job_ptr->end_time) { /* Job cancelled while pending and * expected start time is in the future. */ start_time = 0; } else start_time = job_ptr->start_time; end_time = job_ptr->end_time; } connect_type = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_CONNECTION); reboot = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_REBOOT); rotate = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_ROTATE); geometry = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_GEOMETRY); start = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_START); #ifdef HAVE_BG blockid = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_BG_ID); #else blockid = select_g_select_jobinfo_xstrdup(job_ptr->select_jobinfo, SELECT_PRINT_RESV_ID); #endif query = xstrdup_printf( "insert into %s (jobid, uid, user_name, gid, group_name, " "name, state, proc_cnt, partition, timelimit, " "starttime, endtime, nodecnt", jobcomp_table); if(job_ptr->nodes) xstrcat(query, ", nodelist"); if(connect_type) xstrcat(query, ", connect_type"); if(reboot) xstrcat(query, ", reboot"); if(rotate) xstrcat(query, ", rotate"); if(job_ptr->details && (job_ptr->details->max_cpus != NO_VAL)) xstrcat(query, ", maxprocs"); if(geometry) xstrcat(query, ", geometry"); if(start) xstrcat(query, ", start"); if(blockid) xstrcat(query, ", blockid"); xstrfmtcat(query, ") values (%u, %u, '%s', %u, '%s', \"%s\", %d, %u, " "'%s', \"%s\", %u, %u, %u", job_ptr->job_id, job_ptr->user_id, usr_str, job_ptr->group_id, grp_str, job_ptr->name, job_state, job_ptr->total_cpus, job_ptr->partition, lim_str, start_time, end_time, job_ptr->node_cnt); if(job_ptr->nodes) xstrfmtcat(query, ", '%s'", job_ptr->nodes); if(connect_type) { xstrfmtcat(query, ", '%s'", connect_type); xfree(connect_type); } if(reboot) { xstrfmtcat(query, ", '%s'", reboot); xfree(reboot); } if(rotate) { xstrfmtcat(query, ", '%s'", rotate); xfree(rotate); } if(job_ptr->details && (job_ptr->details->max_cpus != NO_VAL)) xstrfmtcat(query, ", '%u'", job_ptr->details->max_cpus); if(geometry) { xstrfmtcat(query, ", '%s'", geometry); xfree(geometry); } if(start) { xstrfmtcat(query, ", '%s'", start); xfree(start); } if(blockid) { xstrfmtcat(query, ", '%s'", blockid); xfree(blockid); } xstrcat(query, ")"); //info("query = %s", query); rc = mysql_db_query(jobcomp_mysql_conn, query); xfree(usr_str); xfree(grp_str); return rc; }