/src/sacctmgr/event_functions.c

https://github.com/cfenoy/slurm · C · 749 lines · 648 code · 54 blank · 47 comment · 210 complexity · 9b5480a7d87b7687991a30df7976c503 MD5 · raw file

  1. /*****************************************************************************\
  2. * event_functions.c - functions dealing with events in the
  3. * accounting system.
  4. *****************************************************************************
  5. * Copyright (C) 2008 Lawrence Livermore National Security.
  6. * Copyright (C) 2002-2007 The Regents of the University of California.
  7. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  8. * Written by Danny Auble <da@llnl.gov>
  9. * CODE-OCEC-09-009. All rights reserved.
  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. #include "src/sacctmgr/sacctmgr.h"
  41. #include "src/common/slurmdbd_defs.h"
  42. #include "src/common/uid.h"
  43. #include <grp.h>
  44. static uint32_t _decode_node_state(char *val)
  45. {
  46. int vallen;
  47. xassert(val);
  48. vallen = strlen(val);
  49. if (!strncasecmp(val, "DRAIN", MAX(vallen, 3)))
  50. return NODE_STATE_DRAIN;
  51. else if (!strncasecmp(val, "FAIL", MAX(vallen, 3)))
  52. return NODE_STATE_FAIL;
  53. else {
  54. uint32_t j;
  55. for (j = 0; j < NODE_STATE_END; j++) {
  56. if (strncasecmp(node_state_string(j), val,
  57. MAX(vallen, 3)) == 0){
  58. return j;
  59. }
  60. }
  61. if (j == NODE_STATE_END) {
  62. exit_code = 1;
  63. fprintf(stderr, "Invalid state: %s\n", val);
  64. fprintf (stderr, "Valid node states are: ");
  65. fprintf (stderr, "DRAIN FAIL ");
  66. for (j = 0; j < NODE_STATE_END; j++) {
  67. fprintf (stderr, "%s ",
  68. node_state_string(j));
  69. }
  70. fprintf (stderr, "\n");
  71. }
  72. }
  73. return NO_VAL;
  74. }
  75. static int _addto_state_char_list(List char_list, char *names)
  76. {
  77. int i=0, start=0;
  78. uint32_t c;
  79. char *name = NULL, *tmp_char = NULL;
  80. ListIterator itr = NULL;
  81. char quote_c = '\0';
  82. int quote = 0;
  83. int count = 0;
  84. if(!char_list) {
  85. error("No list was given to fill in");
  86. return 0;
  87. }
  88. itr = list_iterator_create(char_list);
  89. if(names) {
  90. if (names[i] == '\"' || names[i] == '\'') {
  91. quote_c = names[i];
  92. quote = 1;
  93. i++;
  94. }
  95. start = i;
  96. while(names[i]) {
  97. //info("got %d - %d = %d", i, start, i-start);
  98. if(quote && names[i] == quote_c)
  99. break;
  100. else if (names[i] == '\"' || names[i] == '\'')
  101. names[i] = '`';
  102. else if(names[i] == ',') {
  103. if((i-start) > 0) {
  104. name = xmalloc((i-start+1));
  105. memcpy(name, names+start, (i-start));
  106. c = _decode_node_state(name);
  107. if (c == NO_VAL)
  108. fatal("unrecognized job "
  109. "state value");
  110. xfree(name);
  111. name = xstrdup_printf("%u", c);
  112. while((tmp_char = list_next(itr))) {
  113. if(!strcasecmp(tmp_char, name))
  114. break;
  115. }
  116. if(!tmp_char) {
  117. list_append(char_list, name);
  118. count++;
  119. } else
  120. xfree(name);
  121. list_iterator_reset(itr);
  122. }
  123. i++;
  124. start = i;
  125. if(!names[i]) {
  126. info("There is a problem with "
  127. "your request. It appears you "
  128. "have spaces inside your list.");
  129. break;
  130. }
  131. }
  132. i++;
  133. }
  134. if((i-start) > 0) {
  135. name = xmalloc((i-start)+1);
  136. memcpy(name, names+start, (i-start));
  137. c = _decode_node_state(name);
  138. if (c == NO_VAL)
  139. fatal("unrecognized job state value");
  140. xfree(name);
  141. name = xstrdup_printf("%u", c);
  142. while((tmp_char = list_next(itr))) {
  143. if(!strcasecmp(tmp_char, name))
  144. break;
  145. }
  146. if(!tmp_char) {
  147. list_append(char_list, name);
  148. count++;
  149. } else
  150. xfree(name);
  151. }
  152. }
  153. list_iterator_destroy(itr);
  154. return count;
  155. }
  156. static char *_convert_to_id(char *name, bool gid)
  157. {
  158. if (gid) {
  159. gid_t gid;
  160. if ( gid_from_string( name, &gid ) != 0 ) {
  161. fprintf(stderr, "Invalid group id: %s\n", name);
  162. exit(1);
  163. }
  164. xfree(name);
  165. name = xstrdup_printf( "%d", (int) gid );
  166. } else {
  167. uid_t uid;
  168. if ( uid_from_string( name, &uid ) != 0 ) {
  169. fprintf(stderr, "Invalid user id: %s\n", name);
  170. exit(1);
  171. }
  172. xfree(name);
  173. name = xstrdup_printf( "%d", (int) uid );
  174. }
  175. return name;
  176. }
  177. /* returns number of objects added to list */
  178. static int _addto_id_char_list(List char_list, char *names, bool gid)
  179. {
  180. int i=0, start=0;
  181. char *name = NULL, *tmp_char = NULL;
  182. ListIterator itr = NULL;
  183. char quote_c = '\0';
  184. int quote = 0;
  185. int count = 0;
  186. if(!char_list) {
  187. error("No list was given to fill in");
  188. return 0;
  189. }
  190. itr = list_iterator_create(char_list);
  191. if(names) {
  192. if (names[i] == '\"' || names[i] == '\'') {
  193. quote_c = names[i];
  194. quote = 1;
  195. i++;
  196. }
  197. start = i;
  198. while(names[i]) {
  199. //info("got %d - %d = %d", i, start, i-start);
  200. if(quote && names[i] == quote_c)
  201. break;
  202. else if (names[i] == '\"' || names[i] == '\'')
  203. names[i] = '`';
  204. else if(names[i] == ',') {
  205. if((i-start) > 0) {
  206. name = xmalloc((i-start+1));
  207. memcpy(name, names+start, (i-start));
  208. //info("got %s %d", name, i-start);
  209. name = _convert_to_id( name, gid );
  210. while((tmp_char = list_next(itr))) {
  211. if(!strcasecmp(tmp_char, name))
  212. break;
  213. }
  214. if(!tmp_char) {
  215. list_append(char_list, name);
  216. count++;
  217. } else
  218. xfree(name);
  219. list_iterator_reset(itr);
  220. }
  221. i++;
  222. start = i;
  223. if(!names[i]) {
  224. info("There is a problem with "
  225. "your request. It appears you "
  226. "have spaces inside your list.");
  227. break;
  228. }
  229. }
  230. i++;
  231. }
  232. if((i-start) > 0) {
  233. name = xmalloc((i-start)+1);
  234. memcpy(name, names+start, (i-start));
  235. name = _convert_to_id(name, gid);
  236. while((tmp_char = list_next(itr))) {
  237. if(!strcasecmp(tmp_char, name))
  238. break;
  239. }
  240. if(!tmp_char) {
  241. list_append(char_list, name);
  242. count++;
  243. } else
  244. xfree(name);
  245. }
  246. }
  247. list_iterator_destroy(itr);
  248. return count;
  249. }
  250. static int _set_cond(int *start, int argc, char *argv[],
  251. slurmdb_event_cond_t *event_cond,
  252. List format_list)
  253. {
  254. int i, end = 0;
  255. int set = 0;
  256. int command_len = 0;
  257. int local_cluster_flag = 0;
  258. int all_time_flag = 0;
  259. if(!event_cond->cluster_list)
  260. event_cond->cluster_list = list_create(slurm_destroy_char);
  261. for (i=(*start); i<argc; i++) {
  262. end = parse_option_end(argv[i]);
  263. if(!end)
  264. command_len=strlen(argv[i]);
  265. else {
  266. command_len=end-1;
  267. if (argv[i][end] == '=') {
  268. end++;
  269. }
  270. }
  271. if(!end && !strncasecmp(argv[i], "all_clusters",
  272. MAX(command_len, 5))) {
  273. local_cluster_flag = 1;
  274. } else if(!end && !strncasecmp(argv[i], "all_time",
  275. MAX(command_len, 5))) {
  276. all_time_flag = 1;
  277. } else if(!end && !strncasecmp(argv[i], "where",
  278. MAX(command_len, 5))) {
  279. continue;
  280. } else if(!end || (!strncasecmp (argv[i], "Events",
  281. MAX(command_len, 1)))) {
  282. ListIterator itr = NULL;
  283. List tmp_list = list_create(slurm_destroy_char);
  284. char *temp = NULL;
  285. if(slurm_addto_char_list(tmp_list,
  286. argv[i]+end))
  287. set = 1;
  288. /* check to make sure user gave ints here */
  289. itr = list_iterator_create(tmp_list);
  290. while ((temp = list_next(itr))) {
  291. if(!strncasecmp("Node", temp,
  292. MAX(strlen(temp), 1))) {
  293. if(event_cond->event_type)
  294. event_cond->event_type =
  295. SLURMDB_EVENT_ALL;
  296. else
  297. event_cond->event_type =
  298. SLURMDB_EVENT_NODE;
  299. } else if(!strncasecmp("Cluster", temp,
  300. MAX(strlen(temp), 1))) {
  301. if(event_cond->event_type)
  302. event_cond->event_type =
  303. SLURMDB_EVENT_ALL;
  304. else
  305. event_cond->event_type =
  306. SLURMDB_EVENT_CLUSTER;
  307. } else {
  308. exit_code=1;
  309. fprintf(stderr,
  310. " Unknown event type: '%s' "
  311. "Valid events are Cluster "
  312. "and Node.\n",
  313. temp);
  314. }
  315. }
  316. list_iterator_destroy(itr);
  317. list_destroy(tmp_list);
  318. } else if (!strncasecmp (argv[i], "Clusters",
  319. MAX(command_len, 1))) {
  320. if(!event_cond->cluster_list)
  321. event_cond->cluster_list =
  322. list_create(slurm_destroy_char);
  323. if(slurm_addto_char_list(event_cond->cluster_list,
  324. argv[i]+end))
  325. set = 1;
  326. } else if (!strncasecmp (argv[i], "End", MAX(command_len, 1))) {
  327. event_cond->period_end = parse_time(argv[i]+end, 1);
  328. set = 1;
  329. } else if (!strncasecmp (argv[i], "Format",
  330. MAX(command_len, 1))) {
  331. if(format_list)
  332. slurm_addto_char_list(format_list, argv[i]+end);
  333. } else if (!strncasecmp (argv[i], "MinCpus",
  334. MAX(command_len, 2))) {
  335. if (get_uint(argv[i]+end, &event_cond->cpus_min,
  336. "MinCpus") == SLURM_SUCCESS)
  337. set = 1;
  338. } else if (!strncasecmp (argv[i], "MaxCpus",
  339. MAX(command_len, 2))) {
  340. if (get_uint(argv[i]+end, &event_cond->cpus_max,
  341. "MaxCpus") == SLURM_SUCCESS)
  342. set = 1;
  343. } else if (!strncasecmp (argv[i], "Nodes",
  344. MAX(command_len, 1))) {
  345. if(!event_cond->node_list)
  346. event_cond->node_list =
  347. list_create(slurm_destroy_char);
  348. if(slurm_addto_char_list(event_cond->node_list,
  349. argv[i]+end))
  350. set = 1;
  351. } else if (!strncasecmp (argv[i], "Reason",
  352. MAX(command_len, 1))) {
  353. if(!event_cond->reason_list)
  354. event_cond->reason_list =
  355. list_create(slurm_destroy_char);
  356. if(slurm_addto_char_list(event_cond->reason_list,
  357. argv[i]+end))
  358. set = 1;
  359. } else if (!strncasecmp (argv[i], "Start",
  360. MAX(command_len, 4))) {
  361. event_cond->period_start = parse_time(argv[i]+end, 1);
  362. set = 1;
  363. } else if (!strncasecmp (argv[i], "States",
  364. MAX(command_len, 4))) {
  365. if(!event_cond->state_list)
  366. event_cond->state_list =
  367. list_create(slurm_destroy_char);
  368. if(_addto_state_char_list(event_cond->state_list,
  369. argv[i]+end)) {
  370. event_cond->event_type = SLURMDB_EVENT_NODE;
  371. set = 1;
  372. }
  373. } else if (!strncasecmp (argv[i], "User",
  374. MAX(command_len, 1))) {
  375. if(!event_cond->reason_uid_list)
  376. event_cond->reason_uid_list =
  377. list_create(slurm_destroy_char);
  378. if(_addto_id_char_list(event_cond->reason_uid_list,
  379. argv[i]+end, 0)) {
  380. event_cond->event_type = SLURMDB_EVENT_NODE;
  381. set = 1;
  382. }
  383. } else {
  384. exit_code=1;
  385. fprintf(stderr, " Unknown condition: %s\n", argv[i]);
  386. }
  387. }
  388. (*start) = i;
  389. if(!local_cluster_flag && !list_count(event_cond->cluster_list)) {
  390. char *temp = slurm_get_cluster_name();
  391. if(temp)
  392. list_append(event_cond->cluster_list, temp);
  393. }
  394. if(!all_time_flag && !event_cond->period_start) {
  395. event_cond->period_start = time(NULL);
  396. if(!event_cond->state_list) {
  397. struct tm start_tm;
  398. if(!localtime_r(&event_cond->period_start, &start_tm)) {
  399. fprintf(stderr,
  400. " Couldn't get localtime from %ld",
  401. (long)event_cond->period_start);
  402. exit_code=1;
  403. return 0;
  404. }
  405. start_tm.tm_sec = 0;
  406. start_tm.tm_min = 0;
  407. start_tm.tm_hour = 0;
  408. start_tm.tm_mday--;
  409. start_tm.tm_isdst = -1;
  410. event_cond->period_start = mktime(&start_tm);
  411. }
  412. }
  413. return set;
  414. }
  415. extern int sacctmgr_list_event(int argc, char *argv[])
  416. {
  417. int rc = SLURM_SUCCESS;
  418. slurmdb_event_cond_t *event_cond =
  419. xmalloc(sizeof(slurmdb_event_cond_t));
  420. List event_list = NULL;
  421. slurmdb_event_rec_t *event = NULL;
  422. int i=0;
  423. ListIterator itr = NULL;
  424. ListIterator itr2 = NULL;
  425. char *object = NULL;
  426. int field_count = 0;
  427. print_field_t *field = NULL;
  428. List format_list = list_create(slurm_destroy_char);
  429. List print_fields_list; /* types are of print_field_t */
  430. /* If we don't have any arguments make sure we set up the
  431. time correctly for just the past day.
  432. */
  433. if (argc == 0) {
  434. struct tm start_tm;
  435. event_cond->period_start = time(NULL);
  436. if(!localtime_r(&event_cond->period_start, &start_tm)) {
  437. fprintf(stderr,
  438. " Couldn't get localtime from %ld",
  439. (long)event_cond->period_start);
  440. exit_code=1;
  441. return 0;
  442. }
  443. start_tm.tm_sec = 0;
  444. start_tm.tm_min = 0;
  445. start_tm.tm_hour = 0;
  446. start_tm.tm_mday--;
  447. start_tm.tm_isdst = -1;
  448. event_cond->period_start = mktime(&start_tm);
  449. }
  450. for (i=0; i<argc; i++) {
  451. int command_len = strlen(argv[i]);
  452. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))
  453. || !strncasecmp (argv[i], "Set", MAX(command_len, 3)))
  454. i++;
  455. _set_cond(&i, argc, argv, event_cond, format_list);
  456. }
  457. if(exit_code) {
  458. slurmdb_destroy_event_cond(event_cond);
  459. list_destroy(format_list);
  460. return SLURM_ERROR;
  461. }
  462. print_fields_list = list_create(destroy_print_field);
  463. if(!list_count(format_list)) {
  464. if(event_cond->event_type == SLURMDB_EVENT_CLUSTER)
  465. slurm_addto_char_list(format_list,
  466. "Cluster,Cpus,Start,End,"
  467. "ClusterNodes");
  468. else
  469. slurm_addto_char_list(format_list,
  470. "Cluster,NodeName,Start,"
  471. "End,State,Reason,User");
  472. }
  473. itr = list_iterator_create(format_list);
  474. while((object = list_next(itr))) {
  475. char *tmp_char = NULL;
  476. int command_len = 0;
  477. int newlen = 0;
  478. if((tmp_char = strstr(object, "\%"))) {
  479. newlen = atoi(tmp_char+1);
  480. tmp_char[0] = '\0';
  481. }
  482. command_len = strlen(object);
  483. field = xmalloc(sizeof(print_field_t));
  484. if(!strncasecmp("ClusterNodes", object,
  485. MAX(command_len, 8))) {
  486. field->type = PRINT_CLUSTER_NODES;
  487. field->name = xstrdup("Cluster Nodes");
  488. field->len = 20;
  489. field->print_routine = print_fields_str;
  490. } else if(!strncasecmp("Cluster", object,
  491. MAX(command_len, 1))) {
  492. field->type = PRINT_CLUSTER;
  493. field->name = xstrdup("Cluster");
  494. field->len = 10;
  495. field->print_routine = print_fields_str;
  496. } else if(!strncasecmp("CPUs", object,
  497. MAX(command_len, 2))) {
  498. field->type = PRINT_CPUS;
  499. field->name = xstrdup("CPUs");
  500. field->len = 7;
  501. field->print_routine = print_fields_str;
  502. } else if(!strncasecmp("Duration", object,
  503. MAX(command_len, 2))) {
  504. field->type = PRINT_DURATION;
  505. field->name = xstrdup("Duration");
  506. field->len = 13;
  507. field->print_routine = print_fields_time_from_secs;
  508. } else if(!strncasecmp("End", object, MAX(command_len, 2))) {
  509. field->type = PRINT_END;
  510. field->name = xstrdup("End");
  511. field->len = 19;
  512. field->print_routine = print_fields_date;
  513. } else if(!strncasecmp("EventRaw", object,
  514. MAX(command_len, 6))) {
  515. field->type = PRINT_EVENTRAW;
  516. field->name = xstrdup("EventRaw");
  517. field->len = 8;
  518. field->print_routine = print_fields_uint;
  519. } else if(!strncasecmp("Event", object,
  520. MAX(command_len, 2))) {
  521. field->type = PRINT_EVENT;
  522. field->name = xstrdup("Event");
  523. field->len = 7;
  524. field->print_routine = print_fields_str;
  525. } else if(!strncasecmp("NodeName", object,
  526. MAX(command_len, 1))) {
  527. field->type = PRINT_NODENAME;
  528. field->name = xstrdup("Node Name");
  529. field->len = -15;
  530. field->print_routine = print_fields_str;
  531. } else if(!strncasecmp("Reason", object, MAX(command_len, 1))) {
  532. field->type = PRINT_REASON;
  533. field->name = xstrdup("Reason");
  534. field->len = 30;
  535. field->print_routine = print_fields_str;
  536. } else if(!strncasecmp("Start", object,
  537. MAX(command_len, 1))) {
  538. field->type = PRINT_START;
  539. field->name = xstrdup("Start");
  540. field->len = 19;
  541. field->print_routine = print_fields_date;
  542. } else if(!strncasecmp("StateRaw", object,
  543. MAX(command_len, 6))) {
  544. field->type = PRINT_STATERAW;
  545. field->name = xstrdup("StateRaw");
  546. field->len = 8;
  547. field->print_routine = print_fields_uint;
  548. } else if(!strncasecmp("State", object, MAX(command_len, 1))) {
  549. field->type = PRINT_STATE;
  550. field->name = xstrdup("State");
  551. field->len = 6;
  552. field->print_routine = print_fields_str;
  553. } else if(!strncasecmp("User", object, MAX(command_len, 1))) {
  554. field->type = PRINT_USER;
  555. field->name = xstrdup("User");
  556. field->len = 15;
  557. field->print_routine = print_fields_str;
  558. } else {
  559. exit_code=1;
  560. fprintf(stderr, " Unknown field '%s'\n", object);
  561. xfree(field);
  562. continue;
  563. }
  564. if(newlen)
  565. field->len = newlen;
  566. list_append(print_fields_list, field);
  567. }
  568. list_iterator_destroy(itr);
  569. list_destroy(format_list);
  570. if(exit_code) {
  571. list_destroy(print_fields_list);
  572. return SLURM_ERROR;
  573. }
  574. event_list = acct_storage_g_get_events(db_conn, my_uid, event_cond);
  575. slurmdb_destroy_event_cond(event_cond);
  576. if(!event_list) {
  577. exit_code=1;
  578. fprintf(stderr, " Error with request: %s\n",
  579. slurm_strerror(errno));
  580. list_destroy(print_fields_list);
  581. return SLURM_ERROR;
  582. }
  583. itr = list_iterator_create(event_list);
  584. itr2 = list_iterator_create(print_fields_list);
  585. print_fields_header(print_fields_list);
  586. field_count = list_count(print_fields_list);
  587. while((event = list_next(itr))) {
  588. int curr_inx = 1;
  589. char tmp[20], *tmp_char;
  590. time_t newend = event->period_end;
  591. while((field = list_next(itr2))) {
  592. switch(field->type) {
  593. case PRINT_CLUSTER:
  594. field->print_routine(field, event->cluster,
  595. (curr_inx == field_count));
  596. break;
  597. case PRINT_CLUSTER_NODES:
  598. field->print_routine(
  599. field,
  600. event->cluster_nodes,
  601. (curr_inx == field_count));
  602. break;
  603. case PRINT_CPUS:
  604. convert_num_unit((float)event->cpu_count,
  605. tmp, sizeof(tmp), UNIT_NONE);
  606. field->print_routine(
  607. field,
  608. tmp,
  609. (curr_inx == field_count));
  610. break;
  611. case PRINT_DURATION:
  612. if(!newend)
  613. newend = time(NULL);
  614. field->print_routine(
  615. field,
  616. (uint64_t)(newend
  617. - event->period_start),
  618. (curr_inx == field_count));
  619. break;
  620. case PRINT_END:
  621. field->print_routine(field,
  622. event->period_end,
  623. (curr_inx == field_count));
  624. break;
  625. case PRINT_EVENTRAW:
  626. field->print_routine(field, event->event_type,
  627. (curr_inx == field_count));
  628. break;
  629. case PRINT_EVENT:
  630. if(event->event_type == SLURMDB_EVENT_CLUSTER)
  631. tmp_char = "Cluster";
  632. else if(event->event_type == SLURMDB_EVENT_NODE)
  633. tmp_char = "Node";
  634. else
  635. tmp_char = "Unknown";
  636. field->print_routine(field,
  637. tmp_char,
  638. (curr_inx == field_count));
  639. break;
  640. case PRINT_NODENAME:
  641. field->print_routine(field,
  642. event->node_name,
  643. (curr_inx == field_count));
  644. break;
  645. case PRINT_START:
  646. field->print_routine(field,
  647. event->period_start,
  648. (curr_inx == field_count));
  649. break;
  650. case PRINT_REASON:
  651. field->print_routine(field, event->reason,
  652. (curr_inx == field_count));
  653. break;
  654. case PRINT_STATERAW:
  655. field->print_routine(field, event->state,
  656. (curr_inx == field_count));
  657. break;
  658. case PRINT_STATE:
  659. if(event->event_type == SLURMDB_EVENT_CLUSTER)
  660. tmp_char = NULL;
  661. else
  662. tmp_char = node_state_string_compact(
  663. event->state);
  664. field->print_routine(field,
  665. tmp_char,
  666. (curr_inx == field_count));
  667. break;
  668. case PRINT_USER:
  669. if(event->reason_uid != NO_VAL) {
  670. tmp_char = uid_to_string(
  671. event->reason_uid);
  672. snprintf(tmp, sizeof(tmp), "%s(%u)",
  673. tmp_char, event->reason_uid);
  674. xfree(tmp_char);
  675. } else
  676. memset(tmp, 0, sizeof(tmp));
  677. field->print_routine(field, tmp,
  678. (curr_inx == field_count));
  679. break;
  680. default:
  681. field->print_routine(field, NULL,
  682. (curr_inx == field_count));
  683. break;
  684. }
  685. curr_inx++;
  686. }
  687. list_iterator_reset(itr2);
  688. printf("\n");
  689. }
  690. list_iterator_destroy(itr2);
  691. list_iterator_destroy(itr);
  692. list_destroy(event_list);
  693. list_destroy(print_fields_list);
  694. return rc;
  695. }