Exemplo n.º 1
0
extern int sacctmgr_modify_account(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_account_cond_t *acct_cond =
        xmalloc(sizeof(slurmdb_account_cond_t));
    slurmdb_account_rec_t *acct = xmalloc(sizeof(slurmdb_account_rec_t));
    slurmdb_association_rec_t *assoc =
        xmalloc(sizeof(slurmdb_association_rec_t));

    int i=0;
    int cond_set = 0, prev_set = 0, rec_set = 0, set = 0;
    List ret_list = NULL;

    slurmdb_init_association_rec(assoc, 0);

    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, acct_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, NULL,
                                acct, assoc);
            rec_set |= prev_set;
        } else {
            prev_set = _set_cond(&i, argc, argv, acct_cond, NULL);
            cond_set |= prev_set;
        }
    }

    if (exit_code) {
        slurmdb_destroy_account_cond(acct_cond);
        slurmdb_destroy_account_rec(acct);
        slurmdb_destroy_association_rec(assoc);
        return SLURM_ERROR;
    } else if (!rec_set) {
        exit_code=1;
        fprintf(stderr, " You didn't give me anything to set\n");
        slurmdb_destroy_account_cond(acct_cond);
        slurmdb_destroy_account_rec(acct);
        slurmdb_destroy_association_rec(assoc);
        return SLURM_ERROR;
    } 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");
            slurmdb_destroy_account_cond(acct_cond);
            slurmdb_destroy_account_rec(acct);
            slurmdb_destroy_association_rec(assoc);
            return SLURM_SUCCESS;
        }
    }

    // Special case:  reset raw usage only
    if (assoc->usage) {
        rc = SLURM_ERROR;
        if (assoc->usage->usage_raw == 0.0)
            rc = sacctmgr_remove_assoc_usage(acct_cond->assoc_cond);
        else
            error("Raw usage can only be set to 0 (zero)");

        slurmdb_destroy_account_cond(acct_cond);
        slurmdb_destroy_account_rec(acct);
        slurmdb_destroy_association_rec(assoc);
        return rc;
    }

    notice_thread_init();
    if (rec_set & 1) { // process the account changes
        if (cond_set == 2) {
            exit_code=1;
            fprintf(stderr,
                    " There was a problem with your "
                    "'where' options.\n");
            rc = SLURM_ERROR;
            goto assoc_start;
        }
        ret_list = acct_storage_g_modify_accounts(
                       db_conn, my_uid, acct_cond, acct);
        if (ret_list && list_count(ret_list)) {
            char *object = NULL;
            ListIterator itr = list_iterator_create(ret_list);
            printf(" Modified accounts...\n");
            while((object = list_next(itr))) {
                printf("  %s\n", object);
            }
            list_iterator_destroy(itr);
            set = 1;
        } else if (ret_list) {
            printf(" Nothing modified\n");
            rc = SLURM_ERROR;
        } else {
            exit_code=1;
            fprintf(stderr, " Error with request: %s\n",
                    slurm_strerror(errno));

            rc = SLURM_ERROR;
        }

        if (ret_list)
            list_destroy(ret_list);
    }

assoc_start:
    if (rec_set == 3 || rec_set == 2) { // process the association changes
        if (cond_set == 1 && !acct_cond->assoc_cond->acct_list) {
            rc = SLURM_ERROR;
            exit_code=1;
            fprintf(stderr,
                    " There was a problem with your "
                    "'where' options.\n");
            goto assoc_end;
        }

        if (assoc->parent_acct) {
            slurmdb_account_rec_t *acct_rec =
                sacctmgr_find_account(assoc->parent_acct);
            if (!acct_rec) {
                exit_code=1;
                fprintf(stderr,
                        " Parent Account %s doesn't exist.\n",
                        assoc->parent_acct);
                rc = SLURM_ERROR;
                goto assoc_end;
            }
        }

        ret_list = acct_storage_g_modify_associations(
                       db_conn, my_uid, acct_cond->assoc_cond, assoc);

        if (ret_list && list_count(ret_list)) {
            set = 1;
            if (assoc->def_qos_id != NO_VAL)
                set = sacctmgr_check_default_qos(
                          assoc->def_qos_id,
                          acct_cond->assoc_cond);
            else if (assoc->qos_list)
                set = sacctmgr_check_default_qos(
                          -1, acct_cond->assoc_cond);

            if (set) {
                char *object = NULL;
                ListIterator itr = list_iterator_create(
                                       ret_list);
                printf(" Modified account 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");
            rc = SLURM_ERROR;
        } else {
            exit_code=1;
            fprintf(stderr, " Error with request: %s\n",
                    slurm_strerror(errno));

            rc = SLURM_ERROR;
        }

        if (ret_list)
            list_destroy(ret_list);
    }

assoc_end:

    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);
        }
    }
    slurmdb_destroy_account_cond(acct_cond);
    slurmdb_destroy_account_rec(acct);
    slurmdb_destroy_association_rec(assoc);

    return rc;
}
Exemplo n.º 2
0
extern int sacctmgr_delete_account(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_account_cond_t *acct_cond =
        xmalloc(sizeof(slurmdb_account_cond_t));
    int i=0;
    List ret_list = NULL, local_assoc_list = NULL;
    ListIterator itr = NULL;
    int cond_set = 0, prev_set = 0;

    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, NULL);
        cond_set |= prev_set;
    }

    if (!cond_set) {
        exit_code=1;
        fprintf(stderr,
                " No conditions given to remove, not executing.\n");
        slurmdb_destroy_account_cond(acct_cond);
        return SLURM_ERROR;
    }

    if (exit_code) {
        slurmdb_destroy_account_cond(acct_cond);
        return SLURM_ERROR;
    }
    /* check to see if person is trying to remove root account.  This is
     * bad, and should not be allowed outside of deleting a cluster.
     */
    if (acct_cond->assoc_cond
            && acct_cond->assoc_cond->acct_list
            && list_count(acct_cond->assoc_cond->acct_list)) {
        char *tmp_char = NULL;
        itr = list_iterator_create(acct_cond->assoc_cond->acct_list);
        while((tmp_char = list_next(itr))) {
            if (!strcasecmp(tmp_char, "root"))
                break;
        }
        list_iterator_destroy(itr);
        if (tmp_char) {
            exit_code=1;
            fprintf(stderr, " You are not allowed to remove "
                    "the root account.\n"
                    " Use remove cluster instead.\n");
            slurmdb_destroy_account_cond(acct_cond);
            return SLURM_ERROR;
        }
    }

    acct_cond->assoc_cond->only_defs = 1;
    local_assoc_list = acct_storage_g_get_associations(
                           db_conn, my_uid, acct_cond->assoc_cond);
    acct_cond->assoc_cond->only_defs = 0;

    notice_thread_init();
    if (cond_set == 1) {
        ret_list = acct_storage_g_remove_accounts(
                       db_conn, my_uid, acct_cond);
    } else if (cond_set & 2) {
        ret_list = acct_storage_g_remove_associations(
                       db_conn, my_uid, acct_cond->assoc_cond);
    }
    rc = errno;
    notice_thread_fini();
    slurmdb_destroy_account_cond(acct_cond);

    if (ret_list && list_count(ret_list)) {
        char *object = NULL;
        ListIterator itr = NULL;

        /* Check to see if person is trying to remove a default
         * account of a user.  _isdefault only works with the
         * output from acct_storage_g_remove_accounts, and
         * with a previously got assoc_list.
         */
        if (_isdefault(cond_set, ret_list, local_assoc_list)) {
            exit_code=1;
            fprintf(stderr, " Please either remove the "
                    "accounts listed "
                    "above from list and resubmit,\n"
                    " or change these users default account to "
                    "remove the account(s).\n"
                    " Changes Discarded\n");
            acct_storage_g_commit(db_conn, 0);
            goto end_it;
        }
        itr = list_iterator_create(ret_list);
        /* If there were jobs running with an association to
           be deleted, don't.
        */
        if (rc == ESLURM_JOBS_RUNNING_ON_ASSOC) {
            fprintf(stderr, " Error with request: %s\n",
                    slurm_strerror(rc));
            while((object = list_next(itr))) {
                fprintf(stderr,"  %s\n", object);
            }
            acct_storage_g_commit(db_conn, 0);
            goto end_it;
        }

        if (cond_set == 1) {
            printf(" Deleting accounts...\n");
        } else if (cond_set & 2) {
            printf(" Deleting account associations...\n");
        }
        while((object = list_next(itr))) {
            printf("  %s\n", object);
        }
        list_iterator_destroy(itr);
        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);
        }
    } else if (ret_list) {
        printf(" Nothing deleted\n");
        rc = SLURM_ERROR;
    } else {
        exit_code=1;
        fprintf(stderr, " Error with request: %s\n",
                slurm_strerror(errno));

        rc = SLURM_ERROR;
    }

