/* Load current partiton table information into *part_buffer_pptr */ extern int scontrol_load_partitions (partition_info_msg_t **part_buffer_pptr) { int error_code; static uint16_t last_show_flags = 0xffff; uint16_t show_flags = 0; partition_info_msg_t *part_info_ptr = NULL; if (all_flag) show_flags |= SHOW_ALL; if (old_part_info_ptr) { if (last_show_flags != show_flags) old_part_info_ptr->last_update = (time_t) 0; error_code = slurm_load_partitions ( old_part_info_ptr->last_update, &part_info_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg (old_part_info_ptr); else if (slurm_get_errno () == SLURM_NO_CHANGE_IN_DATA) { part_info_ptr = old_part_info_ptr; error_code = SLURM_SUCCESS; if (quiet_flag == -1) printf ("slurm_load_part no change in data\n"); } } else error_code = slurm_load_partitions((time_t) NULL, &part_info_ptr, show_flags); if (error_code == SLURM_SUCCESS) { old_part_info_ptr = part_info_ptr; last_show_flags = show_flags; *part_buffer_pptr = part_info_ptr; } return error_code; }
static hostlist_t _slurm_wcoll_partition (List partitionlist) { int i; char * str; hostlist_t hl = NULL; partition_info_msg_t * msg; partition_info_t * p; ListIterator li; if (slurm_load_partitions((time_t) NULL, &msg, 1) < 0) errx ("Unable to contact slurm controller: %s\n", slurm_strerror (errno)); for (i = 0; i < msg->record_count; i++){ p = &msg->partition_array[i]; if (_partition_requested (partitionlist, p->name)) { hl = _hl_append (hl, p->nodes); /* * Exit when there is no more partitions to search */ if (list_count (partitionlist) == 0) break; } } /* * Anything left in partitionlist wasn't found, emit a warning */ li = list_iterator_create(partitionlist); while ((str = list_next(li))){ err("%p: Warning - partition %s not found\n", str); } slurm_free_partition_info_msg (msg); if (hl) hostlist_uniq (hl); return (hl); }
/* main is used here for module testing purposes only */ int main (int argc, char *argv[]) { static time_t last_update_time = (time_t) NULL; int error_code ; partition_info_msg_t * part_info_ptr = NULL; error_code = slurm_load_partitions (last_update_time, &part_info_ptr, 1); if (error_code) { slurm_perror ("slurm_load_partitions"); return (error_code); } note("Updated at %ld, record count %d\n", (time_t) part_info_ptr->last_update, part_info_ptr->record_count); slurm_print_partition_info_msg (stdout, part_info_ptr, 0); slurm_free_partition_info_msg (part_info_ptr); return (0); }
/* * Determine total node count for named partition. */ static uint32_t _partition_node_count(char *partition_name) { int error_code, i; uint16_t show_flags = 0; uint32_t node_count = 0; partition_info_msg_t *part_info_ptr = NULL; partition_info_t *part_ptr = NULL; error_code = slurm_load_partitions((time_t) NULL, &part_info_ptr, show_flags); if (error_code != SLURM_SUCCESS) { slurm_free_partition_info_msg (part_info_ptr); return NO_VAL; } part_ptr = part_info_ptr->partition_array;; for (i = 0; i < part_info_ptr->record_count; i++) { if (strcmp (partition_name, part_ptr[i].name)) continue; node_count = part_ptr[i].total_nodes; } slurm_free_partition_info_msg (part_info_ptr); return node_count; }
extern void get_slurm_part(void) { int error_code, i, j, recs, count = 0; static partition_info_msg_t *part_info_ptr = NULL; static partition_info_msg_t *new_part_ptr = NULL; partition_info_t part; uint16_t show_flags = 0; bitstr_t *nodes_req = NULL; static uint16_t last_flags = 0; if (params.all_flag) show_flags |= SHOW_ALL; if (part_info_ptr) { if (show_flags != last_flags) part_info_ptr->last_update = 0; error_code = slurm_load_partitions(part_info_ptr->last_update, &new_part_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg(part_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_part_ptr = part_info_ptr; } } else { error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr, show_flags); } last_flags = show_flags; if (error_code) { if (quiet_flag != 1) { if (!params.commandline) { mvwprintw(text_win, main_ycord, 1, "slurm_load_partitions: %s", slurm_strerror(slurm_get_errno())); main_ycord++; } else { printf("slurm_load_partitions: %s\n", slurm_strerror(slurm_get_errno())); } } return; } if (!params.no_header) _print_header_part(); if (new_part_ptr) recs = new_part_ptr->record_count; else recs = 0; if (!params.commandline) if ((recs - text_line_cnt) < (getmaxy(text_win) - 4)) text_line_cnt--; if (params.hl) nodes_req = get_requested_node_bitmap(); for (i = 0; i < recs; i++) { part = new_part_ptr->partition_array[i]; if (nodes_req) { int overlap = 0; bitstr_t *loc_bitmap = bit_alloc(bit_size(nodes_req)); inx2bitstr(loc_bitmap, part.node_inx); overlap = bit_overlap(loc_bitmap, nodes_req); FREE_NULL_BITMAP(loc_bitmap); if (!overlap) continue; } j = 0; while (part.node_inx[j] >= 0) { set_grid_inx(part.node_inx[j], part.node_inx[j + 1], count); j += 2; } if (!params.commandline) { if (i >= text_line_cnt) { part.flags = (int) letters[count%62]; wattron(text_win, COLOR_PAIR(colors[count%6])); _print_text_part(&part, NULL); wattroff(text_win, COLOR_PAIR(colors[count%6])); } } else { part.flags = (int) letters[count%62]; _print_text_part(&part, NULL); } count++; } if (params.commandline && params.iterate) printf("\n"); part_info_ptr = new_part_ptr; return; }
extern void get_bg_part(void) { int error_code, i, recs=0, count = 0, last_count = -1; static partition_info_msg_t *part_info_ptr = NULL; static partition_info_msg_t *new_part_ptr = NULL; static block_info_msg_t *bg_info_ptr = NULL; static block_info_msg_t *new_bg_ptr = NULL; uint16_t show_flags = 0; partition_info_t part; db2_block_info_t *block_ptr = NULL; db2_block_info_t *found_block = NULL; ListIterator itr; List nodelist = NULL; bitstr_t *nodes_req = NULL; if (!(params.cluster_flags & CLUSTER_FLAG_BG)) return; if (params.all_flag) show_flags |= SHOW_ALL; if (part_info_ptr) { error_code = slurm_load_partitions(part_info_ptr->last_update, &new_part_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg(part_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_part_ptr = part_info_ptr; } } else { error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr, show_flags); } if (error_code) { if (quiet_flag != 1) { if (!params.commandline) { mvwprintw(text_win, main_ycord, 1, "slurm_load_partitions: %s", slurm_strerror(slurm_get_errno())); main_ycord++; } else { printf("slurm_load_partitions: %s\n", slurm_strerror(slurm_get_errno())); } } return; } if (bg_info_ptr) { error_code = slurm_load_block_info(bg_info_ptr->last_update, &new_bg_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_block_info_msg(bg_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_bg_ptr = bg_info_ptr; } } else { error_code = slurm_load_block_info((time_t) NULL, &new_bg_ptr, show_flags); } if (error_code) { if (quiet_flag != 1) { if (!params.commandline) { mvwprintw(text_win, main_ycord, 1, "slurm_load_block: %s", slurm_strerror(slurm_get_errno())); main_ycord++; } else { printf("slurm_load_block: %s\n", slurm_strerror(slurm_get_errno())); } } return; } if (block_list) { /* clear the old list */ list_flush(block_list); } else { block_list = list_create(_block_list_del); } if (!params.commandline) if ((new_bg_ptr->record_count - text_line_cnt) < (getmaxy(text_win) - 4)) text_line_cnt--; if (params.hl) nodes_req = get_requested_node_bitmap(); for (i = 0; i < new_bg_ptr->record_count; i++) { if (nodes_req) { int overlap = 0; bitstr_t *loc_bitmap = bit_alloc(bit_size(nodes_req)); inx2bitstr(loc_bitmap, new_bg_ptr->block_array[i].mp_inx); overlap = bit_overlap(loc_bitmap, nodes_req); FREE_NULL_BITMAP(loc_bitmap); if (!overlap) continue; } if (params.io_bit && new_bg_ptr->block_array[i].ionode_str) { int overlap = 0; bitstr_t *loc_bitmap = bit_alloc(bit_size(params.io_bit)); inx2bitstr(loc_bitmap, new_bg_ptr->block_array[i].ionode_inx); overlap = bit_overlap(loc_bitmap, params.io_bit); FREE_NULL_BITMAP(loc_bitmap); if (!overlap) continue; } block_ptr = xmalloc(sizeof(db2_block_info_t)); block_ptr->bg_block_name = xstrdup(new_bg_ptr->block_array[i].bg_block_id); block_ptr->mp_str = xstrdup(new_bg_ptr->block_array[i].mp_str); block_ptr->nodelist = list_create(_nodelist_del); _make_nodelist(block_ptr->mp_str, block_ptr->nodelist); block_ptr->state = new_bg_ptr->block_array[i].state; memcpy(block_ptr->bg_conn_type, new_bg_ptr->block_array[i].conn_type, sizeof(block_ptr->bg_conn_type)); block_ptr->ionode_str = xstrdup(new_bg_ptr->block_array[i].ionode_str); block_ptr->cnode_cnt = new_bg_ptr->block_array[i].cnode_cnt; itr = list_iterator_create(block_list); while ((found_block = (db2_block_info_t*)list_next(itr))) { if (!xstrcmp(block_ptr->mp_str, found_block->mp_str)) { block_ptr->letter_num = found_block->letter_num; break; } } list_iterator_destroy(itr); if (!found_block) { last_count++; _marknodes(block_ptr, last_count); } block_ptr->job_list = list_create(slurm_free_block_job_info); if (new_bg_ptr->block_array[i].job_list) { block_job_info_t *found_job; ListIterator itr = list_iterator_create( new_bg_ptr->block_array[i].job_list); while ((found_job = list_next(itr))) { block_job_info_t *block_job = xmalloc(sizeof(block_job_info_t)); block_job->job_id = found_job->job_id; list_append(block_ptr->job_list, block_job); } list_iterator_destroy(itr); } if (block_ptr->bg_conn_type[0] >= SELECT_SMALL) block_ptr->size = 0; list_append(block_list, block_ptr); } if (!params.no_header) _print_header_part(); if (new_part_ptr) recs = new_part_ptr->record_count; else recs = 0; for (i = 0; i < recs; i++) { part = new_part_ptr->partition_array[i]; if (!part.nodes || (part.nodes[0] == '\0')) continue; /* empty partition */ nodelist = list_create(_nodelist_del); _make_nodelist(part.nodes, nodelist); if (block_list) { itr = list_iterator_create(block_list); while ((block_ptr = (db2_block_info_t*) list_next(itr)) != NULL) { if (_in_slurm_partition(nodelist, block_ptr->nodelist)) { block_ptr->slurm_part_name = xstrdup(part.name); } } list_iterator_destroy(itr); } FREE_NULL_LIST(nodelist); } /* Report the BG Blocks */ if (block_list) { itr = list_iterator_create(block_list); while ((block_ptr = (db2_block_info_t*) list_next(itr)) != NULL) { if (params.commandline) block_ptr->printed = 1; else { if (count>=text_line_cnt) block_ptr->printed = 1; } _print_rest(block_ptr); count++; } list_iterator_destroy(itr); } if (params.commandline && params.iterate) printf("\n"); part_info_ptr = new_part_ptr; bg_info_ptr = new_bg_ptr; return; }
int main() { //=========================================================================================== // Declarations //=========================================================================================== int i,j; int i2,j2; job_info_msg_t *job_ptr; partition_info_msg_t *prt_ptr = NULL; node_info_msg_t *node_ptr = NULL; int err = SLURM_SUCCESS; err = slurm_load_partitions((time_t) NULL, &prt_ptr, 0); err = slurm_load_node((time_t) NULL, &node_ptr, 0); err = slurm_load_jobs((time_t) NULL, &job_ptr, 0); Linked_List_Node* job_llist; struct json_object *partition = json_object_new_object(); struct json_object *node = json_object_new_object(); //=========================================================================================== // Filling hash tables //=========================================================================================== j2 = 0; i2 = 0; //fill node_job hash if (job_ptr->record_count > 0) { for (i = 0; i < job_ptr->record_count; i++) { j2=0; while( job_ptr->job_array[i].node_inx[j2] >= 0){ i2 = 0; for(i2 = job_ptr->job_array[i].node_inx[j2];i2 <= job_ptr->job_array[i].node_inx[j2+1];i2++) { node_job_put(node_ptr->node_array[i2].name,job_ptr -> job_array[i]); } j2+=2; } } } //============================================================================================ // Creating Output in Json //============================================================================================ // create json int total_node_unknown = 0; int total_node_down = 0; int total_node_idle = 0; int total_node_allocated = 0; int current_node_unknown; int current_node_down; int current_node_idle; int current_node_allocated; int current_job_running; int current_job_waiting; int current_job_stopped; if(prt_ptr -> record_count > 0){ for (i = 0; i < prt_ptr->record_count; i++) { current_node_unknown = 0; current_node_down = 0; current_node_idle = 0; current_node_allocated = 0; current_job_running = 0; current_job_waiting = 0; current_job_stopped = 0; int j2=0; while( prt_ptr->partition_array[i].node_inx[j2] >= 0){ int i2 = 0; for(i2 = prt_ptr->partition_array[i].node_inx[j2];i2 <= prt_ptr->partition_array[i].node_inx[j2+1];i2++) { if(node_ptr->node_array[i2].node_state == 5 || node_ptr->node_array[i2].node_state == 3){ total_node_allocated++; current_node_allocated++;} else if(node_ptr->node_array[i2].node_state == 1){ total_node_down++; current_node_down++;} else if(node_ptr->node_array[i2].node_state == 2 || node_ptr->node_array[i2].node_state == 6){ total_node_idle++; current_node_idle++;} else { total_node_unknown++; current_node_unknown++;} job_llist = node_job_get(node_ptr->node_array[i2].name); //get job name while( job_llist != NULL){ if(job_llist->value_job.job_state == 2 || job_llist->value_job.job_state == 8 || job_llist->value_job.job_state == 0) current_job_waiting++; else if(job_llist->value_job.job_state == 1) current_job_running++; else current_job_stopped++; job_llist = job_llist->next; } } j2+=2; } json_object_object_add(node, "Allocated", json_object_new_int(current_node_allocated)); json_object_object_add(node, "Down", json_object_new_int(current_node_down)); json_object_object_add(node, "Idle", json_object_new_int(current_node_idle)); json_object_object_add(node, "Unknown", json_object_new_int(current_node_unknown)); json_object_object_add(node, "Running", json_object_new_int(current_job_running)); json_object_object_add(node, "Wating", json_object_new_int(current_job_waiting)); json_object_object_add(node, "Stopped", json_object_new_int(current_job_stopped)); json_object_object_add(partition, prt_ptr->partition_array[i].name , node); } } node = json_object_new_object(); json_object_object_add(node, "Unknown", json_object_new_int(total_node_unknown)); json_object_object_add(node, "Down", json_object_new_int(total_node_down)); json_object_object_add(node, "Idle", json_object_new_int(total_node_idle)); json_object_object_add(node, "Allocated", json_object_new_int(total_node_allocated)); json_object_object_add(partition, "General", node); printf("Content-type: text/html\n\n%s",json_object_to_json_string(partition)); slurm_free_partition_info_msg(prt_ptr); slurm_free_node_info_msg(node_ptr); return 1; }
/* * _query_server - download the current server state * part_pptr IN/OUT - partition information message * node_pptr IN/OUT - node information message * block_pptr IN/OUT - BlueGene block data * reserv_pptr IN/OUT - reservation information message * clear_old IN - If set, then always replace old data, needed when going * between clusters. * RET zero or error code */ static int _query_server(partition_info_msg_t ** part_pptr, node_info_msg_t ** node_pptr, block_info_msg_t ** block_pptr, reserve_info_msg_t ** reserv_pptr, bool clear_old) { static partition_info_msg_t *old_part_ptr = NULL, *new_part_ptr; static node_info_msg_t *old_node_ptr = NULL, *new_node_ptr; static block_info_msg_t *old_bg_ptr = NULL, *new_bg_ptr; static reserve_info_msg_t *old_resv_ptr = NULL, *new_resv_ptr; int error_code; uint16_t show_flags = 0; int cc; node_info_t *node_ptr; if (params.all_flag) show_flags |= SHOW_ALL; if (old_part_ptr) { if (clear_old) old_part_ptr->last_update = 0; error_code = slurm_load_partitions(old_part_ptr->last_update, &new_part_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg(old_part_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_part_ptr = old_part_ptr; } } else { error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr, show_flags); } if (error_code) { slurm_perror("slurm_load_partitions"); return error_code; } old_part_ptr = new_part_ptr; *part_pptr = new_part_ptr; if (old_node_ptr) { if (clear_old) old_node_ptr->last_update = 0; if (params.node_name_single) { error_code = slurm_load_node_single(&new_node_ptr, params.nodes, show_flags); } else { error_code = slurm_load_node(old_node_ptr->last_update, &new_node_ptr, show_flags); } if (error_code == SLURM_SUCCESS) slurm_free_node_info_msg(old_node_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_node_ptr = old_node_ptr; } } else if (params.node_name_single) { error_code = slurm_load_node_single(&new_node_ptr, params.nodes, show_flags); } else { error_code = slurm_load_node((time_t) NULL, &new_node_ptr, show_flags); } if (error_code) { slurm_perror("slurm_load_node"); return error_code; } old_node_ptr = new_node_ptr; *node_pptr = new_node_ptr; /* Set the node state as NODE_STATE_MIXED. */ for (cc = 0; cc < new_node_ptr->record_count; cc++) { node_ptr = &(new_node_ptr->node_array[cc]); if (IS_NODE_DRAIN(node_ptr)) { /* don't worry about mixed since the * whole node is being drained. */ } else { uint16_t alloc_cpus = 0, err_cpus = 0, idle_cpus; int single_node_cpus = (node_ptr->cpus / g_node_scaling); select_g_select_nodeinfo_get(node_ptr->select_nodeinfo, SELECT_NODEDATA_SUBCNT, NODE_STATE_ALLOCATED, &alloc_cpus); if (params.cluster_flags & CLUSTER_FLAG_BG) { if (!alloc_cpus && (IS_NODE_ALLOCATED(node_ptr) || IS_NODE_COMPLETING(node_ptr))) alloc_cpus = node_ptr->cpus; else alloc_cpus *= single_node_cpus; } idle_cpus = node_ptr->cpus - alloc_cpus; select_g_select_nodeinfo_get(node_ptr->select_nodeinfo, SELECT_NODEDATA_SUBCNT, NODE_STATE_ERROR, &err_cpus); if (params.cluster_flags & CLUSTER_FLAG_BG) err_cpus *= single_node_cpus; idle_cpus -= err_cpus; if ((alloc_cpus && err_cpus) || (idle_cpus && (idle_cpus != node_ptr->cpus))) { node_ptr->node_state &= NODE_STATE_FLAGS; node_ptr->node_state |= NODE_STATE_MIXED; } } } if (old_resv_ptr) { if (clear_old) old_resv_ptr->last_update = 0; error_code = slurm_load_reservations(old_resv_ptr->last_update, &new_resv_ptr); if (error_code == SLURM_SUCCESS) slurm_free_reservation_info_msg(old_resv_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_resv_ptr = old_resv_ptr; } } else { error_code = slurm_load_reservations((time_t) NULL, &new_resv_ptr); } if (error_code) { slurm_perror("slurm_load_reservations"); return error_code; } old_resv_ptr = new_resv_ptr; *reserv_pptr = new_resv_ptr; if (!params.bg_flag) return SLURM_SUCCESS; if (params.cluster_flags & CLUSTER_FLAG_BG) { if (old_bg_ptr) { if (clear_old) old_bg_ptr->last_update = 0; error_code = slurm_load_block_info( old_bg_ptr->last_update, &new_bg_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_block_info_msg(old_bg_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_bg_ptr = old_bg_ptr; } } else { error_code = slurm_load_block_info((time_t) NULL, &new_bg_ptr, show_flags); } } if (error_code) { slurm_perror("slurm_load_block"); return error_code; } old_bg_ptr = new_bg_ptr; *block_pptr = new_bg_ptr; return SLURM_SUCCESS; }
/* * _query_server - download the current server state * part_pptr IN/OUT - partition information message * node_pptr IN/OUT - node information message * block_pptr IN/OUT - BlueGene block data * reserv_pptr IN/OUT - reservation information message * clear_old IN - If set, then always replace old data, needed when going * between clusters. * RET zero or error code */ static int _query_server(partition_info_msg_t ** part_pptr, node_info_msg_t ** node_pptr, block_info_msg_t ** block_pptr, reserve_info_msg_t ** reserv_pptr, bool clear_old) { static partition_info_msg_t *old_part_ptr = NULL, *new_part_ptr; static node_info_msg_t *old_node_ptr = NULL, *new_node_ptr; static block_info_msg_t *old_bg_ptr = NULL, *new_bg_ptr; static reserve_info_msg_t *old_resv_ptr = NULL, *new_resv_ptr; int error_code; uint16_t show_flags = 0; if (params.all_flag) show_flags |= SHOW_ALL; if (old_part_ptr) { if (clear_old) old_part_ptr->last_update = 0; error_code = slurm_load_partitions(old_part_ptr->last_update, &new_part_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg(old_part_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_part_ptr = old_part_ptr; } } else { error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr, show_flags); } if (error_code) { slurm_perror("slurm_load_partitions"); return error_code; } old_part_ptr = new_part_ptr; *part_pptr = new_part_ptr; if (old_node_ptr) { if (clear_old) old_node_ptr->last_update = 0; if (params.node_name_single) { error_code = slurm_load_node_single(&new_node_ptr, params.nodes, show_flags); } else { error_code = slurm_load_node(old_node_ptr->last_update, &new_node_ptr, show_flags); } if (error_code == SLURM_SUCCESS) slurm_free_node_info_msg(old_node_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_node_ptr = old_node_ptr; } } else if (params.node_name_single) { error_code = slurm_load_node_single(&new_node_ptr, params.nodes, show_flags); } else { error_code = slurm_load_node((time_t) NULL, &new_node_ptr, show_flags); } if (error_code) { slurm_perror("slurm_load_node"); return error_code; } old_node_ptr = new_node_ptr; *node_pptr = new_node_ptr; if (old_resv_ptr) { if (clear_old) old_resv_ptr->last_update = 0; error_code = slurm_load_reservations(old_resv_ptr->last_update, &new_resv_ptr); if (error_code == SLURM_SUCCESS) slurm_free_reservation_info_msg(old_resv_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_resv_ptr = old_resv_ptr; } } else { error_code = slurm_load_reservations((time_t) NULL, &new_resv_ptr); } if (error_code) { slurm_perror("slurm_load_reservations"); return error_code; } old_resv_ptr = new_resv_ptr; *reserv_pptr = new_resv_ptr; if (!params.bg_flag) return SLURM_SUCCESS; if (params.cluster_flags & CLUSTER_FLAG_BG) { if (old_bg_ptr) { if (clear_old) old_bg_ptr->last_update = 0; error_code = slurm_load_block_info( old_bg_ptr->last_update, &new_bg_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_block_info_msg(old_bg_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_bg_ptr = old_bg_ptr; } } else { error_code = slurm_load_block_info((time_t) NULL, &new_bg_ptr, show_flags); } } if (error_code) { slurm_perror("slurm_load_block"); return error_code; } old_bg_ptr = new_bg_ptr; *block_pptr = new_bg_ptr; return SLURM_SUCCESS; }
int get_batch_queues(bridge_batch_manager_t* p_batch_manager, bridge_batch_queue_t** p_p_batch_queues, int* p_batch_queues_nb, char* batch_queue_name) { int fstatus=-1; int i,j; int queue_nb=0; int stored_queue_nb=0; bridge_batch_queue_t* bn; partition_info_msg_t* ppim; partition_info_t* ppi; job_info_msg_t* pjim; job_info_t* pji; node_info_msg_t* pnim; node_info_t* pni; /* get slurm partition infos */ if (slurm_load_partitions(0,&ppim,SHOW_ALL) != 0) { DEBUG3_LOGGER("unable to get slurm partitions infos"); ppim=NULL; goto exit; } /* get nodes status */ if(slurm_load_node(0,&pnim,SHOW_ALL)) { DEBUG3_LOGGER("unable to get nodes informations"); slurm_free_partition_info_msg(ppim); pnim=NULL; goto exit; } /* get slurm job infos */ if (slurm_load_jobs(0,&pjim,SHOW_ALL) != 0) { DEBUG3_LOGGER("unable to get allocations informations"); slurm_free_partition_info_msg(ppim); slurm_free_node_info_msg(pnim); goto exit; } /* build/initialize storage structures */ queue_nb = ppim->record_count; if (*p_p_batch_queues != NULL) { if (*p_batch_queues_nb < queue_nb) queue_nb=*p_batch_queues_nb; } else { *p_p_batch_queues = (bridge_batch_queue_t*) malloc(queue_nb*(sizeof(bridge_batch_queue_t)+1)); if (*p_p_batch_queues == NULL) { *p_batch_queues_nb = 0; queue_nb = *p_batch_queues_nb; } else { *p_batch_queues_nb = queue_nb; } } stored_queue_nb=0; /* fill queue structures */ for (i=0; i<ppim->record_count && stored_queue_nb<queue_nb; i++) { /* get partition pointer */ ppi=ppim->partition_array+i; if (ppi->name == NULL) continue; /* queue name filter */ if (batch_queue_name != NULL && strcmp(batch_queue_name,ppi->name) != 0) continue; bn = &(*p_p_batch_queues)[stored_queue_nb]; /* put default values */ init_batch_queue(p_batch_manager,bn); /* queue Name */ bn->name=strdup(ppi->name); bn->default_queue = (uint32_t) ( ppi->flags | PART_FLAG_DEFAULT); bn->priority = (uint32_t) ppi->priority; /* queue activity */ if(ppi->state_up == PARTITION_UP) { bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_ACTIVE ; bn->state = BRIDGE_BATCH_QUEUE_STATE_OPENED ; } else if (ppi->state_up == PARTITION_DRAIN) { bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_ACTIVE ; bn->state = BRIDGE_BATCH_QUEUE_STATE_CLOSED ; } else if (ppi->state_up == PARTITION_DOWN) { bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_INACTIVE ; bn->state = BRIDGE_BATCH_QUEUE_STATE_OPENED ; } else if (ppi->state_up == PARTITION_INACTIVE) { bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_INACTIVE ; bn->state = BRIDGE_BATCH_QUEUE_STATE_CLOSED ; } else { bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_UNKNOWN ; bn->state = BRIDGE_BATCH_QUEUE_STATE_UNKNOWN ; } /* max times */ if ( ppi->max_time != INFINITE ) bn->seq_time_max = (uint32_t) ppi->max_time * 60 ; else bn->seq_time_max = NO_LIMIT; bn->par_time_max = bn->seq_time_max ; /* slurm */ for ( j=0 ; j < pjim->record_count ; j++ ) { pji=pjim->job_array+j; if ( strcmp(pji->partition,ppi->name) != 0 ) continue; switch ( pji->job_state & JOB_STATE_BASE ) { case JOB_PENDING : bn->jobs_nb++; bn->pending_jobs_nb++; break; case JOB_RUNNING : bn->jobs_nb++; bn->running_jobs_nb++; break; case JOB_SUSPENDED : bn->jobs_nb++; bn->syssuspended_jobs_nb++; break; } } /* Slurm does not provide information about Min and Max cpus per * partition. So we use the following method : * * if partition->name ~= /.*_seq/ min=max=1 * otherwise, calculate it using MinNodes, MaxNodes and nodes * informations */ int done = 0 ; char * p; p = rindex(ppi->name,'_'); if ( p != NULL ) { if ( strcmp(p+1,"seq") == 0 ) { done = 1; bn->par_cores_nb_min = 1; bn->par_cores_nb_max = 1; } } if ( ! done ) { /* use partition nodes information to build the min and max */ /* number of cores (only min and max nodes number are provided */ /* by slurm so we have to build this information) */ uint32_t max_cpus_per_node=0; uint32_t min_cpus_per_node=-1; bridge_nodelist_t list1,list2; bridge_nodelist_init(&list1,NULL,0); bridge_nodelist_add_nodes(&list1,ppi->nodes); for ( j=0 ; j < pnim->record_count ; j++ ) { pni=pnim->node_array+j; bridge_nodelist_init(&list2,NULL,0); bridge_nodelist_add_nodes(&list2,pni->name); if(bridge_nodelist_intersects(&list1,&list2)==0) { bridge_nodelist_free_contents(&list2); continue; } if ( pni->cpus > max_cpus_per_node ) max_cpus_per_node = pni->cpus ; if ( pni->cpus < min_cpus_per_node ) min_cpus_per_node = pni->cpus ; bridge_nodelist_free_contents(&list2); } bridge_nodelist_free_contents(&list1); if ( max_cpus_per_node > 0 && ppi->max_nodes != INFINITE ) bn->par_cores_nb_max = max_cpus_per_node * ppi->max_nodes ; if ( min_cpus_per_node < (uint32_t) -1 && ppi->min_nodes > 1 ) bn->par_cores_nb_min = min_cpus_per_node * ppi->min_nodes ; } stored_queue_nb++; } fstatus=0; /* free slurm informations */ slurm_free_job_info_msg(pjim); slurm_free_node_info_msg(pnim); slurm_free_partition_info_msg(ppim); if(stored_queue_nb<queue_nb) { *p_p_batch_queues=(bridge_batch_queue_t*) realloc(*p_p_batch_queues, stored_queue_nb*(sizeof(bridge_batch_queue_t)+1)); if(*p_p_batch_queues==NULL) *p_batch_queues_nb=0; else *p_batch_queues_nb=stored_queue_nb; } exit: return fstatus; }