extern int sacctmgr_list_account(int argc, char *argv[]) { int rc = SLURM_SUCCESS; slurmdb_account_cond_t *acct_cond = xmalloc(sizeof(slurmdb_account_cond_t)); List acct_list; int i=0, cond_set=0, prev_set=0; ListIterator itr = NULL; ListIterator itr2 = NULL; slurmdb_account_rec_t *acct = NULL; slurmdb_association_rec_t *assoc = NULL; int field_count = 0; print_field_t *field = NULL; List format_list = list_create(slurm_destroy_char); List print_fields_list; /* types are of print_field_t */ acct_cond->with_assocs = with_assoc_flag; 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++; prev_set = _set_cond(&i, argc, argv, acct_cond, format_list); cond_set |= prev_set; } if (exit_code) { slurmdb_destroy_account_cond(acct_cond); list_destroy(format_list); return SLURM_ERROR; } else if (!list_count(format_list)) { slurm_addto_char_list(format_list, "Acc,Des,O"); if (acct_cond->with_assocs) slurm_addto_char_list(format_list, "Cl,ParentN,U,Share,GrpJ,GrpN," "GrpCPUs,GrpMEM,GrpS,GrpWall,GrpCPUMins," "MaxJ,MaxN,MaxCPUs,MaxS,MaxW," "MaxCPUMins,QOS,DefaultQOS"); if (acct_cond->with_coords) slurm_addto_char_list(format_list, "Coord"); } if (!acct_cond->with_assocs && cond_set > 1) { if (!commit_check("You requested options that are only vaild " "when querying with the withassoc option.\n" "Are you sure you want to continue?")) { printf("Aborted\n"); list_destroy(format_list); slurmdb_destroy_account_cond(acct_cond); return SLURM_SUCCESS; } } print_fields_list = sacctmgr_process_format_list(format_list); list_destroy(format_list); if (exit_code) { slurmdb_destroy_account_cond(acct_cond); list_destroy(print_fields_list); return SLURM_ERROR; } acct_list = acct_storage_g_get_accounts(db_conn, my_uid, acct_cond); slurmdb_destroy_account_cond(acct_cond); if (!acct_list) { exit_code=1; fprintf(stderr, " Problem with query.\n"); list_destroy(print_fields_list); return SLURM_ERROR; } itr = list_iterator_create(acct_list); itr2 = list_iterator_create(print_fields_list); print_fields_header(print_fields_list); field_count = list_count(print_fields_list); while((acct = list_next(itr))) { if (acct->assoc_list) { ListIterator itr3 = list_iterator_create(acct->assoc_list); while((assoc = list_next(itr3))) { int curr_inx = 1; while((field = list_next(itr2))) { switch(field->type) { case PRINT_ACCT: field->print_routine( field, acct->name, (curr_inx == field_count)); break; case PRINT_COORDS: field->print_routine( field, acct->coordinators, (curr_inx == field_count)); break; case PRINT_DESC: field->print_routine( field, acct->description, (curr_inx == field_count)); break; case PRINT_ORG: field->print_routine( field, acct->organization, (curr_inx == field_count)); break; default: sacctmgr_print_association_rec( assoc, field, NULL, (curr_inx == field_count)); break; } curr_inx++; } list_iterator_reset(itr2); printf("\n"); } list_iterator_destroy(itr3); } else { int curr_inx = 1; while((field = list_next(itr2))) { switch(field->type) { case PRINT_QOS: field->print_routine( field, NULL, NULL, (curr_inx == field_count)); break; case PRINT_ACCT: field->print_routine( field, acct->name, (curr_inx == field_count)); break; case PRINT_COORDS: field->print_routine( field, acct->coordinators, (curr_inx == field_count)); break; case PRINT_DESC: field->print_routine( field, acct->description, (curr_inx == field_count)); break; case PRINT_ORG: field->print_routine( field, acct->organization, (curr_inx == field_count)); break; default: field->print_routine( field, NULL, (curr_inx == field_count)); break; } curr_inx++; } list_iterator_reset(itr2); printf("\n"); } } list_iterator_destroy(itr2); list_iterator_destroy(itr); list_destroy(acct_list); list_destroy(print_fields_list); return rc; }
extern int sacctmgr_list_association(int argc, char *argv[]) { int rc = SLURM_SUCCESS; slurmdb_association_cond_t *assoc_cond = xmalloc(sizeof(slurmdb_association_cond_t)); List assoc_list = NULL; slurmdb_association_rec_t *assoc = NULL; int i=0; ListIterator itr = NULL; ListIterator itr2 = NULL; char *last_cluster = NULL; List tree_list = NULL; int field_count = 0; print_field_t *field = NULL; List format_list = list_create(slurm_destroy_char); List print_fields_list; /* types are of print_field_t */ 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, assoc_cond, format_list); } if (exit_code) { slurmdb_destroy_association_cond(assoc_cond); list_destroy(format_list); return SLURM_ERROR; } else if (!list_count(format_list)) { slurm_addto_char_list(format_list, "Cluster,Account,User,Part"); if (!assoc_cond->without_parent_limits) slurm_addto_char_list(format_list, "Share,GrpJ,GrpN,GrpCPUs," "GrpS,GrpWall,GrpCPUMins,MaxJ," "MaxN,MaxCPUs,MaxS,MaxW," "MaxCPUMins,QOS,DefaultQOS"); } print_fields_list = sacctmgr_process_format_list(format_list); list_destroy(format_list); if (exit_code) { slurmdb_destroy_association_cond(assoc_cond); list_destroy(print_fields_list); return SLURM_ERROR; } assoc_list = acct_storage_g_get_associations(db_conn, my_uid, assoc_cond); slurmdb_destroy_association_cond(assoc_cond); if (!assoc_list) { exit_code=1; fprintf(stderr, " Error with request: %s\n", slurm_strerror(errno)); list_destroy(print_fields_list); return SLURM_ERROR; } slurmdb_sort_hierarchical_assoc_list(assoc_list); itr = list_iterator_create(assoc_list); itr2 = list_iterator_create(print_fields_list); print_fields_header(print_fields_list); field_count = list_count(print_fields_list); while((assoc = list_next(itr))) { int curr_inx = 1; if (!last_cluster || strcmp(last_cluster, assoc->cluster)) { if (tree_list) { list_flush(tree_list); } else { tree_list = list_create(slurmdb_destroy_print_tree); } last_cluster = assoc->cluster; } while((field = list_next(itr2))) { sacctmgr_print_association_rec( assoc, field, tree_list, (curr_inx == field_count)); curr_inx++; } list_iterator_reset(itr2); printf("\n"); } if (tree_list) list_destroy(tree_list); list_iterator_destroy(itr2); list_iterator_destroy(itr); list_destroy(assoc_list); list_destroy(print_fields_list); tree_display = 0; return rc; }