PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/plugins/jobcomp/mysql/mysql_jobcomp_process.c

https://github.com/cfenoy/slurm
C | 211 lines | 143 code | 20 blank | 48 comment | 18 complexity | 8e54bde5bf391020ff7a5d72f592ac9a MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * mysql_jobcomp_process.c - functions the processing of
  3. * information from the mysql jobcomp
  4. * storage.
  5. *****************************************************************************
  6. *
  7. * Copyright (C) 2004-2007 The Regents of the University of California.
  8. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  9. * Written by Danny Auble <da@llnl.gov>
  10. *
  11. * This file is part of SLURM, a resource management program.
  12. * For details, see <http://www.schedmd.com/slurmdocs/>.
  13. * Please also read the included file: DISCLAIMER.
  14. *
  15. * SLURM is free software; you can redistribute it and/or modify it under
  16. * the terms of the GNU General Public License as published by the Free
  17. * Software Foundation; either version 2 of the License, or (at your option)
  18. * any later version.
  19. *
  20. * In addition, as a special exception, the copyright holders give permission
  21. * to link the code of portions of this program with the OpenSSL library under
  22. * certain conditions as described in each individual source file, and
  23. * distribute linked combinations including the two. You must obey the GNU
  24. * General Public License in all respects for all of the code used other than
  25. * OpenSSL. If you modify file(s) with this exception, you may extend this
  26. * exception to your version of the file(s), but you are not obligated to do
  27. * so. If you do not wish to do so, delete this exception statement from your
  28. * version. If you delete this exception statement from all source files in
  29. * the program, then also delete it here.
  30. *
  31. * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
  32. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  33. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  34. * details.
  35. *
  36. * You should have received a copy of the GNU General Public License along
  37. * with SLURM; if not, write to the Free Software Foundation, Inc.,
  38. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  39. *
  40. * This file is patterned after jobcomp_linux.c, written by Morris Jette and
  41. * Copyright (C) 2002 The Regents of the University of California.
  42. \*****************************************************************************/
  43. #include <stdlib.h>
  44. #include "src/common/parse_time.h"
  45. #include "src/common/xstring.h"
  46. #include "mysql_jobcomp_process.h"
  47. static void _do_fdump(MYSQL_ROW row, int lc)
  48. {
  49. int i = 0;
  50. printf("\n------- Line %d -------\n", lc);
  51. while(jobcomp_table_fields[i].name) {
  52. printf("%12s: %s\n", jobcomp_table_fields[i].name, row[i]);
  53. i++;
  54. }
  55. return;
  56. }
  57. extern List mysql_jobcomp_process_get_jobs(slurmdb_job_cond_t *job_cond)
  58. {
  59. char *query = NULL;
  60. char *extra = NULL;
  61. char *tmp = NULL;
  62. char *selected_part = NULL;
  63. slurmdb_selected_step_t *selected_step = NULL;
  64. ListIterator itr = NULL;
  65. int set = 0;
  66. MYSQL_RES *result = NULL;
  67. MYSQL_ROW row;
  68. int i;
  69. int lc = 0;
  70. jobcomp_job_rec_t *job = NULL;
  71. char time_str[32];
  72. time_t temp_time;
  73. List job_list = list_create(jobcomp_destroy_job);
  74. int fdump_flag = 0;
  75. /* we grab the fdump only for the filetxt plug through the
  76. FDUMP_FLAG on the job_cond->duplicates variable. We didn't
  77. add this extra field to the structure since it only applies
  78. to this plugin.
  79. */
  80. if(job_cond) {
  81. fdump_flag = job_cond->duplicates & FDUMP_FLAG;
  82. job_cond->duplicates &= (~FDUMP_FLAG);
  83. }
  84. if(job_cond->step_list && list_count(job_cond->step_list)) {
  85. set = 0;
  86. xstrcat(extra, " where (");
  87. itr = list_iterator_create(job_cond->step_list);
  88. while((selected_step = list_next(itr))) {
  89. if(set)
  90. xstrcat(extra, " || ");
  91. tmp = xstrdup_printf("jobid=%d",
  92. selected_step->jobid);
  93. xstrcat(extra, tmp);
  94. set = 1;
  95. xfree(tmp);
  96. }
  97. list_iterator_destroy(itr);
  98. xstrcat(extra, ")");
  99. }
  100. if(job_cond->partition_list && list_count(job_cond->partition_list)) {
  101. set = 0;
  102. if(extra)
  103. xstrcat(extra, " && (");
  104. else
  105. xstrcat(extra, " where (");
  106. itr = list_iterator_create(job_cond->partition_list);
  107. while((selected_part = list_next(itr))) {
  108. if(set)
  109. xstrcat(extra, " || ");
  110. tmp = xstrdup_printf("partition='%s'",
  111. selected_part);
  112. xstrcat(extra, tmp);
  113. set = 1;
  114. xfree(tmp);
  115. }
  116. list_iterator_destroy(itr);
  117. xstrcat(extra, ")");
  118. }
  119. i = 0;
  120. while(jobcomp_table_fields[i].name) {
  121. if(i)
  122. xstrcat(tmp, ", ");
  123. xstrcat(tmp, jobcomp_table_fields[i].name);
  124. i++;
  125. }
  126. query = xstrdup_printf("select %s from %s", tmp, jobcomp_table);
  127. xfree(tmp);
  128. if(extra) {
  129. xstrcat(query, extra);
  130. xfree(extra);
  131. }
  132. //info("query = %s", query);
  133. if(!(result =
  134. mysql_db_query_ret(jobcomp_mysql_conn, query, 0))) {
  135. xfree(query);
  136. list_destroy(job_list);
  137. return NULL;
  138. }
  139. xfree(query);
  140. while((row = mysql_fetch_row(result))) {
  141. lc++;
  142. if (fdump_flag) {
  143. _do_fdump(row, lc);
  144. continue;
  145. }
  146. job = xmalloc(sizeof(jobcomp_job_rec_t));
  147. if(row[JOBCOMP_REQ_JOBID])
  148. job->jobid = atoi(row[JOBCOMP_REQ_JOBID]);
  149. job->partition = xstrdup(row[JOBCOMP_REQ_PARTITION]);
  150. temp_time = atoi(row[JOBCOMP_REQ_STARTTIME]);
  151. slurm_make_time_str(&temp_time,
  152. time_str,
  153. sizeof(time_str));
  154. job->start_time = xstrdup(time_str);
  155. temp_time = atoi(row[JOBCOMP_REQ_ENDTIME]);
  156. slurm_make_time_str(&temp_time,
  157. time_str,
  158. sizeof(time_str));
  159. job->end_time = xstrdup(time_str);
  160. if(row[JOBCOMP_REQ_UID])
  161. job->uid = atoi(row[JOBCOMP_REQ_UID]);
  162. job->uid_name = xstrdup(row[JOBCOMP_REQ_USER_NAME]);
  163. if(row[JOBCOMP_REQ_GID])
  164. job->gid = atoi(row[JOBCOMP_REQ_GID]);
  165. job->gid_name = xstrdup(row[JOBCOMP_REQ_GROUP_NAME]);
  166. job->jobname = xstrdup(row[JOBCOMP_REQ_NAME]);
  167. job->nodelist = xstrdup(row[JOBCOMP_REQ_NODELIST]);
  168. if(row[JOBCOMP_REQ_NODECNT])
  169. job->node_cnt = atoi(row[JOBCOMP_REQ_NODECNT]);
  170. if(row[JOBCOMP_REQ_STATE]) {
  171. i = atoi(row[JOBCOMP_REQ_STATE]);
  172. job->state = xstrdup(job_state_string(i));
  173. }
  174. job->timelimit = xstrdup(row[JOBCOMP_REQ_TIMELIMIT]);
  175. if(row[JOBCOMP_REQ_MAXPROCS])
  176. job->max_procs = atoi(row[JOBCOMP_REQ_MAXPROCS]);
  177. job->connection = xstrdup(row[JOBCOMP_REQ_CONNECTION]);
  178. job->reboot = xstrdup(row[JOBCOMP_REQ_REBOOT]);
  179. job->rotate = xstrdup(row[JOBCOMP_REQ_ROTATE]);
  180. job->geo = xstrdup(row[JOBCOMP_REQ_GEOMETRY]);
  181. job->bg_start_point = xstrdup(row[JOBCOMP_REQ_START]);
  182. job->blockid = xstrdup(row[JOBCOMP_REQ_BLOCKID]);
  183. list_append(job_list, job);
  184. }
  185. mysql_free_result(result);
  186. return job_list;
  187. }
  188. extern int mysql_jobcomp_process_archive(slurmdb_archive_cond_t *arch_cond)
  189. {
  190. return SLURM_SUCCESS;
  191. }