/src/sacctmgr/problem_functions.c

https://github.com/cfenoy/slurm · C · 240 lines · 176 code · 21 blank · 43 comment · 49 complexity · d2e4351718b74602943e1327b8e9b3dc MD5 · raw file

  1. /*****************************************************************************\
  2. * problem_functions.c - functions dealing with problems in the
  3. * accounting system.
  4. *****************************************************************************
  5. * Copyright (C) 2002-2008 The Regents of the University of California.
  6. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  7. * Written by Danny Auble <da@llnl.gov>
  8. * CODE-OCEC-09-009. All rights reserved.
  9. *
  10. * This file is part of SLURM, a resource management program.
  11. * For details, see <http://www.schedmd.com/slurmdocs/>.
  12. * Please also read the included file: DISCLAIMER.
  13. *
  14. * SLURM is free software; you can redistribute it and/or modify it under
  15. * the terms of the GNU General Public License as published by the Free
  16. * Software Foundation; either version 2 of the License, or (at your option)
  17. * any later version.
  18. *
  19. * In addition, as a special exception, the copyright holders give permission
  20. * to link the code of portions of this program with the OpenSSL library under
  21. * certain conditions as described in each individual source file, and
  22. * distribute linked combinations including the two. You must obey the GNU
  23. * General Public License in all respects for all of the code used other than
  24. * OpenSSL. If you modify file(s) with this exception, you may extend this
  25. * exception to your version of the file(s), but you are not obligated to do
  26. * so. If you do not wish to do so, delete this exception statement from your
  27. * version. If you delete this exception statement from all source files in
  28. * the program, then also delete it here.
  29. *
  30. * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
  31. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  32. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  33. * details.
  34. *
  35. * You should have received a copy of the GNU General Public License along
  36. * with SLURM; if not, write to the Free Software Foundation, Inc.,
  37. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  38. \*****************************************************************************/
  39. #include "src/sacctmgr/sacctmgr.h"
  40. static int _set_cond(int *start, int argc, char *argv[],
  41. slurmdb_association_cond_t *assoc_cond,
  42. List format_list)
  43. {
  44. int i, end = 0;
  45. int set = 0;
  46. int command_len = 0;
  47. for (i=(*start); i<argc; i++) {
  48. end = parse_option_end(argv[i]);
  49. if(!end)
  50. command_len=strlen(argv[i]);
  51. else {
  52. command_len=end-1;
  53. if (argv[i][end] == '=') {
  54. end++;
  55. }
  56. }
  57. if (!end && !strncasecmp (argv[i], "Tree",
  58. MAX(command_len, 4))) {
  59. tree_display = 1;
  60. } else if(!end && !strncasecmp(argv[i], "where",
  61. MAX(command_len, 5))) {
  62. continue;
  63. } else if(!end || !strncasecmp (argv[i], "Ids",
  64. MAX(command_len, 1))
  65. || !strncasecmp (argv[i], "Problems",
  66. MAX(command_len, 2))) {
  67. if(!assoc_cond->id_list)
  68. assoc_cond->id_list =
  69. list_create(slurm_destroy_char);
  70. slurm_addto_char_list(assoc_cond->id_list,
  71. argv[i]+end);
  72. set = 1;
  73. } else if (!strncasecmp (argv[i], "Accounts",
  74. MAX(command_len, 2))
  75. || !strncasecmp (argv[i], "Acct",
  76. MAX(command_len, 4))) {
  77. if(!assoc_cond->acct_list)
  78. assoc_cond->acct_list =
  79. list_create(slurm_destroy_char);
  80. slurm_addto_char_list(assoc_cond->acct_list,
  81. argv[i]+end);
  82. set = 1;
  83. } else if (!strncasecmp (argv[i], "Clusters",
  84. MAX(command_len, 1))) {
  85. if(!assoc_cond->cluster_list)
  86. assoc_cond->cluster_list =
  87. list_create(slurm_destroy_char);
  88. slurm_addto_char_list(assoc_cond->cluster_list,
  89. argv[i]+end);
  90. set = 1;
  91. } else if (!strncasecmp (argv[i], "Format",
  92. MAX(command_len, 1))) {
  93. if(format_list)
  94. slurm_addto_char_list(format_list,
  95. argv[i]+end);
  96. } else if (!strncasecmp (argv[i], "Partitions",
  97. MAX(command_len, 4))) {
  98. if(!assoc_cond->partition_list)
  99. assoc_cond->partition_list =
  100. list_create(slurm_destroy_char);
  101. slurm_addto_char_list(assoc_cond->partition_list,
  102. argv[i]+end);
  103. set = 1;
  104. } else if (!strncasecmp (argv[i], "Users",
  105. MAX(command_len, 1))) {
  106. if(!assoc_cond->user_list)
  107. assoc_cond->user_list =
  108. list_create(slurm_destroy_char);
  109. slurm_addto_char_list(assoc_cond->user_list,
  110. argv[i]+end);
  111. set = 1;
  112. } else {
  113. exit_code = 1;
  114. fprintf(stderr, " Unknown condition: %s\n", argv[i]);
  115. }
  116. }
  117. (*start) = i;
  118. return set;
  119. }
  120. extern int sacctmgr_list_problem(int argc, char *argv[])
  121. {
  122. int rc = SLURM_SUCCESS;
  123. slurmdb_association_cond_t *assoc_cond =
  124. xmalloc(sizeof(slurmdb_association_cond_t));
  125. List assoc_list = NULL;
  126. slurmdb_association_rec_t *assoc = NULL;
  127. int i=0;
  128. ListIterator itr = NULL;
  129. ListIterator itr2 = NULL;
  130. List tree_list = NULL;
  131. int field_count = 0;
  132. print_field_t *field = NULL;
  133. List format_list = list_create(slurm_destroy_char);
  134. List print_fields_list; /* types are of print_field_t */
  135. for (i=0; i<argc; i++) {
  136. int command_len = strlen(argv[i]);
  137. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))
  138. || !strncasecmp (argv[i], "Set", MAX(command_len, 3)))
  139. i++;
  140. _set_cond(&i, argc, argv, assoc_cond, format_list);
  141. }
  142. if(exit_code) {
  143. slurmdb_destroy_association_cond(assoc_cond);
  144. list_destroy(format_list);
  145. return SLURM_ERROR;
  146. } else if(!list_count(format_list))
  147. slurm_addto_char_list(format_list, "Cl,Acct,User,Problem");
  148. print_fields_list = sacctmgr_process_format_list(format_list);
  149. list_destroy(format_list);
  150. if(exit_code) {
  151. slurmdb_destroy_association_cond(assoc_cond);
  152. list_destroy(print_fields_list);
  153. return SLURM_ERROR;
  154. }
  155. assoc_list = acct_storage_g_get_problems(db_conn, my_uid, assoc_cond);
  156. slurmdb_destroy_association_cond(assoc_cond);
  157. if(!assoc_list) {
  158. exit_code=1;
  159. fprintf(stderr, " Error with request: %s\n",
  160. slurm_strerror(errno));
  161. list_destroy(print_fields_list);
  162. return SLURM_ERROR;
  163. }
  164. itr = list_iterator_create(assoc_list);
  165. itr2 = list_iterator_create(print_fields_list);
  166. print_fields_header(print_fields_list);
  167. field_count = list_count(print_fields_list);
  168. while((assoc = list_next(itr))) {
  169. int curr_inx = 1;
  170. while((field = list_next(itr2))) {
  171. switch(field->type) {
  172. case PRINT_ACCT:
  173. field->print_routine(
  174. field,
  175. assoc->acct,
  176. (curr_inx == field_count));
  177. break;
  178. case PRINT_CLUSTER:
  179. field->print_routine(
  180. field,
  181. assoc->cluster,
  182. (curr_inx == field_count));
  183. break;
  184. case PRINT_PROBLEM:
  185. /* make some sort of string here to
  186. print out the problem reported.
  187. Maybe make an array or something
  188. and just print out a standard error.
  189. */
  190. field->print_routine(
  191. field,
  192. slurmdb_problem_str_get(assoc->id),
  193. (curr_inx == field_count));
  194. break;
  195. case PRINT_USER:
  196. field->print_routine(field,
  197. assoc->user,
  198. (curr_inx == field_count));
  199. break;
  200. default:
  201. field->print_routine(
  202. field, NULL,
  203. (curr_inx == field_count));
  204. break;
  205. }
  206. curr_inx++;
  207. }
  208. list_iterator_reset(itr2);
  209. printf("\n");
  210. }
  211. if(tree_list)
  212. list_destroy(tree_list);
  213. list_iterator_destroy(itr2);
  214. list_iterator_destroy(itr);
  215. list_destroy(assoc_list);
  216. list_destroy(print_fields_list);
  217. tree_display = 0;
  218. return rc;
  219. }