extern int sacctmgr_list_problem(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; 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, "Cl,Acct,User,Problem"); 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_problems(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; } 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; while((field = list_next(itr2))) { switch(field->type) { case PRINT_ACCT: field->print_routine( field, assoc->acct, (curr_inx == field_count)); break; case PRINT_CLUSTER: field->print_routine( field, assoc->cluster, (curr_inx == field_count)); break; case PRINT_PROBLEM: /* make some sort of string here to print out the problem reported. Maybe make an array or something and just print out a standard error. */ field->print_routine( field, slurmdb_problem_str_get(assoc->id), (curr_inx == field_count)); break; case PRINT_USER: field->print_routine(field, assoc->user, (curr_inx == field_count)); break; default: field->print_routine( field, NULL, (curr_inx == field_count)); break; } 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; }
extern int sacctmgr_modify_cluster(int argc, char *argv[]) { int rc = SLURM_SUCCESS; int i=0; slurmdb_association_rec_t *assoc = xmalloc(sizeof(slurmdb_association_rec_t)); slurmdb_association_cond_t *assoc_cond = xmalloc(sizeof(slurmdb_association_cond_t)); int cond_set = 0, prev_set = 0, rec_set = 0, set = 0; List ret_list = NULL; uint16_t class_rec = 0; slurmdb_cluster_cond_t cluster_cond; slurmdb_init_association_rec(assoc, 0); assoc_cond->cluster_list = list_create(slurm_destroy_char); assoc_cond->acct_list = list_create(NULL); slurmdb_init_cluster_cond(&cluster_cond, 0); cluster_cond.cluster_list = assoc_cond->cluster_list; for (i=0; i<argc; i++) { int command_len = strlen(argv[i]); if (!strncasecmp(argv[i], "Where", MAX(command_len, 5))) { i++; prev_set = _set_cond(&i, argc, argv, &cluster_cond, NULL); cond_set |= prev_set; } else if (!strncasecmp(argv[i], "Set", MAX(command_len, 3))) { i++; prev_set = _set_rec(&i, argc, argv, NULL, assoc, &class_rec); rec_set |= prev_set; } else { prev_set = _set_cond(&i, argc, argv, &cluster_cond, NULL); cond_set |= prev_set; } } if(!rec_set) { exit_code=1; fprintf(stderr, " You didn't give me anything to set\n"); rc = SLURM_ERROR; goto end_it; } else if(!cond_set) { if(!commit_check("You didn't set any conditions with 'WHERE'.\n" "Are you sure you want to continue?")) { printf("Aborted\n"); rc = SLURM_SUCCESS; goto end_it; } } else if(exit_code) { rc = SLURM_ERROR; goto end_it; } if(cond_set & 1) { List temp_list = NULL; temp_list = acct_storage_g_get_clusters(db_conn, my_uid, &cluster_cond); if(!temp_list) { exit_code=1; fprintf(stderr, " Problem getting clusters from database. " "Contact your admin.\n"); rc = SLURM_ERROR; goto end_it; } else if(!list_count(temp_list)) { fprintf(stderr, " Query didn't return any clusters.\n"); rc = SLURM_ERROR; goto end_it; } /* we are only looking for the clusters returned from this query, so we free the cluster_list and replace it */ if(assoc_cond->cluster_list) list_destroy(assoc_cond->cluster_list); assoc_cond->cluster_list = temp_list; } printf(" Setting\n"); if(rec_set) { printf(" Default Limits =\n"); sacctmgr_print_assoc_limits(assoc); if(class_rec) printf(" Cluster Classification = %s\n", get_classification_str(class_rec)); } list_append(assoc_cond->acct_list, "root"); notice_thread_init(); ret_list = acct_storage_g_modify_associations( db_conn, my_uid, assoc_cond, assoc); if(ret_list && list_count(ret_list)) { char *object = NULL; ListIterator itr = list_iterator_create(ret_list); printf(" Modified cluster defaults for associations...\n"); while((object = list_next(itr))) { printf(" %s\n", object); } list_iterator_destroy(itr); set = 1; } else if(ret_list) { printf(" Nothing modified\n"); } else { exit_code=1; fprintf(stderr, " Error with request: %s\n", slurm_strerror(errno)); rc = SLURM_ERROR; } if(ret_list) list_destroy(ret_list); if(class_rec) { slurmdb_cluster_rec_t cluster_rec; slurmdb_init_cluster_rec(&cluster_rec, 0); /* the class has already returned these clusters so just go with it */ cluster_rec.classification = class_rec; ret_list = acct_storage_g_modify_clusters( db_conn, my_uid, &cluster_cond, &cluster_rec); if(ret_list && list_count(ret_list)) { char *object = NULL; ListIterator itr = list_iterator_create(ret_list); printf(" Modified cluster classifications...\n"); while((object = list_next(itr))) { printf(" %s\n", object); } list_iterator_destroy(itr); set = 1; } else if(ret_list) { printf(" Nothing modified\n"); } else { exit_code=1; fprintf(stderr, " Error with request: %s\n", slurm_strerror(errno)); rc = SLURM_ERROR; } if(ret_list) list_destroy(ret_list); } notice_thread_fini(); if(set) { if(commit_check("Would you like to commit changes?")) acct_storage_g_commit(db_conn, 1); else { printf(" Changes Discarded\n"); acct_storage_g_commit(db_conn, 0); } } end_it: slurmdb_destroy_association_cond(assoc_cond); slurmdb_destroy_association_rec(assoc); 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; }