end_it:

    if (ret_list)
        list_destroy(ret_list);
    if (local_assoc_list)
        list_destroy(local_assoc_list);

    return rc;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
extern int sacctmgr_modify_federation(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	int i=0;
	int cond_set = 0, prev_set = 0, rec_set = 0, set = 0;
	List ret_list = NULL;
	slurmdb_federation_cond_t *federation_cond =
		xmalloc(sizeof(slurmdb_federation_cond_t));
	slurmdb_federation_rec_t *federation =
		xmalloc(sizeof(slurmdb_federation_rec_t));

	slurmdb_init_federation_cond(federation_cond, 0);
	slurmdb_init_federation_rec(federation, 0);

	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,
					     federation_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, federation);
			rec_set |= prev_set;
		} else {
			prev_set = _set_cond(&i, argc, argv,
					     federation_cond, NULL);
			cond_set |= prev_set;
		}
	}

	if (exit_code) {
		rc = SLURM_ERROR;
		goto end_it;
	} else 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 (verify_federations_exist(
					federation_cond->federation_list)) {
		rc = SLURM_ERROR;
		goto end_it;
	}

	if (federation->cluster_list) {
		bool existing_feds = false;
		char *mod_fed = NULL;
		slurmdb_cluster_rec_t *tmp_c = NULL;
		List cluster_list = federation->cluster_list;

		if (federation_cond->federation_list &&
		    (list_count(federation_cond->federation_list) > 1)) {
			fprintf(stderr, " Can't assign clusters to "
					"multiple federations.\n");
			rc = SLURM_ERROR;
			goto end_it;
		}

		/* Add all clusters that need to be removed if clearing all
		 * clusters or add clusters that will be removed if setting
		 * clusters to specific set. */
		mod_fed = list_peek(federation_cond->federation_list);
		if ((!list_count(cluster_list) ||
		     ((tmp_c = list_peek(cluster_list)) &&
		      *tmp_c->name != '-' && *tmp_c->name != '+')) &&
		    ((rc = _add_clusters_to_remove(cluster_list, mod_fed)) ||
		     (rc = _change_assigns_to_adds(cluster_list)))) {
			goto end_it;
		} else if ((rc = verify_fed_clusters(cluster_list, mod_fed,
						     &existing_feds))) {
			goto end_it;
		} else if (!list_count(cluster_list)) {
			printf("Nothing to change\n");
			rc = SLURM_ERROR;
			goto end_it;
		} else if (existing_feds) {
			char *warning = "\nAre you sure you want to continue?";
			if (!commit_check(warning)) {
				rc = SLURM_ERROR;
				goto end_it;
			}
		}
	}

	printf(" Setting\n");
	sacctmgr_print_federation(federation);

	notice_thread_init();
	ret_list = acct_storage_g_modify_federations(db_conn, my_uid,
						     federation_cond,
						     federation);

	if (ret_list && list_count(ret_list)) {
		char *object = NULL;
		ListIterator itr = list_iterator_create(ret_list);
		printf(" Modified federation...\n");
		while((object = list_next(itr))) {
			printf("  %s\n", object);
		}
		list_iterator_destroy(itr);
		set = 1;
	} else if (ret_list) {
		printf(" Nothing modified\n");
		rc = SLURM_ERROR;
	} else {
		exit_code=1;
		fprintf(stderr, " Error with request: %s\n",
			slurm_strerror(errno));
		rc = SLURM_ERROR;
	}

	FREE_NULL_LIST(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_federation_cond(federation_cond);
	slurmdb_destroy_federation_rec(federation);

	return rc;
}
Exemplo n.º 6
0
extern int sacctmgr_list_event(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	slurmdb_event_cond_t *event_cond =
		xmalloc(sizeof(slurmdb_event_cond_t));
	List event_list = NULL;
	slurmdb_event_rec_t *event = NULL;
	int i=0;
	ListIterator itr = NULL;
	ListIterator itr2 = NULL;
	char *object = 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 */

	/* 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;
		event_cond->period_start = time(NULL);

                if(!localtime_r(&event_cond->period_start, &start_tm)) {
                        fprintf(stderr,
                                " Couldn't get localtime from %ld",
                                (long)event_cond->period_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;
                event_cond->period_start = 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, event_cond, format_list);
	}

	if(exit_code) {
		slurmdb_destroy_event_cond(event_cond);
		list_destroy(format_list);
		return SLURM_ERROR;
	}

	print_fields_list = list_create(destroy_print_field);

	if(!list_count(format_list)) {
		if(event_cond->event_type == SLURMDB_EVENT_CLUSTER)
			slurm_addto_char_list(format_list,
					      "Cluster,Cpus,Start,End,"
					      "ClusterNodes");
		else
			slurm_addto_char_list(format_list,
					      "Cluster,NodeName,Start,"
					      "End,State,Reason,User");
	}

	itr = list_iterator_create(format_list);
	while((object = list_next(itr))) {
		char *tmp_char = NULL;
		int command_len = 0;
		int newlen = 0;

		if((tmp_char = strstr(object, "\%"))) {
			newlen = atoi(tmp_char+1);
			tmp_char[0] = '\0';
		}

		command_len = strlen(object);

		field = xmalloc(sizeof(print_field_t));
		if(!strncasecmp("ClusterNodes", object,
				       MAX(command_len, 8))) {
			field->type = PRINT_CLUSTER_NODES;
			field->name = xstrdup("Cluster Nodes");
			field->len = 20;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("Cluster", object,
				       MAX(command_len, 1))) {
			field->type = PRINT_CLUSTER;
			field->name = xstrdup("Cluster");
			field->len = 10;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("CPUs", object,
				MAX(command_len, 2))) {
			field->type = PRINT_CPUS;
			field->name = xstrdup("CPUs");
			field->len = 7;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("Duration", object,
				       MAX(command_len, 2))) {
			field->type = PRINT_DURATION;
			field->name = xstrdup("Duration");
			field->len = 13;
			field->print_routine = print_fields_time_from_secs;
		} else if(!strncasecmp("End", object, MAX(command_len, 2))) {
			field->type = PRINT_END;
			field->name = xstrdup("End");
			field->len = 19;
			field->print_routine = print_fields_date;
		} else if(!strncasecmp("EventRaw", object,
				MAX(command_len, 6))) {
			field->type = PRINT_EVENTRAW;
			field->name = xstrdup("EventRaw");
			field->len = 8;
			field->print_routine = print_fields_uint;
		} else if(!strncasecmp("Event", object,
				MAX(command_len, 2))) {
			field->type = PRINT_EVENT;
			field->name = xstrdup("Event");
			field->len = 7;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("NodeName", object,
				       MAX(command_len, 1))) {
			field->type = PRINT_NODENAME;
			field->name = xstrdup("Node Name");
			field->len = -15;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("Reason", object, MAX(command_len, 1))) {
			field->type = PRINT_REASON;
			field->name = xstrdup("Reason");
			field->len = 30;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("Start", object,
				       MAX(command_len, 1))) {
			field->type = PRINT_START;
			field->name = xstrdup("Start");
			field->len = 19;
			field->print_routine = print_fields_date;
		} else if(!strncasecmp("StateRaw", object,
				       MAX(command_len, 6))) {
			field->type = PRINT_STATERAW;
			field->name = xstrdup("StateRaw");
			field->len = 8;
			field->print_routine = print_fields_uint;
		} else if(!strncasecmp("State", object, MAX(command_len, 1))) {
			field->type = PRINT_STATE;
			field->name = xstrdup("State");
			field->len = 6;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("User", object, MAX(command_len, 1))) {
			field->type = PRINT_USER;
			field->name = xstrdup("User");
			field->len = 15;
			field->print_routine = print_fields_str;
		} else {
			exit_code=1;
			fprintf(stderr, " Unknown field '%s'\n", object);
			xfree(field);
			continue;
		}

		if(newlen)
			field->len = newlen;

		list_append(print_fields_list, field);
	}
Exemplo n.º 7
0
extern int sacctmgr_modify_cluster(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	int i=0;
	slurmdb_cluster_rec_t *cluster =
		xmalloc(sizeof(slurmdb_cluster_rec_t));
	slurmdb_assoc_rec_t *assoc =
		xmalloc(sizeof(slurmdb_assoc_rec_t));
	slurmdb_assoc_cond_t *assoc_cond =
		xmalloc(sizeof(slurmdb_assoc_cond_t));
	int cond_set = 0, prev_set = 0, rec_set = 0, set = 0;
	List ret_list = NULL;
	slurmdb_cluster_cond_t cluster_cond;
	bool existing_fed = false;

	slurmdb_init_assoc_rec(assoc, 0);

	assoc_cond->cluster_list = list_create(slurm_destroy_char);
	assoc_cond->acct_list = list_create(NULL);

	slurmdb_init_cluster_rec(cluster, 0);
	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, cluster);
			rec_set |= prev_set;
		} else {
			prev_set = _set_cond(&i, argc, argv,
					     &cluster_cond, NULL);
			cond_set |= prev_set;
		}
	}

	if (exit_code) {
		rc = SLURM_ERROR;
		goto end_it;
	} else 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;
		}
	}

	if (cluster->fed.name && cluster->fed.name[0]) {
		int rc;
		/* Make sure federation exists. */
		List fed_list = list_create(slurm_destroy_char);
		list_append(fed_list, xstrdup(cluster->fed.name));
		rc = verify_federations_exist(fed_list);
		FREE_NULL_LIST(fed_list);
		if (rc)
			goto end_it;

		/* See if cluster is assigned to another federation already. */
		if (list_count(cluster_cond.cluster_list)) {
			if (_verify_fed_clusters(cluster_cond.cluster_list,
						 cluster->fed.name,
						 &existing_fed))
					goto end_it;
			else if (!list_count(cluster_cond.cluster_list)) {
				/* irrelevant changes have been removed and
				 * nothing to change now. */
				printf("Nothing to change\n");
				rc = SLURM_ERROR;
				(void)rc; /* CLANG false positive */
				goto end_it;
			} else if (existing_fed) {
				char *warning =
					"\nAre you sure you want to continue?";
				if (!commit_check(warning)) {
					rc = SLURM_ERROR;
					(void)rc; /* CLANG false positive */
					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 */
		FREE_NULL_LIST(assoc_cond->cluster_list);
		assoc_cond->cluster_list = temp_list;
	}

	printf(" Setting\n");
	if (rec_set & CLUS_REC_SET)
		sacctmgr_print_cluster(cluster);
	if (rec_set & CLUS_ASSOC_SET) {
		printf("  Default Limits:\n");
		sacctmgr_print_assoc_limits(assoc);
	}

	if (rec_set & CLUS_REC_SET) {
		notice_thread_init();
		ret_list = acct_storage_g_modify_clusters(
			db_conn, my_uid, &cluster_cond, cluster);

		if (ret_list && list_count(ret_list)) {
			char *object = NULL;
			ListIterator itr = list_iterator_create(ret_list);
			printf(" Modified cluster...\n");
			while((object = list_next(itr))) {
				printf("  %s\n", object);
			}
			list_iterator_destroy(itr);
			set = 1;
		} else if (ret_list) {
			printf(" Nothing modified\n");
			rc = SLURM_ERROR;
		} else {
			exit_code=1;
			fprintf(stderr, " Error with request: %s\n",
				slurm_strerror(errno));
			rc = SLURM_ERROR;
		}

		FREE_NULL_LIST(ret_list);
		notice_thread_fini();
	}

	if (rec_set & CLUS_ASSOC_SET) {
		list_append(assoc_cond->acct_list, "root");
		notice_thread_init();
		ret_list = acct_storage_g_modify_assocs(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");
			rc = SLURM_ERROR;
		} else {
			exit_code=1;
			fprintf(stderr, " Error with request: %s\n",
				slurm_strerror(errno));
			rc = SLURM_ERROR;
		}
		FREE_NULL_LIST(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_assoc_cond(assoc_cond);
	slurmdb_destroy_assoc_rec(assoc);
	slurmdb_destroy_cluster_rec(cluster);

	return rc;
}
Exemplo n.º 8
0
extern int sacctmgr_list_qos(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_qos_cond_t *qos_cond = xmalloc(sizeof(slurmdb_qos_cond_t));
    int i=0;
    ListIterator itr = NULL;
    ListIterator itr2 = NULL;
    slurmdb_qos_rec_t *qos = NULL;
    List qos_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, qos_cond, format_list);
    }

    if(exit_code) {
        slurmdb_destroy_qos_cond(qos_cond);
        list_destroy(format_list);
        return SLURM_ERROR;
    } else if(!list_count(format_list)) {
        slurm_addto_char_list(format_list,
                              "Name,Prio,GraceT,Preempt,PreemptM,"
                              "Flags%40,UsageThres,UsageFactor,"
                              "GrpCPUs,GrpCPUMins,GrpCPURunMins,"
                              "GrpJ,GrpMEM,GrpN,GrpS,GrpW,"
                              "MaxCPUs,MaxCPUMins,MaxN,MaxW,"
                              "MaxCPUsPerUser,"
                              "MaxJobsPerUser,MaxNodesPerUser,"
                              "MaxSubmitJobsPerUser");
    }

    print_fields_list = sacctmgr_process_format_list(format_list);
    list_destroy(format_list);

    if(exit_code) {
        list_destroy(print_fields_list);
        return SLURM_ERROR;
    }
    qos_list = acct_storage_g_get_qos(db_conn, my_uid, qos_cond);
    slurmdb_destroy_qos_cond(qos_cond);

    if(!qos_list) {
        exit_code=1;
        fprintf(stderr, " Problem with query.\n");
        list_destroy(print_fields_list);
        return SLURM_ERROR;
    }
    itr = list_iterator_create(qos_list);
    itr2 = list_iterator_create(print_fields_list);
    print_fields_header(print_fields_list);

    field_count = list_count(print_fields_list);

    while((qos = list_next(itr))) {
        int curr_inx = 1;
        while((field = list_next(itr2))) {
            switch(field->type) {
            case PRINT_DESC:
                field->print_routine(
                    field, qos->description,
                    (curr_inx == field_count));
                break;
            case PRINT_FLAGS:
            {
                char *tmp_char = slurmdb_qos_flags_str(
                                     qos->flags);
                field->print_routine(
                    field,
                    tmp_char,
                    (curr_inx == field_count));
                xfree(tmp_char);
                break;
            }
            case PRINT_UT:
                field->print_routine(
                    field, qos->usage_thres,
                    (curr_inx == field_count));
                break;
            case PRINT_GRACE:
                field->print_routine(
                    field, (uint64_t)qos->grace_time,
                    (curr_inx == field_count));
                break;
            case PRINT_GRPCM:
                field->print_routine(
                    field,
                    qos->grp_cpu_mins,
                    (curr_inx == field_count));
                break;
            case PRINT_GRPCRM:
                field->print_routine(
                    field,
                    qos->grp_cpu_run_mins,
                    (curr_inx == field_count));
                break;
            case PRINT_GRPC:
                field->print_routine(field,
                                     qos->grp_cpus,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPJ:
                field->print_routine(field,
                                     qos->grp_jobs,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPMEM:
                field->print_routine(field,
                                     qos->grp_mem,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPN:
                field->print_routine(field,
                                     qos->grp_nodes,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPS:
                field->print_routine(field,
                                     qos->grp_submit_jobs,
                                     (curr_inx == field_count));
                break;
            case PRINT_GRPW:
                field->print_routine(
                    field,
                    qos->grp_wall,
                    (curr_inx == field_count));
                break;
            case PRINT_ID:
                field->print_routine(
                    field, qos->id,
                    (curr_inx == field_count));
                break;
            case PRINT_MAXCM:
                field->print_routine(
                    field,
                    qos->max_cpu_mins_pj,
                    (curr_inx == field_count));
                break;
            case PRINT_MAXCRM:
                field->print_routine(
                    field,
                    qos->max_cpu_run_mins_pu,
                    (curr_inx == field_count));
                break;
            case PRINT_MAXC:
                field->print_routine(field,
                                     qos->max_cpus_pj,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXCU:
                field->print_routine(field,
                                     qos->max_cpus_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXJ:
                field->print_routine(field,
                                     qos->max_jobs_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXN:
                field->print_routine(field,
                                     qos->max_nodes_pj,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXNU:
                field->print_routine(field,
                                     qos->max_nodes_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXS:
                field->print_routine(field,
                                     qos->max_submit_jobs_pu,
                                     (curr_inx == field_count));
                break;
            case PRINT_MAXW:
                field->print_routine(
                    field,
                    qos->max_wall_pj,
                    (curr_inx == field_count));
                break;
            case PRINT_NAME:
                field->print_routine(
                    field, qos->name,
                    (curr_inx == field_count));
                break;
            case PRINT_PREE:
                if(!g_qos_list)
                    g_qos_list = acct_storage_g_get_qos(
                                     db_conn, my_uid, NULL);

                field->print_routine(
                    field, g_qos_list, qos->preempt_bitstr,
                    (curr_inx == field_count));
                break;
            case PRINT_PREEM:
            {
                char *tmp_char = "cluster";
                if(qos->preempt_mode)
                    tmp_char = xstrtolower(
                                   preempt_mode_string(
                                       qos->preempt_mode));
                field->print_routine(
                    field,
                    tmp_char,
                    (curr_inx == field_count));
                break;
            }
            case PRINT_PRIO:
                field->print_routine(
                    field, qos->priority,
                    (curr_inx == field_count));
                break;
            case PRINT_UF:
                field->print_routine(
                    field, qos->usage_factor,
                    (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(qos_list);
    list_destroy(print_fields_list);

    return rc;
}
Exemplo n.º 9
0
extern int sacctmgr_modify_qos(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_qos_cond_t *qos_cond = xmalloc(sizeof(slurmdb_qos_cond_t));
    slurmdb_qos_rec_t *qos = xmalloc(sizeof(slurmdb_qos_rec_t));
    int i=0;
    int cond_set = 0, rec_set = 0, set = 0;
    List ret_list = NULL;

    slurmdb_init_qos_rec(qos, 0);

    for (i=0; i<argc; i++) {
        int command_len = strlen(argv[i]);
        if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))) {
            i++;
            cond_set += _set_cond(&i, argc, argv, qos_cond, NULL);

        } else if (!strncasecmp (argv[i], "Set", MAX(command_len, 3))) {
            i++;
            rec_set += _set_rec(&i, argc, argv, NULL, qos);
        } else {
            cond_set += _set_cond(&i, argc, argv, qos_cond, NULL);
        }
    }

    if(exit_code) {
        slurmdb_destroy_qos_cond(qos_cond);
        slurmdb_destroy_qos_rec(qos);
        return SLURM_ERROR;
    } else if(!rec_set) {
        exit_code=1;
        fprintf(stderr, " You didn't give me anything to set\n");
        slurmdb_destroy_qos_cond(qos_cond);
        slurmdb_destroy_qos_rec(qos);
        return SLURM_ERROR;
    } 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");
            slurmdb_destroy_qos_cond(qos_cond);
            slurmdb_destroy_qos_rec(qos);
            return SLURM_SUCCESS;
        }
    }

    notice_thread_init();

    ret_list = acct_storage_g_modify_qos(db_conn, my_uid, qos_cond, qos);
    if(ret_list && list_count(ret_list)) {
        char *object = NULL;
        ListIterator itr = list_iterator_create(ret_list);
        printf(" Modified qos...\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);
        }
    }

    slurmdb_destroy_qos_cond(qos_cond);
    slurmdb_destroy_qos_rec(qos);

    return rc;
}
Exemplo n.º 10
0
extern int sacctmgr_list_txn(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	slurmdb_txn_cond_t *txn_cond = xmalloc(sizeof(slurmdb_txn_cond_t));
	List txn_list = NULL;
	slurmdb_txn_rec_t *txn = NULL;
	int i=0;
	ListIterator itr = NULL;
	ListIterator itr2 = 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, txn_cond, format_list);
	}

	if(exit_code) {
		slurmdb_destroy_txn_cond(txn_cond);
		list_destroy(format_list);
		return SLURM_ERROR;
	}

	if(!list_count(format_list)) {
		slurm_addto_char_list(format_list, "T,Action,Actor,Where,Info");
		if(txn_cond->with_assoc_info)
			slurm_addto_char_list(format_list,
					      "User,Account,Cluster");
	}

	print_fields_list = sacctmgr_process_format_list(format_list);
	list_destroy(format_list);

	if(exit_code) {
		list_destroy(print_fields_list);
		return SLURM_ERROR;
	}

	txn_list = acct_storage_g_get_txn(db_conn, my_uid, txn_cond);
	slurmdb_destroy_txn_cond(txn_cond);

	if(!txn_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(txn_list);
	itr2 = list_iterator_create(print_fields_list);
	print_fields_header(print_fields_list);

	field_count = list_count(print_fields_list);

	while((txn = list_next(itr))) {
		int curr_inx = 1;
		while((field = list_next(itr2))) {
			switch(field->type) {
			case PRINT_ACCT:
				field->print_routine(field, txn->accts,
						     (curr_inx == field_count));
				break;
			case PRINT_ACTIONRAW:
				field->print_routine(
					field,
					txn->action,
					(curr_inx == field_count));
				break;
			case PRINT_ACTION:
				field->print_routine(
					field,
					slurmdbd_msg_type_2_str(txn->action,
								0),
					(curr_inx == field_count));
				break;
			case PRINT_ACTOR:
				field->print_routine(field,
						     txn->actor_name,
						     (curr_inx == field_count));
				break;
			case PRINT_CLUSTER:
				field->print_routine(field, txn->clusters,
						     (curr_inx == field_count));
				break;
			case PRINT_ID:
				field->print_routine(field,
						     txn->id,
						     (curr_inx == field_count));
				break;
			case PRINT_INFO:
				field->print_routine(field,
						     txn->set_info,
						     (curr_inx == field_count));
				break;
			case PRINT_TS:
				field->print_routine(field,
						     txn->timestamp,
						     (curr_inx == field_count));
				break;
			case PRINT_USER:
				field->print_routine(field, txn->users,
						     (curr_inx == field_count));
				break;
			case PRINT_WHERE:
				field->print_routine(field,
						     txn->where_query,
						     (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(txn_list);
	list_destroy(print_fields_list);
	return rc;
}
Exemplo n.º 11
0
extern int sacctmgr_delete_qos(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_qos_cond_t *qos_cond =
        xmalloc(sizeof(slurmdb_qos_cond_t));
    int i=0;
    List ret_list = NULL;
    int set = 0;

    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 += _set_cond(&i, argc, argv, qos_cond, NULL);
    }

    if(!set) {
        exit_code=1;
        fprintf(stderr,
                " No conditions given to remove, not executing.\n");
        slurmdb_destroy_qos_cond(qos_cond);
        return SLURM_ERROR;
    } else if(set == -1) {
        slurmdb_destroy_qos_cond(qos_cond);
        return SLURM_ERROR;
    }

    if (!g_qos_list)
        g_qos_list = acct_storage_g_get_qos(
                         db_conn, my_uid, NULL);

    notice_thread_init();
    ret_list = acct_storage_g_remove_qos(db_conn, my_uid, qos_cond);
    notice_thread_fini();
    slurmdb_destroy_qos_cond(qos_cond);

    if(ret_list && list_count(ret_list)) {
        char *object = NULL;
        ListIterator itr = NULL;

        /* Check to see if person is trying to remove a default
         * qos of an association.  _isdefault only works with the
         * output from acct_storage_g_remove_qos, and
         * with a previously got g_qos_list.
         */
        if (_isdefault(ret_list)) {
            exit_code=1;
            fprintf(stderr, " Please either remove the qos' listed "
                    "above from list and resubmit,\n"
                    " or change the default qos to "
                    "remove the qos.\n"
                    " Changes Discarded\n");
            acct_storage_g_commit(db_conn, 0);
            goto end_it;
        }

        itr = list_iterator_create(ret_list);
        printf(" Deleting QOS(s)...\n");

        while((object = list_next(itr))) {
            printf("  %s\n", object);
        }
        list_iterator_destroy(itr);
        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);
        }
    } else if(ret_list) {
        printf(" Nothing deleted\n");
    } else {
        exit_code=1;
        fprintf(stderr, " Error with request: %s\n",
                slurm_strerror(errno));
        rc = SLURM_ERROR;
    }

end_it:
    if(ret_list)
        list_destroy(ret_list);

    return rc;
}
Exemplo n.º 12
0
extern int sacctmgr_list_wckey(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	slurmdb_wckey_cond_t *wckey_cond =
		xmalloc(sizeof(slurmdb_wckey_cond_t));
	List wckey_list = NULL;
	int i=0;
	ListIterator itr = NULL;
	ListIterator itr2 = NULL;
	slurmdb_wckey_rec_t *wckey = NULL;
	char *object;

	print_field_t *field = NULL;
	int field_count = 0;

	List format_list = list_create(slurm_destroy_char);
	List print_fields_list; /* types are of print_field_t */

	enum {
		PRINT_CLUSTER,
		PRINT_ID,
		PRINT_NAME,
		PRINT_USER
	};

	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, wckey_cond, format_list);
	}

	if(exit_code) {
		slurmdb_destroy_wckey_cond(wckey_cond);
		list_destroy(format_list);
		return SLURM_ERROR;
	}

	if(!list_count(format_list)) {
		slurm_addto_char_list(format_list,
				      "Name,Cluster,User");
	}

	print_fields_list = list_create(destroy_print_field);

	itr = list_iterator_create(format_list);
	while((object = list_next(itr))) {
		char *tmp_char = NULL;
		int command_len = 0;
		int newlen = 0;

		if((tmp_char = strstr(object, "\%"))) {
			newlen = atoi(tmp_char+1);
			tmp_char[0] = '\0';
		}

		command_len = strlen(object);

		field = xmalloc(sizeof(print_field_t));
		if(!strncasecmp("WCKeys", object, MAX(command_len, 1))
		   || !strncasecmp("Names", object, MAX(command_len, 1))) {
			field->type = PRINT_NAME;
			field->name = xstrdup("WCKey");
			field->len = 10;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("Clusters", object,
				       MAX(command_len, 2))) {
			field->type = PRINT_CLUSTER;
			field->name = xstrdup("Cluster");
			field->len = 10;
			field->print_routine = print_fields_str;
		} else if(!strncasecmp("IDs", object, MAX(command_len, 1))) {
			field->type = PRINT_ID;
			field->name = xstrdup("ID");
			field->len = 6;
			field->print_routine = print_fields_uint;
		} else if(!strncasecmp("Users", object, MAX(command_len, 1))) {
			field->type = PRINT_USER;
			field->name = xstrdup("User");
			field->len = 10;
			field->print_routine = print_fields_str;
		} else {
			exit_code=1;
			fprintf(stderr, "Unknown field '%s'\n", object);
			xfree(field);
			continue;
		}

		if(newlen)
			field->len = newlen;

		list_append(print_fields_list, field);
	}
Exemplo n.º 13
0
/* 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;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
/* sacctmgr_list_tres()
 */
int sacctmgr_list_tres(int argc, char **argv)
{
	List tres_list;
	ListIterator itr;
	ListIterator itr2;
	List format_list = list_create(slurm_destroy_char);
	List print_fields_list;
	slurmdb_tres_cond_t *tres_cond = xmalloc(sizeof(slurmdb_tres_cond_t));
	slurmdb_tres_rec_t *tres;
	int field_count, i;
	print_field_t *field;

    	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, tres_cond, format_list);
	}

	if (exit_code) {
		slurmdb_destroy_tres_cond(tres_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, "Type,Name%15,ID");
	}

	tres_list = slurmdb_tres_get(db_conn, tres_cond);
	slurmdb_destroy_tres_cond(tres_cond);

	if (!tres_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(tres_list);
	itr2 = list_iterator_create(print_fields_list);
	print_fields_header(print_fields_list);
	field_count = list_count(print_fields_list);

	/* For each tres prints the data structure members
	 */
	while ((tres = list_next(itr))) {
		while ((field = list_next(itr2))) {
			switch (field->type) {
				case PRINT_NAME:
					field->print_routine(field,
							     tres->name,
							     field_count);
					break;
				case PRINT_ID:
					field->print_routine(field,
							     tres->id,
							     field_count);
					break;
				case PRINT_TYPE:
					field->print_routine(field,
							     tres->type,
							     field_count);
					break;
			}
		}
		list_iterator_reset(itr2);
		printf("\n");
	}
	list_iterator_destroy(itr);
	list_iterator_destroy(itr2);
	FREE_NULL_LIST(tres_list);
	FREE_NULL_LIST(print_fields_list);

	return 0;
}
Exemplo n.º 16
0
extern int sacctmgr_list_cluster(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	slurmdb_cluster_cond_t *cluster_cond =
		xmalloc(sizeof(slurmdb_cluster_cond_t));
	List cluster_list;
	int i=0;
	ListIterator itr = NULL;
	ListIterator itr2 = NULL;
	slurmdb_cluster_rec_t *cluster = NULL;
	char *tmp_char = 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 */

	slurmdb_init_cluster_cond(cluster_cond, 0);
	cluster_cond->cluster_list = list_create(slurm_destroy_char);
	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, cluster_cond, format_list);
	}

	if(exit_code) {
		slurmdb_destroy_cluster_cond(cluster_cond);
		list_destroy(format_list);
		return SLURM_ERROR;
	}

	if(!list_count(format_list)) {
		slurm_addto_char_list(format_list,
				      "Cl,Controlh,Controlp,RPC");
		if(!without_limits)
			slurm_addto_char_list(format_list,
					      "Fa,GrpJ,GrpN,GrpS,MaxJ,MaxN,"
					      "MaxS,MaxW,QOS,DefaultQOS");
	}

	cluster_cond->with_deleted = with_deleted;

	print_fields_list = sacctmgr_process_format_list(format_list);
	list_destroy(format_list);

	if(exit_code) {
		slurmdb_destroy_cluster_cond(cluster_cond);
		list_destroy(print_fields_list);
		return SLURM_ERROR;
	}

	cluster_list = acct_storage_g_get_clusters(db_conn, my_uid,
						   cluster_cond);
	slurmdb_destroy_cluster_cond(cluster_cond);

	if(!cluster_list) {
		exit_code=1;
		fprintf(stderr, " Problem with query.\n");
		list_destroy(print_fields_list);
		return SLURM_ERROR;
	}

	itr = list_iterator_create(cluster_list);
	itr2 = list_iterator_create(print_fields_list);
	print_fields_header(print_fields_list);

	field_count = list_count(print_fields_list);

	while((cluster = list_next(itr))) {
		int curr_inx = 1;
		slurmdb_association_rec_t *assoc = cluster->root_assoc;
		/* set up the working cluster rec so nodecnt's and node names
		 * are handled correctly */
		working_cluster_rec = cluster;
		while((field = list_next(itr2))) {
			switch(field->type) {
			case PRINT_CLUSTER:
				field->print_routine(field,
						     cluster->name,
						     (curr_inx == field_count));
				break;
			case PRINT_CHOST:
				field->print_routine(field,
						     cluster->control_host,
						     (curr_inx == field_count));
				break;
			case PRINT_CPORT:
				field->print_routine(field,
						     cluster->control_port,
						     (curr_inx == field_count));
				break;
			case PRINT_CLASS:
				field->print_routine(field,
						     get_classification_str(
							     cluster->
							     classification),
						     (curr_inx == field_count));
				break;
			case PRINT_CPUS:
			{
				char tmp_char[9];
				convert_num_unit((float)cluster->cpu_count,
						 tmp_char, sizeof(tmp_char),
						 UNIT_NONE);
				field->print_routine(field,
						     tmp_char,
						     (curr_inx == field_count));
				break;
			}
			case PRINT_DQOS:
				if(!g_qos_list) {
					g_qos_list = acct_storage_g_get_qos(
						db_conn,
						my_uid,
						NULL);
				}
				tmp_char = slurmdb_qos_str(g_qos_list,
							   assoc->def_qos_id);
				field->print_routine(
					field,
					tmp_char,
					(curr_inx == field_count));
				break;
			case PRINT_FAIRSHARE:
				field->print_routine(
					field,
					assoc->shares_raw,
					(curr_inx == field_count));
				break;
			case PRINT_FLAGS:
			{
				char *tmp_char = slurmdb_cluster_flags_2_str(
					cluster->flags);
				field->print_routine(
					field,
					tmp_char,
					(curr_inx == field_count));
				xfree(tmp_char);
				break;
			}
			case PRINT_GRPC:
				field->print_routine(field,
						     assoc->grp_cpus,
						     (curr_inx == field_count));
				break;
			case PRINT_GRPJ:
				field->print_routine(field,
						     assoc->grp_jobs,
						     (curr_inx == field_count));
				break;
			case PRINT_GRPN:
				field->print_routine(field,
						     assoc->grp_nodes,
						     (curr_inx == field_count));
				break;
			case PRINT_GRPS:
				field->print_routine(field,
						     assoc->grp_submit_jobs,
						     (curr_inx == field_count));
				break;
			case PRINT_MAXCM:
				field->print_routine(
					field,
					assoc->max_cpu_mins_pj,
					(curr_inx == field_count));
				break;
			case PRINT_MAXC:
				field->print_routine(field,
						     assoc->max_cpus_pj,
						     (curr_inx == field_count));
				break;
			case PRINT_MAXJ:
				field->print_routine(field,
						     assoc->max_jobs,
						     (curr_inx == field_count));
				break;
			case PRINT_MAXN:
				field->print_routine(field,
						     assoc->max_nodes_pj,
						     (curr_inx == field_count));
				break;
			case PRINT_MAXS:
				field->print_routine(field,
						     assoc->max_submit_jobs,
						     (curr_inx == field_count));
				break;
			case PRINT_MAXW:
				field->print_routine(
					field,
					assoc->max_wall_pj,
					(curr_inx == field_count));
				break;

			case PRINT_NODECNT:
			{
				hostlist_t hl = hostlist_create(cluster->nodes);
				int cnt = 0;
				if(hl) {
					cnt = hostlist_count(hl);
					hostlist_destroy(hl);
				}
				field->print_routine(
					field,
					cnt,
					(curr_inx == field_count));
				break;
			}
			case PRINT_CLUSTER_NODES:
				field->print_routine(
					field,
					cluster->nodes,
					(curr_inx == field_count));
				break;
			case PRINT_QOS:
				if(!g_qos_list)
					g_qos_list = acct_storage_g_get_qos(
						db_conn, my_uid, NULL);

				field->print_routine(field,
						     g_qos_list,
						     assoc->qos_list,
						     (curr_inx == field_count));
				break;
			case PRINT_QOS_RAW:
				field->print_routine(field,
						     assoc->qos_list,
						     (curr_inx == field_count));
				break;
			case PRINT_RPC_VERSION:
				field->print_routine(
					field,
					cluster->rpc_version,
					(curr_inx == field_count));
				break;
			case PRINT_SELECT:
				field->print_routine(
					field,
					cluster->plugin_id_select,
					(curr_inx == field_count));
				break;
			default:
				field->print_routine(
					field, NULL,
					(curr_inx == field_count));
				break;
			}
			curr_inx++;
		}
		list_iterator_reset(itr2);
		printf("\n");
	}
	/* clear the working cluster rec */
	working_cluster_rec = NULL;

	list_iterator_destroy(itr2);
	list_iterator_destroy(itr);
	list_destroy(cluster_list);
	list_destroy(print_fields_list);

	return rc;
}
Exemplo n.º 17
0
extern int sacctmgr_archive_dump(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	slurmdb_archive_cond_t *arch_cond =
		xmalloc(sizeof(slurmdb_archive_cond_t));
	int i=0;
	struct stat st;

	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, arch_cond);
	}

	if (!arch_cond->purge_event)
		arch_cond->purge_event = NO_VAL;
	if (!arch_cond->purge_job)
		arch_cond->purge_job = NO_VAL;
	if (!arch_cond->purge_resv)
		arch_cond->purge_resv = NO_VAL;
	if (!arch_cond->purge_step)
		arch_cond->purge_step = NO_VAL;
	if (!arch_cond->purge_suspend)
		arch_cond->purge_suspend = NO_VAL;

	if (exit_code) {
		slurmdb_destroy_archive_cond(arch_cond);
		return SLURM_ERROR;
	}

	if (arch_cond->archive_dir) {
		if (stat(arch_cond->archive_dir, &st) < 0) {
			exit_code = errno;
			fprintf(stderr, " dump: Failed to stat %s: %s\n "
				"Note: For archive dump, "
				"the directory must be on "
				"the calling host.\n",
				arch_cond->archive_dir, slurm_strerror(errno));
			return SLURM_ERROR;
		}

		if (!(st.st_mode & S_IFDIR)) {
			errno = EACCES;
			fprintf(stderr, " dump: "
				"archive dir %s isn't a directory\n",
				arch_cond->archive_dir);
			return SLURM_ERROR;
		}

		if (access(arch_cond->archive_dir, W_OK) < 0) {
			errno = EACCES;
			fprintf(stderr, " dump: "
				"archive dir %s is not writable\n",
				arch_cond->archive_dir);
			return SLURM_ERROR;
		}
	}

	if (arch_cond->archive_script) {
		if (stat(arch_cond->archive_script, &st) < 0) {
			exit_code = errno;
			fprintf(stderr, " dump: Failed to stat %s: %s\n "
				"Note: For archive dump, the script must be on "
				"the calling host.\n",
				arch_cond->archive_script,
				slurm_strerror(errno));
			return SLURM_ERROR;
		}
		if (!(st.st_mode & S_IFREG)) {
			errno = EACCES;
			fprintf(stderr, " dump: "
				"archive script %s isn't a regular file\n",
				arch_cond->archive_script);
			return SLURM_ERROR;
		}

		if (access(arch_cond->archive_script, X_OK) < 0) {
			errno = EACCES;
			fprintf(stderr, " dump: "
				"archive script %s is not executable\n",
				arch_cond->archive_script);
			return SLURM_ERROR;
		}
	}

	rc = jobacct_storage_g_archive(db_conn, arch_cond);
	if (rc == SLURM_SUCCESS) {
		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);
		}
	} else {
		exit_code=1;
		fprintf(stderr, " Problem dumping archive: %s\n",
			slurm_strerror(rc));
		rc = SLURM_ERROR;
	}
	slurmdb_destroy_archive_cond(arch_cond);

	return rc;
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
extern int sacctmgr_list_cluster(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	slurmdb_cluster_cond_t *cluster_cond =
		xmalloc(sizeof(slurmdb_cluster_cond_t));
	List cluster_list;
	int i=0;
	ListIterator itr = NULL;
	ListIterator itr2 = NULL;
	slurmdb_cluster_rec_t *cluster = NULL;
	char *tmp_char = 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 */

	slurmdb_init_cluster_cond(cluster_cond, 0);
	cluster_cond->cluster_list = list_create(slurm_destroy_char);
	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, cluster_cond, format_list);
	}

	if (exit_code) {
		slurmdb_destroy_cluster_cond(cluster_cond);
		FREE_NULL_LIST(format_list);
		return SLURM_ERROR;
	}

	if (!list_count(format_list)) {
		slurm_addto_char_list(format_list,
				      "Cl,Controlh,Controlp,RPC");
		if (!without_limits)
			slurm_addto_char_list(format_list,
					      "Fa,GrpJ,GrpTRES,GrpS,MaxJ,"
					      "MaxTRES,MaxS,MaxW,QOS,"
					      "DefaultQOS");
		if (with_fed)
			slurm_addto_char_list(format_list,
					      "Federation,ID,Weight,FedState");
	}

	cluster_cond->with_deleted = with_deleted;

	print_fields_list = sacctmgr_process_format_list(format_list);
	FREE_NULL_LIST(format_list);

	if (exit_code) {
		slurmdb_destroy_cluster_cond(cluster_cond);
		FREE_NULL_LIST(print_fields_list);
		return SLURM_ERROR;
	}

	cluster_list = acct_storage_g_get_clusters(db_conn, my_uid,
						   cluster_cond);
	slurmdb_destroy_cluster_cond(cluster_cond);

	if (!cluster_list) {
		exit_code=1;
		fprintf(stderr, " Problem with query.\n");
		FREE_NULL_LIST(print_fields_list);
		return SLURM_ERROR;
	}

	itr = list_iterator_create(cluster_list);
	itr2 = list_iterator_create(print_fields_list);
	print_fields_header(print_fields_list);

	field_count = list_count(print_fields_list);

	while ((cluster = list_next(itr))) {
		int curr_inx = 1;

		/* set up the working cluster rec so nodecnt's and node names
		 * are handled correctly */
		working_cluster_rec = cluster;
		while((field = list_next(itr2))) {
			switch(field->type) {
			case PRINT_CLUSTER:
				field->print_routine(field, cluster->name,
						     (curr_inx == field_count));
				break;
			case PRINT_CHOST:
				field->print_routine(field,
						     cluster->control_host,
						     (curr_inx == field_count));
				break;
			case PRINT_CPORT:
				field->print_routine(field,
						     cluster->control_port,
						     (curr_inx == field_count));
				break;
			case PRINT_CLASS:
				field->print_routine(field,
						     get_classification_str(
						     cluster->classification),
						     (curr_inx == field_count));
				break;
			case PRINT_FEDERATION:
				field->print_routine(field, cluster->fed.name,
						     (curr_inx == field_count));
				break;
			case PRINT_FEDSTATE:
			{
				char *tmp_str = slurmdb_cluster_fed_states_str(
							cluster->fed.state);
				field->print_routine(field, tmp_str,
						     (curr_inx == field_count));
				break;
			}
			case PRINT_FEDSTATERAW:
				field->print_routine(field, cluster->fed.state,
						     (curr_inx == field_count));
				break;
			case PRINT_ID:
				field->print_routine(field, cluster->fed.id,
						     (curr_inx == field_count));
				break;
			case PRINT_WEIGHT:
				field->print_routine(field, cluster->fed.weight,
						     (curr_inx == field_count));
				break;
			case PRINT_TRES:
				sacctmgr_initialize_g_tres_list();

				tmp_char = slurmdb_make_tres_string_from_simple(
					cluster->tres_str, g_tres_list, NO_VAL,
					CONVERT_NUM_UNIT_EXACT);
				field->print_routine(field, tmp_char,
						     (curr_inx == field_count));
				xfree(tmp_char);
				break;
			case PRINT_FLAGS:
			{
				char *tmp_char = slurmdb_cluster_flags_2_str(
							     cluster->flags);
				field->print_routine(field, tmp_char,
						     (curr_inx == field_count));
				xfree(tmp_char);
				break;
			}
			case PRINT_NODECNT:
			{
				hostlist_t hl = hostlist_create(cluster->nodes);
				int cnt = 0;
				if (hl) {
					cnt = hostlist_count(hl);
					hostlist_destroy(hl);
				}
				field->print_routine(
					field,
					cnt,
					(curr_inx == field_count));
				break;
			}
			case PRINT_CLUSTER_NODES:
				field->print_routine(
					field,
					cluster->nodes,
					(curr_inx == field_count));
				break;
			case PRINT_RPC_VERSION:
				field->print_routine(
					field,
					cluster->rpc_version,
					(curr_inx == field_count));
				break;
			case PRINT_SELECT:
				field->print_routine(
					field,
					cluster->plugin_id_select,
					(curr_inx == field_count));
				break;
			default:
				sacctmgr_print_assoc_rec(cluster->root_assoc,
							 field, NULL,
							 (curr_inx ==
							  field_count));
				break;
			}
			curr_inx++;
		}
		list_iterator_reset(itr2);
		printf("\n");
	}
	/* clear the working cluster rec */
	working_cluster_rec = NULL;

	list_iterator_destroy(itr2);
	list_iterator_destroy(itr);
	FREE_NULL_LIST(cluster_list);
	FREE_NULL_LIST(print_fields_list);

	return rc;
}
Exemplo n.º 20
0
extern int sacctmgr_list_federation(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	slurmdb_federation_cond_t *federation_cond =
		xmalloc(sizeof(slurmdb_federation_cond_t));
	List federation_list;
	int i=0;
	ListIterator itr = NULL;
	ListIterator itr2 = NULL;
	slurmdb_federation_rec_t *fed = NULL;
	bool print_clusters = false;

	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 */

	slurmdb_init_federation_cond(federation_cond, 0);
	federation_cond->federation_list = list_create(slurm_destroy_char);
	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, federation_cond, format_list);
	}

	if (exit_code) {
		slurmdb_destroy_federation_cond(federation_cond);
		FREE_NULL_LIST(format_list);
		return SLURM_ERROR;
	}

	if (!list_count(format_list)) {
		slurm_addto_char_list(format_list,
				      "Federation,Cluster,ID%2,"
				      "Features,FedState");
	}

	print_fields_list = sacctmgr_process_format_list(format_list);
	FREE_NULL_LIST(format_list);

	if (exit_code) {
		slurmdb_destroy_federation_cond(federation_cond);
		FREE_NULL_LIST(print_fields_list);
		return SLURM_ERROR;
	}

	federation_list = acct_storage_g_get_federations(db_conn, my_uid,
							 federation_cond);
	slurmdb_destroy_federation_cond(federation_cond);

	if (!federation_list) {
		exit_code=1;
		fprintf(stderr, " Problem with query.\n");
		FREE_NULL_LIST(print_fields_list);
		return SLURM_ERROR;
	}

	itr = list_iterator_create(federation_list);
	itr2 = list_iterator_create(print_fields_list);
	print_fields_header(print_fields_list);

	field_count = list_count(print_fields_list);

	/* only print clusters if a cluster field is requested */
	while((field = list_next(itr2))) {
		switch (field->type) {
		case PRINT_CLUSTER:
		case PRINT_FEDSTATE:
		case PRINT_FEDSTATERAW:
		case PRINT_ID:
			print_clusters = true;
			break;
		}
	}
	list_iterator_reset(itr2);

	while ((fed = list_next(itr))) {
		int      curr_inx   = 1;
		char    *tmp_str    = NULL;
		uint32_t tmp_uint32 = 0;
		slurmdb_cluster_rec_t *tmp_cluster = NULL;
		ListIterator itr3 =
			list_iterator_create(fed->cluster_list);

		if (!tree_display && print_clusters)
			tmp_cluster = list_next(itr3);

		do {
			while((field = list_next(itr2))) {
				switch(field->type) {
				/* Federation Specific Fields */
				case PRINT_FEDERATION:
					if (tree_display && tmp_cluster)
						tmp_str = NULL;
					else
						tmp_str = fed->name;
					field->print_routine(
						field, tmp_str,
						(curr_inx == field_count));
					break;
				case PRINT_FLAGS:
					if (tree_display && tmp_cluster)
						tmp_str = NULL;
					else {
						tmp_str =
						slurmdb_federation_flags_str(
								fed->flags);
					}
					field->print_routine(
						field, tmp_str,
						(curr_inx == field_count));

					if (tmp_str)
						xfree(tmp_str);
					break;

				/* Cluster Specific Fields */
				case PRINT_CLUSTER:
					if (!tmp_cluster)
						tmp_str = NULL;
					else
						tmp_str = tmp_cluster->name;
					field->print_routine(
						field, tmp_str,
						(curr_inx == field_count));
					break;
				case PRINT_FEATURES:
				{
					List tmp_list = NULL;
					if (tmp_cluster)
						tmp_list = tmp_cluster->
							fed.feature_list;
					field->print_routine(
						field, tmp_list,
						(curr_inx == field_count));
					break;
				}
				case PRINT_FEDSTATE:
					if (!tmp_cluster)
						tmp_str = NULL;
					else {
						tmp_str =
						slurmdb_cluster_fed_states_str(
							tmp_cluster->fed.state);
					}
					field->print_routine(
						field, tmp_str,
						(curr_inx == field_count));
					break;
				case PRINT_FEDSTATERAW:
					if (!tmp_cluster)
						tmp_uint32 = NO_VAL;
					else
						tmp_uint32 =
							tmp_cluster->fed.state;
					field->print_routine(
						field, tmp_uint32,
						(curr_inx == field_count));
					break;
				case PRINT_ID:
					if (!tmp_cluster)
						tmp_uint32 = NO_VAL;
					else
						tmp_uint32 =
							tmp_cluster->fed.id;
					field->print_routine(
						field, tmp_uint32,
						(curr_inx == field_count));
					break;
				default:
					field->print_routine(
						field, NULL,
						(curr_inx == field_count));
					break;
				}
				curr_inx++;
			}
			list_iterator_reset(itr2);
			printf("\n");
		} while(print_clusters && (tmp_cluster = list_next(itr3)));
		list_iterator_destroy(itr3);
	}

	list_iterator_destroy(itr2);
	list_iterator_destroy(itr);
	FREE_NULL_LIST(federation_list);
	FREE_NULL_LIST(print_fields_list);

	return rc;
}
Exemplo n.º 21
0
extern int sacctmgr_delete_cluster(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	slurmdb_cluster_cond_t *cluster_cond =
		xmalloc(sizeof(slurmdb_cluster_cond_t));
	int i=0;
	List ret_list = NULL;
	int cond_set = 0, prev_set;

	slurmdb_init_cluster_cond(cluster_cond, 0);
	cluster_cond->cluster_list = list_create(slurm_destroy_char);

	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, cluster_cond, NULL);
		cond_set |= prev_set;
	}

	if (exit_code) {
		slurmdb_destroy_cluster_cond(cluster_cond);
		return SLURM_ERROR;
	} else if (!cond_set) {
		exit_code=1;
		fprintf(stderr,
			" No conditions given to remove, not executing.\n");
		slurmdb_destroy_cluster_cond(cluster_cond);
		return SLURM_ERROR;
	}

	if (!list_count(cluster_cond->cluster_list)
	   && !cluster_cond->classification
	   && (!cluster_cond->federation_list ||
	       !list_count(cluster_cond->federation_list))) {
		exit_code=1;
		fprintf(stderr,
			"problem with delete request.  "
			"Nothing given to delete.\n");
		slurmdb_destroy_cluster_cond(cluster_cond);
		return SLURM_SUCCESS;
	}
	notice_thread_init();
	ret_list = acct_storage_g_remove_clusters(
		db_conn, my_uid, cluster_cond);
	rc = errno;
	notice_thread_fini();

	slurmdb_destroy_cluster_cond(cluster_cond);

	if (ret_list && list_count(ret_list)) {
		char *object = NULL;
		ListIterator itr = list_iterator_create(ret_list);
		/* If there were jobs running with an association to
		   be deleted, don't.
		*/
		if (rc == ESLURM_JOBS_RUNNING_ON_ASSOC) {
			fprintf(stderr, " Error with request: %s\n",
				slurm_strerror(rc));
			while((object = list_next(itr))) {
				fprintf(stderr,"  %s\n", object);
			}
			FREE_NULL_LIST(ret_list);
			acct_storage_g_commit(db_conn, 0);
			return rc;
		}
		printf(" Deleting clusters...\n");
		while((object = list_next(itr))) {
			printf("  %s\n", object);
		}
		list_iterator_destroy(itr);
		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);
		}
	} else if (ret_list) {
		printf(" Nothing deleted\n");
		rc = SLURM_ERROR;
	} else {
		exit_code=1;
		fprintf(stderr, " Error with request: %s\n",
			slurm_strerror(errno));
		rc = SLURM_ERROR;
	}

	FREE_NULL_LIST(ret_list);

	return rc;
}
Exemplo n.º 22
0
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;
}