PageRenderTime 122ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 1ms

/src/plugins/jobcomp/pgsql/pgsql_jobcomp_process.c

https://github.com/cfenoy/slurm
C | 226 lines | 159 code | 19 blank | 48 comment | 19 complexity | 489d3a4062f062c1a4f0a77b4342467a MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * pgsql_jobcomp_process.c - functions the processing of
  3. * information from the pgsql 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 "pgsql_jobcomp_process.h"
  47. static void _do_fdump(PGresult *result, 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,
  53. PQgetvalue(result, lc, i));
  54. i++;
  55. }
  56. return;
  57. }
  58. extern List pgsql_jobcomp_process_get_jobs(slurmdb_job_cond_t *job_cond)
  59. {
  60. char *query = NULL;
  61. char *extra = NULL;
  62. char *tmp = NULL;
  63. char *selected_part = NULL;
  64. slurmdb_selected_step_t *selected_step = NULL;
  65. ListIterator itr = NULL;
  66. int set = 0;
  67. PGresult *result = NULL;
  68. int i;
  69. jobcomp_job_rec_t *job = NULL;
  70. char time_str[32];
  71. time_t temp_time;
  72. List job_list = NULL;
  73. int fdump_flag = 0;
  74. /* we grab the fdump only for the filetxt plug through the
  75. FDUMP_FLAG on the job_cond->duplicates variable. We didn't
  76. add this extra field to the structure since it only applies
  77. to this plugin.
  78. */
  79. if(job_cond) {
  80. fdump_flag = job_cond->duplicates & FDUMP_FLAG;
  81. job_cond->duplicates &= (~FDUMP_FLAG);
  82. }
  83. if(job_cond->step_list && list_count(job_cond->step_list)) {
  84. set = 0;
  85. xstrcat(extra, " where (");
  86. itr = list_iterator_create(job_cond->step_list);
  87. while((selected_step = list_next(itr))) {
  88. if(set)
  89. xstrcat(extra, " || ");
  90. tmp = xstrdup_printf("jobid=%d",
  91. selected_step->jobid);
  92. xstrcat(extra, tmp);
  93. set = 1;
  94. xfree(tmp);
  95. }
  96. list_iterator_destroy(itr);
  97. xstrcat(extra, ")");
  98. }
  99. if(job_cond->partition_list && list_count(job_cond->partition_list)) {
  100. set = 0;
  101. if(extra)
  102. xstrcat(extra, " && (");
  103. else
  104. xstrcat(extra, " where (");
  105. itr = list_iterator_create(job_cond->partition_list);
  106. while((selected_part = list_next(itr))) {
  107. if(set)
  108. xstrcat(extra, " || ");
  109. tmp = xstrdup_printf("partition='%s'",
  110. selected_part);
  111. xstrcat(extra, tmp);
  112. set = 1;
  113. xfree(tmp);
  114. }
  115. list_iterator_destroy(itr);
  116. xstrcat(extra, ")");
  117. }
  118. i = 0;
  119. while(jobcomp_table_fields[i].name) {
  120. if(i)
  121. xstrcat(tmp, ", ");
  122. xstrcat(tmp, jobcomp_table_fields[i].name);
  123. i++;
  124. }
  125. query = xstrdup_printf("select %s from %s", tmp, jobcomp_table);
  126. xfree(tmp);
  127. if(extra) {
  128. xstrcat(query, extra);
  129. xfree(extra);
  130. }
  131. //info("query = %s", query);
  132. if(!(result =
  133. pgsql_db_query_ret(jobcomp_pgsql_db, query))) {
  134. xfree(query);
  135. return NULL;
  136. }
  137. xfree(query);
  138. job_list = list_create(jobcomp_destroy_job);
  139. for (i = 0; i < PQntuples(result); i++) {
  140. if (fdump_flag) {
  141. _do_fdump(result, i);
  142. continue;
  143. }
  144. job = xmalloc(sizeof(jobcomp_job_rec_t));
  145. if(PQgetvalue(result, i, JOBCOMP_REQ_JOBID))
  146. job->jobid =
  147. atoi(PQgetvalue(result, i, JOBCOMP_REQ_JOBID));
  148. job->partition =
  149. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_PARTITION));
  150. temp_time = atoi(PQgetvalue(result, i, 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(PQgetvalue(result, i, 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(PQgetvalue(result, i, JOBCOMP_REQ_UID))
  161. job->uid =
  162. atoi(PQgetvalue(result, i, JOBCOMP_REQ_UID));
  163. job->uid_name =
  164. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_USER_NAME));
  165. if(PQgetvalue(result, i, JOBCOMP_REQ_GID))
  166. job->gid =
  167. atoi(PQgetvalue(result, i, JOBCOMP_REQ_GID));
  168. job->gid_name =
  169. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_GROUP_NAME));
  170. job->jobname =
  171. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_NAME));
  172. job->nodelist =
  173. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_NODELIST));
  174. if(PQgetvalue(result, i, JOBCOMP_REQ_NODECNT))
  175. job->node_cnt =
  176. atoi(PQgetvalue(result, i, JOBCOMP_REQ_NODECNT));
  177. if(PQgetvalue(result, i, JOBCOMP_REQ_STATE)) {
  178. int j = atoi(PQgetvalue(result, i, JOBCOMP_REQ_STATE));
  179. job->state = xstrdup(job_state_string(j));
  180. }
  181. job->timelimit =
  182. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_TIMELIMIT));
  183. if(PQgetvalue(result, i, JOBCOMP_REQ_MAXPROCS))
  184. job->max_procs =
  185. atoi(PQgetvalue(result, i,
  186. JOBCOMP_REQ_MAXPROCS));
  187. job->blockid =
  188. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_BLOCKID));
  189. job->connection =
  190. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_CONNECTION));
  191. job->reboot =
  192. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_REBOOT));
  193. job->rotate =
  194. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_ROTATE));
  195. job->geo =
  196. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_GEOMETRY));
  197. job->bg_start_point =
  198. xstrdup(PQgetvalue(result, i, JOBCOMP_REQ_START));
  199. list_append(job_list, job);
  200. }
  201. PQclear(result);
  202. return job_list;
  203. }
  204. extern int pgsql_jobcomp_process_archive(slurmdb_archive_cond_t *arch_cond)
  205. {
  206. return SLURM_SUCCESS;
  207. }