/* * slurm_sprint_reservation_info - output information about a specific Slurm * reservation based upon message as loaded using slurm_load_reservations * IN resv_ptr - an individual reservation information record pointer * IN one_liner - print as a single line if true * RET out - char * containing formatted output (must be freed after call) * NULL is returned on failure. */ char *slurm_sprint_reservation_info ( reserve_info_t * resv_ptr, int one_liner ) { char tmp1[32], tmp2[32], tmp3[32], *flag_str = NULL; char tmp_line[MAXHOSTRANGELEN]; char *out = NULL; uint32_t duration; /****** Line 1 ******/ slurm_make_time_str(&resv_ptr->start_time, tmp1, sizeof(tmp1)); slurm_make_time_str(&resv_ptr->end_time, tmp2, sizeof(tmp2)); duration = difftime(resv_ptr->end_time, resv_ptr->start_time); secs2time_str(duration, tmp3, sizeof(tmp3)); snprintf(tmp_line, sizeof(tmp_line), "ReservationName=%s StartTime=%s EndTime=%s Duration=%s", resv_ptr->name, tmp1, tmp2, tmp3); xstrcat(out, tmp_line); if (one_liner) xstrcat(out, " "); else xstrcat(out, "\n "); /****** Line 2 ******/ flag_str = reservation_flags_string(resv_ptr->flags); snprintf(tmp_line, sizeof(tmp_line), "Nodes=%s NodeCnt=%u Features=%s PartitionName=%s Flags=%s", resv_ptr->node_list, resv_ptr->node_cnt, resv_ptr->features, resv_ptr->partition, flag_str); xfree(flag_str); xstrcat(out, tmp_line); if (one_liner) xstrcat(out, " "); else xstrcat(out, "\n "); /****** Line 3 ******/ snprintf(tmp_line, sizeof(tmp_line), "Users=%s Accounts=%s Licenses=%s", resv_ptr->users, resv_ptr->accounts, resv_ptr->licenses); xstrcat(out, tmp_line); if (one_liner) xstrcat(out, "\n"); else xstrcat(out, "\n\n"); return out; }
static void _update_resv_record(sview_resv_info_t *sview_resv_info_ptr, GtkTreeStore *treestore) { char tmp_duration[40], tmp_end[40], tmp_nodes[40], tmp_start[40]; char *tmp_flags; reserve_info_t *resv_ptr = sview_resv_info_ptr->resv_ptr; secs2time_str((uint32_t)difftime(resv_ptr->end_time, resv_ptr->start_time), tmp_duration, sizeof(tmp_duration)); slurm_make_time_str((time_t *)&resv_ptr->end_time, tmp_end, sizeof(tmp_end)); tmp_flags = reservation_flags_string(resv_ptr->flags); convert_num_unit((float)resv_ptr->node_cnt, tmp_nodes, sizeof(tmp_nodes), UNIT_NONE); slurm_make_time_str((time_t *)&resv_ptr->start_time, tmp_start, sizeof(tmp_start)); /* Combining these records provides a slight performance improvement */ gtk_tree_store_set(treestore, &sview_resv_info_ptr->iter_ptr, SORTID_ACCOUNTS, resv_ptr->accounts, SORTID_COLOR, sview_colors[sview_resv_info_ptr->color_inx], SORTID_COLOR_INX, sview_resv_info_ptr->color_inx, SORTID_DURATION, tmp_duration, SORTID_FEATURES, resv_ptr->features, SORTID_FLAGS, tmp_flags, SORTID_LICENSES, resv_ptr->licenses, SORTID_NAME, resv_ptr->name, SORTID_NODE_CNT, tmp_nodes, SORTID_NODE_INX, resv_ptr->node_inx, SORTID_NODELIST, resv_ptr->node_list, SORTID_PARTITION, resv_ptr->partition, SORTID_TIME_START, tmp_start, SORTID_TIME_END, tmp_end, SORTID_UPDATED, 1, SORTID_USERS, resv_ptr->users, -1); xfree(tmp_flags); return; }
static void _layout_resv_record(GtkTreeView *treeview, sview_resv_info_t *sview_resv_info, int update) { GtkTreeIter iter; char time_buf[20], power_buf[20]; reserve_info_t *resv_ptr = sview_resv_info->resv_ptr; char *temp_char = NULL; GtkTreeStore *treestore = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_ACCOUNTS), resv_ptr->accounts); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_BURST_BUFFER), resv_ptr->burst_buffer); convert_num_unit((float)resv_ptr->core_cnt, time_buf, sizeof(time_buf), UNIT_NONE); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_CORE_CNT), time_buf); secs2time_str((uint32_t)difftime(resv_ptr->end_time, resv_ptr->start_time), time_buf, sizeof(time_buf)); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_DURATION), time_buf); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_FEATURES), resv_ptr->features); temp_char = reservation_flags_string(resv_ptr->flags); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_FLAGS), temp_char); xfree(temp_char); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_LICENSES), resv_ptr->licenses); /* NOTE: node_cnt in reservation info from slurmctld ONE number */ convert_num_unit((float)resv_ptr->node_cnt, time_buf, sizeof(time_buf), UNIT_NONE); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_NODE_CNT), time_buf); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_NODELIST), resv_ptr->node_list); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_PARTITION), resv_ptr->partition); slurm_make_time_str((time_t *)&resv_ptr->end_time, time_buf, sizeof(time_buf)); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_TIME_END), time_buf); slurm_make_time_str((time_t *)&resv_ptr->start_time, time_buf, sizeof(time_buf)); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_TIME_START), time_buf); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_TRES), resv_ptr->tres_str); add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_USERS), resv_ptr->users); if ((resv_ptr->resv_watts == NO_VAL) || (resv_ptr->resv_watts == 0)) { snprintf(power_buf, sizeof(power_buf), "0"); } else if ((resv_ptr->resv_watts % 1000000) == 0) { snprintf(power_buf, sizeof(power_buf), "%uM", resv_ptr->resv_watts / 1000000); } else if ((resv_ptr->resv_watts % 1000) == 0) { snprintf(power_buf, sizeof(power_buf), "%uK", resv_ptr->resv_watts / 1000); } else { snprintf(power_buf, sizeof(power_buf), "%u", resv_ptr->resv_watts); } add_display_treestore_line(update, treestore, &iter, find_col_name(display_data_resv, SORTID_WATTS), power_buf); }
/* * slurm_sprint_reservation_info - output information about a specific Slurm * reservation based upon message as loaded using slurm_load_reservations * IN resv_ptr - an individual reservation information record pointer * IN one_liner - print as a single line if true * RET out - char * containing formatted output (must be freed after call) * NULL is returned on failure. */ char *slurm_sprint_reservation_info ( reserve_info_t * resv_ptr, int one_liner ) { char tmp1[32], tmp2[32], tmp3[32], *flag_str = NULL; char *state="INACTIVE"; char *out = NULL; uint32_t duration; time_t now = time(NULL); uint32_t cluster_flags = slurmdb_setup_cluster_flags(); bool is_bluegene = cluster_flags & CLUSTER_FLAG_BG; char *line_end = (one_liner) ? " " : "\n "; /****** Line 1 ******/ slurm_make_time_str(&resv_ptr->start_time, tmp1, sizeof(tmp1)); slurm_make_time_str(&resv_ptr->end_time, tmp2, sizeof(tmp2)); if (resv_ptr->end_time >= resv_ptr->start_time) { duration = difftime(resv_ptr->end_time, resv_ptr->start_time); secs2time_str(duration, tmp3, sizeof(tmp3)); } else { snprintf(tmp3, sizeof(tmp3), "N/A"); } xstrfmtcat(out, "ReservationName=%s StartTime=%s EndTime=%s Duration=%s", resv_ptr->name, tmp1, tmp2, tmp3); xstrcat(out, line_end); /****** Line 2 ******/ flag_str = reservation_flags_string(resv_ptr->flags); xstrfmtcat(out, "%s=%s %sCnt=%u %sCnt=%u Features=%s " "PartitionName=%s Flags=%s", is_bluegene ? "Midplanes" : "Nodes", resv_ptr->node_list, is_bluegene ? "Midplane" : "Node", (resv_ptr->node_cnt == NO_VAL) ? 0 : resv_ptr->node_cnt, is_bluegene ? "Cnode" : "Core", resv_ptr->core_cnt, resv_ptr->features, resv_ptr->partition, flag_str); xfree(flag_str); xstrcat(out, line_end); /****** Line 3 ******/ xstrfmtcat(out, "TRES=%s", resv_ptr->tres_str); xstrcat(out, line_end); /****** Line 4 ******/ if (resv_ptr->resv_watts != (time_t) NO_VAL) { snprintf(tmp1, 32, "%u", resv_ptr->resv_watts); } else snprintf(tmp1, 32, "n/a"); if ((resv_ptr->start_time <= now) && (resv_ptr->end_time >= now)) state = "ACTIVE"; xstrfmtcat(out, "Users=%s Accounts=%s Licenses=%s State=%s BurstBuffer=%s " "Watts=%s", resv_ptr->users, resv_ptr->accounts, resv_ptr->licenses, state, resv_ptr->burst_buffer, tmp1); if (one_liner) xstrcat(out, "\n"); else xstrcat(out, "\n\n"); return out; }
static void _update_resv_record(sview_resv_info_t *sview_resv_info_ptr, GtkTreeStore *treestore) { char tmp_duration[40], tmp_end[40], tmp_nodes[40], tmp_start[40]; char tmp_cores[40], power_buf[40]; char *tmp_flags; reserve_info_t *resv_ptr = sview_resv_info_ptr->resv_ptr; secs2time_str((uint32_t)difftime(resv_ptr->end_time, resv_ptr->start_time), tmp_duration, sizeof(tmp_duration)); slurm_make_time_str((time_t *)&resv_ptr->end_time, tmp_end, sizeof(tmp_end)); tmp_flags = reservation_flags_string(resv_ptr->flags); convert_num_unit((float)resv_ptr->core_cnt, tmp_cores, sizeof(tmp_cores), UNIT_NONE, NO_VAL, working_sview_config.convert_flags); convert_num_unit((float)resv_ptr->node_cnt, tmp_nodes, sizeof(tmp_nodes), UNIT_NONE, NO_VAL, working_sview_config.convert_flags); slurm_make_time_str((time_t *)&resv_ptr->start_time, tmp_start, sizeof(tmp_start)); if ((resv_ptr->resv_watts == NO_VAL) || (resv_ptr->resv_watts == 0)) { snprintf(power_buf, sizeof(power_buf), "0"); } else if ((resv_ptr->resv_watts % 1000000) == 0) { snprintf(power_buf, sizeof(power_buf), "%uM", resv_ptr->resv_watts / 1000000); } else if ((resv_ptr->resv_watts % 1000) == 0) { snprintf(power_buf, sizeof(power_buf), "%uK", resv_ptr->resv_watts / 1000); } else { snprintf(power_buf, sizeof(power_buf), "%u", resv_ptr->resv_watts); } /* Combining these records provides a slight performance improvement */ gtk_tree_store_set(treestore, &sview_resv_info_ptr->iter_ptr, SORTID_ACCOUNTS, resv_ptr->accounts, SORTID_BURST_BUFFER, resv_ptr->burst_buffer, SORTID_COLOR, sview_colors[sview_resv_info_ptr->color_inx], SORTID_COLOR_INX, sview_resv_info_ptr->color_inx, SORTID_CORE_CNT, tmp_cores, SORTID_DURATION, tmp_duration, SORTID_FEATURES, resv_ptr->features, SORTID_FLAGS, tmp_flags, SORTID_LICENSES, resv_ptr->licenses, SORTID_NAME, resv_ptr->name, SORTID_NODE_CNT, tmp_nodes, SORTID_NODE_INX, resv_ptr->node_inx, SORTID_NODELIST, resv_ptr->node_list, SORTID_PARTITION, resv_ptr->partition, SORTID_TIME_START, tmp_start, SORTID_TIME_END, tmp_end, SORTID_TRES, resv_ptr->tres_str, SORTID_UPDATED, 1, SORTID_USERS, resv_ptr->users, SORTID_WATTS, power_buf, -1); xfree(tmp_flags); return; }
/* sacctmgr_list_reservation() */ int sacctmgr_list_reservation(int argc, char **argv) { List reservation_list; ListIterator itr; ListIterator itr2; List format_list = list_create(slurm_destroy_char); List print_fields_list; slurmdb_reservation_cond_t *reservation_cond = xmalloc(sizeof(slurmdb_reservation_cond_t)); slurmdb_reservation_rec_t *reservation; int field_count, i; print_field_t *field; char *tmp_char; /* If we don't have any arguments make sure we set up the time correctly for just the past day. */ if (argc == 0) { struct tm start_tm; reservation_cond->time_start = time(NULL); if (!slurm_localtime_r(&reservation_cond->time_start, &start_tm)) { fprintf(stderr, " Couldn't get localtime from %ld", (long)reservation_cond->time_start); exit_code = 1; return 0; } start_tm.tm_sec = 0; start_tm.tm_min = 0; start_tm.tm_hour = 0; start_tm.tm_mday--; start_tm.tm_isdst = -1; reservation_cond->time_start = slurm_mktime(&start_tm); } for (i=0; i<argc; i++) { int command_len = strlen(argv[i]); if (!strncasecmp(argv[i], "Where", MAX(command_len, 5)) || !strncasecmp(argv[i], "Set", MAX(command_len, 3))) i++; _set_cond(&i, argc, argv, reservation_cond, format_list); } if (exit_code) { slurmdb_destroy_reservation_cond(reservation_cond); FREE_NULL_LIST(format_list); return SLURM_ERROR; } if (!list_count(format_list)) { /* Append to the format list the fields * we want to print, these are the data structure * members of the type returned by slurmdbd */ slurm_addto_char_list(format_list, "Cluster,Name%15,TRES%30," "TimeStart,TimeEnd"); } reservation_list = acct_storage_g_get_reservations( db_conn, my_uid, reservation_cond); slurmdb_destroy_reservation_cond(reservation_cond); if (!reservation_list) { exit_code=1; fprintf(stderr, " Problem with query.\n"); FREE_NULL_LIST(format_list); return SLURM_ERROR; } /* Process the format list creating a list of * print field_t structures */ print_fields_list = sacctmgr_process_format_list(format_list); FREE_NULL_LIST(format_list); itr = list_iterator_create(reservation_list); itr2 = list_iterator_create(print_fields_list); print_fields_header(print_fields_list); field_count = list_count(print_fields_list); /* For each reservation prints the data structure members */ while ((reservation = list_next(itr))) { while ((field = list_next(itr2))) { switch (field->type) { case PRINT_ASSOC_NAME: field->print_routine( field, reservation->assocs, field_count); break; case PRINT_CLUSTER: field->print_routine( field, reservation->cluster, field_count); break; case PRINT_FLAGS: tmp_char = reservation_flags_string( reservation->flags); field->print_routine( field, tmp_char, field_count); xfree(tmp_char); break; case PRINT_ID: field->print_routine(field, reservation->id, field_count); break; case PRINT_NAME: field->print_routine(field, reservation->name, field_count); break; case PRINT_NODENAME: field->print_routine( field, reservation->nodes, field_count); break; case PRINT_TIMEEND: field->print_routine( field, reservation->time_end, field_count); break; case PRINT_TIMESTART: field->print_routine( field, reservation->time_start, field_count); break; case PRINT_TRES: if (!g_tres_list) { slurmdb_tres_cond_t tres_cond; memset(&tres_cond, 0, sizeof(slurmdb_tres_cond_t)); tres_cond.with_deleted = 1; g_tres_list = slurmdb_tres_get( db_conn, &tres_cond); } tmp_char = slurmdb_make_tres_string_from_simple( reservation->tres_str, g_tres_list); field->print_routine(field, tmp_char, field_count); xfree(tmp_char); break; } } list_iterator_reset(itr2); printf("\n"); } list_iterator_destroy(itr); list_iterator_destroy(itr2); FREE_NULL_LIST(reservation_list); FREE_NULL_LIST(print_fields_list); return 0; }
/* sacctmgr_list_reservation() */ int sacctmgr_list_reservation(int argc, char **argv) { List reservation_list; ListIterator itr; ListIterator itr2; List format_list; List print_fields_list; slurmdb_reservation_cond_t *reservation_cond = xmalloc(sizeof(slurmdb_reservation_cond_t)); slurmdb_reservation_rec_t *reservation; int field_count, i; print_field_t *field; char *tmp_char; /* If we don't have any arguments make sure we set up the * time correctly for just the past day. */ if (argc == 0) { struct tm start_tm; reservation_cond->time_start = time(NULL); if (!slurm_localtime_r(&reservation_cond->time_start, &start_tm)) { fprintf(stderr, " Couldn't get localtime from %ld", (long)reservation_cond->time_start); slurmdb_destroy_reservation_cond(reservation_cond); exit_code = 1; return 0; } start_tm.tm_sec = 0; start_tm.tm_min = 0; start_tm.tm_hour = 0; start_tm.tm_mday--; reservation_cond->time_start = slurm_mktime(&start_tm); } format_list = list_create(slurm_destroy_char); for (i=0; i<argc; i++) { int command_len = strlen(argv[i]); if (!xstrncasecmp(argv[i], "Where", MAX(command_len, 5)) || !xstrncasecmp(argv[i], "Set", MAX(command_len, 3))) i++; _set_cond(&i, argc, argv, reservation_cond, format_list); } if (reservation_cond->nodes && !reservation_cond->cluster_list) { char *cluster_name = slurm_get_cluster_name(); char *warning = xstrdup_printf( "If requesting nodes you must also request the cluster.\nWould you like to use the local cluster of '%s'?", cluster_name); if (!commit_check(warning)) { exit_code = 1; } else { reservation_cond->cluster_list = list_create(slurm_destroy_char); list_append(reservation_cond->cluster_list, cluster_name); cluster_name = NULL; } xfree(warning); xfree(cluster_name); } if (exit_code) { slurmdb_destroy_reservation_cond(reservation_cond); FREE_NULL_LIST(format_list); return SLURM_ERROR; } if (!list_count(format_list)) { /* Append to the format list the fields * we want to print, these are the data structure * members of the type returned by slurmdbd */ slurm_addto_char_list(format_list, "Cluster,Name%15,TRES%30," "TimeStart,TimeEnd,Unused"); } reservation_list = slurmdb_reservations_get( db_conn, reservation_cond); slurmdb_destroy_reservation_cond(reservation_cond); if (!reservation_list) { exit_code=1; fprintf(stderr, " Problem with query.\n"); FREE_NULL_LIST(format_list); return SLURM_ERROR; } /* Process the format list creating a list of * print field_t structures */ print_fields_list = sacctmgr_process_format_list(format_list); FREE_NULL_LIST(format_list); itr = list_iterator_create(reservation_list); itr2 = list_iterator_create(print_fields_list); print_fields_header(print_fields_list); field_count = list_count(print_fields_list); /* For each reservation prints the data structure members */ while ((reservation = list_next(itr))) { while ((field = list_next(itr2))) { switch (field->type) { case PRINT_ASSOC_NAME: field->print_routine( field, reservation->assocs, field_count); break; case PRINT_CLUSTER: field->print_routine( field, reservation->cluster, field_count); break; case PRINT_FLAGS: tmp_char = reservation_flags_string( reservation->flags); field->print_routine( field, tmp_char, field_count); xfree(tmp_char); break; case PRINT_ID: field->print_routine(field, reservation->id, field_count); break; case PRINT_NAME: field->print_routine(field, reservation->name, field_count); break; case PRINT_NODENAME: field->print_routine( field, reservation->nodes, field_count); break; case PRINT_NODEINX: field->print_routine( field, reservation->node_inx, field_count); break; case PRINT_TIMEEND: field->print_routine( field, reservation->time_end, field_count); break; case PRINT_TIMESTART: field->print_routine( field, reservation->time_start, field_count); break; case PRINT_TRES: sacctmgr_initialize_g_tres_list(); tmp_char = slurmdb_make_tres_string_from_simple( reservation->tres_str, g_tres_list, NO_VAL, CONVERT_NUM_UNIT_EXACT, 0, NULL); field->print_routine(field, tmp_char, field_count); xfree(tmp_char); break; case PRINT_UNUSED: field->print_routine( field, reservation->unused_wall, field_count); break; } } list_iterator_reset(itr2); printf("\n"); } list_iterator_destroy(itr); list_iterator_destroy(itr2); FREE_NULL_LIST(reservation_list); FREE_NULL_LIST(print_fields_list); return 0; }