Ejemplo n.º 1
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) {
		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);
			}
			list_destroy(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");
	} else {
		exit_code=1;
		fprintf(stderr, " Error with request: %s\n",
			slurm_strerror(errno));
		rc = SLURM_ERROR;
	}

	if(ret_list)
		list_destroy(ret_list);

	return rc;
}
Ejemplo n.º 2
0
extern int sacctmgr_add_federation(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	int i = 0, limit_set = 0;
	slurmdb_federation_rec_t *start_fed =
		xmalloc(sizeof(slurmdb_federation_rec_t));
	List name_list = list_create(slurm_destroy_char);
	List federation_list;
	ListIterator itr = NULL;
	char *name = NULL;

	slurmdb_init_federation_rec(start_fed, 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++;
		limit_set += _set_rec(&i, argc, argv, name_list, start_fed);
	}
	if (exit_code) {
		FREE_NULL_LIST(name_list);
		slurmdb_destroy_federation_rec(start_fed);
		return SLURM_ERROR;
	} else if (!list_count(name_list)) {
		slurmdb_destroy_federation_rec(start_fed);
		FREE_NULL_LIST(name_list);
		fprintf(stderr, " Need name of federation to add.\n");
		return SLURM_ERROR;
	} else if (_remove_existing_feds(name_list)) {
		FREE_NULL_LIST(name_list);
		slurmdb_destroy_federation_rec(start_fed);
		return SLURM_ERROR;
	}

	if ((list_count(name_list) > 1) &&
	    start_fed && start_fed->cluster_list &&
	    list_count(start_fed->cluster_list)) {
		slurmdb_destroy_federation_rec(start_fed);
		FREE_NULL_LIST(name_list);
		fprintf(stderr, " Can't assign clusters to multiple "
				"federations.\n");
		return SLURM_ERROR;
	}
	if (start_fed && start_fed->cluster_list &&
	    list_count(start_fed->cluster_list)) {
		bool existing_feds = false;

		if (list_count(name_list) > 1){
			slurmdb_destroy_federation_rec(start_fed);
			FREE_NULL_LIST(name_list);
			fprintf(stderr, " Can't assign clusters to "
				"multiple federations.\n");
			return SLURM_ERROR;
		}

		/* ensure that clusters exist in db */
		/* and if the clusters are already assigned to another fed. */
		if (verify_fed_clusters(start_fed->cluster_list, NULL,
					&existing_feds)) {
			FREE_NULL_LIST(name_list);
			slurmdb_destroy_federation_rec(start_fed);
			return SLURM_ERROR;
		} else if (existing_feds) {
			char *warning = "\nAre you sure you want to continue?";
			if (!commit_check(warning)) {
				FREE_NULL_LIST(name_list);
				slurmdb_destroy_federation_rec(start_fed);
				return SLURM_ERROR;
			}
		}
	}

	printf(" Adding Federation(s)\n");
	federation_list = list_create(slurmdb_destroy_federation_rec);
	itr = list_iterator_create(name_list);
	while((name = list_next(itr))) {
		slurmdb_federation_rec_t *fed = NULL;
		if (!name[0]) {
			fprintf(stderr, " Skipping blank fed name.\n");
			continue;
		}
		fed = xmalloc(sizeof(slurmdb_federation_rec_t));
		slurmdb_init_federation_rec(fed, 0);
		list_append(federation_list, fed);
		slurmdb_copy_federation_rec(fed, start_fed);
		fed->name = xstrdup(name);
		printf("  %s\n", fed->name);
	}
	list_iterator_destroy(itr);
	FREE_NULL_LIST(name_list);

	if (limit_set) {
		printf(" Settings\n");
		sacctmgr_print_federation(start_fed);
	}
	slurmdb_destroy_federation_rec(start_fed);

	if (!list_count(federation_list)) {
		printf(" Nothing new added.\n");
		rc = SLURM_ERROR;
		goto end_it;
	}

	notice_thread_init();
	rc = acct_storage_g_add_federations(db_conn, my_uid,
					    federation_list);
	notice_thread_fini();

	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 adding federation(s): %s\n",
			slurm_strerror(rc));
		rc = SLURM_ERROR;
	}

end_it:
	FREE_NULL_LIST(federation_list);

	return rc;
}
Ejemplo n.º 3
0
extern int sacctmgr_add_cluster(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	int i = 0;
	slurmdb_cluster_rec_t *cluster = NULL;
	List name_list = list_create(slurm_destroy_char);
	List cluster_list = NULL;
	slurmdb_association_rec_t start_assoc;

	int limit_set = 0;
	ListIterator itr = NULL, itr_c = NULL;
	char *name = NULL;
	uint16_t class = 0;

	slurmdb_init_association_rec(&start_assoc, 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++;
		limit_set += _set_rec(&i, argc, argv,
				      name_list, &start_assoc, &class);
	}
	if(exit_code) {
		list_destroy(name_list);
		return SLURM_ERROR;
	} else if(!list_count(name_list)) {
		list_destroy(name_list);
		exit_code=1;
		fprintf(stderr, " Need name of cluster to add.\n");
		return SLURM_ERROR;
	} else {
		List temp_list = NULL;
		slurmdb_cluster_cond_t cluster_cond;

		slurmdb_init_cluster_cond(&cluster_cond, 0);
		cluster_cond.cluster_list = name_list;
		cluster_cond.classification = class;

		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");
			return SLURM_ERROR;
		}

		itr_c = list_iterator_create(name_list);
		itr = list_iterator_create(temp_list);
		while((name = list_next(itr_c))) {
			slurmdb_cluster_rec_t *cluster_rec = NULL;

			list_iterator_reset(itr);
			while((cluster_rec = list_next(itr))) {
				if(!strcasecmp(cluster_rec->name, name))
					break;
			}
			if(cluster_rec) {
				printf(" This cluster %s already exists.  "
				       "Not adding.\n", name);
				list_delete_item(itr_c);
			}
		}
		list_iterator_destroy(itr);
		list_iterator_destroy(itr_c);
		list_destroy(temp_list);
		if(!list_count(name_list)) {
			list_destroy(name_list);
			return SLURM_ERROR;
		}
	}

	printf(" Adding Cluster(s)\n");
	cluster_list = list_create(slurmdb_destroy_cluster_rec);
	itr = list_iterator_create(name_list);
	while((name = list_next(itr))) {
		if(!name[0]) {
			exit_code=1;
			fprintf(stderr, " No blank names are "
				"allowed when adding.\n");
			rc = SLURM_ERROR;
			continue;
		}
		cluster = xmalloc(sizeof(slurmdb_cluster_rec_t));
		slurmdb_init_cluster_rec(cluster, 0);

		list_append(cluster_list, cluster);
		cluster->flags = NO_VAL;
		cluster->name = xstrdup(name);
		cluster->classification = class;
		cluster->root_assoc =
			xmalloc(sizeof(slurmdb_association_rec_t));
		slurmdb_init_association_rec(cluster->root_assoc, 0);
		printf("  Name          = %s\n", cluster->name);
		if(cluster->classification)
			printf("  Classification= %s\n",
			       get_classification_str(cluster->classification));

		cluster->root_assoc->def_qos_id = start_assoc.def_qos_id;
		cluster->root_assoc->shares_raw = start_assoc.shares_raw;

		cluster->root_assoc->grp_cpus = start_assoc.grp_cpus;
		cluster->root_assoc->grp_jobs = start_assoc.grp_jobs;
		cluster->root_assoc->grp_nodes = start_assoc.grp_nodes;
		cluster->root_assoc->grp_submit_jobs =
			start_assoc.grp_submit_jobs;

		cluster->root_assoc->max_cpu_mins_pj =
			start_assoc.max_cpu_mins_pj;
		cluster->root_assoc->max_cpus_pj = start_assoc.max_cpus_pj;
		cluster->root_assoc->max_jobs = start_assoc.max_jobs;
		cluster->root_assoc->max_nodes_pj = start_assoc.max_nodes_pj;
		cluster->root_assoc->max_submit_jobs =
			start_assoc.max_submit_jobs;
		cluster->root_assoc->max_wall_pj = start_assoc.max_wall_pj;

		cluster->root_assoc->qos_list =
			copy_char_list(start_assoc.qos_list);
	}
	list_iterator_destroy(itr);
	list_destroy(name_list);

	if(limit_set) {
		printf(" Default Limits\n");
		sacctmgr_print_assoc_limits(&start_assoc);
		if(start_assoc.qos_list)
			list_destroy(start_assoc.qos_list);
	}

	if(!list_count(cluster_list)) {
		printf(" Nothing new added.\n");
		goto end_it;
	}

	/* Since we are creating tables with add cluster that can't be
	   rolled back.  So we ask before hand if they are serious
	   about it so we can rollback if needed.
	*/
	if(commit_check("Would you like to commit changes?")) {
		notice_thread_init();
		rc = acct_storage_g_add_clusters(db_conn, my_uid, cluster_list);
		notice_thread_fini();
		if(rc == SLURM_SUCCESS) {
			acct_storage_g_commit(db_conn, 1);
		} else {
			exit_code=1;
			fprintf(stderr, " Problem adding clusters: %s\n",
				slurm_strerror(rc));
			/* this isn't really needed, but just to be safe */
			acct_storage_g_commit(db_conn, 0);
		}
	} else {
		printf(" Changes Discarded\n");
		/* this isn't really needed, but just to be safe */
		acct_storage_g_commit(db_conn, 0);
	}

end_it:
	list_destroy(cluster_list);

	return rc;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
extern int sacctmgr_delete_res(int argc, char *argv[])

{
    int rc = SLURM_SUCCESS;
    slurmdb_res_cond_t *res_cond = xmalloc(sizeof(slurmdb_res_cond_t));
    int i=0;
    List ret_list = NULL;
    ListIterator itr = NULL;
    int set = 0;
    char *name = NULL;

    slurmdb_init_res_cond(res_cond, 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_res_cond(&i, argc, argv, res_cond, NULL);
    }

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

    notice_thread_init();
    ret_list = acct_storage_g_remove_res(db_conn, my_uid, res_cond);
    notice_thread_fini();
    slurmdb_destroy_res_cond(res_cond);

    if (ret_list && list_count(ret_list)) {
        itr = list_iterator_create(ret_list);
        printf(" Deleting resource(s)...\n");

        while ((name = list_next(itr))) {
            printf("  %s\n", name);
        }
        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);

    xfree(name);
    return rc;
}
Ejemplo n.º 7
0
/* _rollup_handler - Process rollup duties */
static void *_rollup_handler(void *db_conn)
{
	time_t start_time = time(NULL);
	time_t next_time;
/* 	int sigarray[] = {SIGUSR1, 0}; */
	struct tm tm;
	rollup_stats_t rollup_stats;
	int i;

	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	(void) pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

	if (!slurm_localtime_r(&start_time, &tm)) {
		fatal("Couldn't get localtime for rollup handler %ld",
		      (long)start_time);
		return NULL;
	}

	while (1) {
		if (!db_conn)
			break;
		/* run the roll up */
		memset(&rollup_stats, 0, sizeof(rollup_stats_t));
		slurm_mutex_lock(&rollup_lock);
		running_rollup = 1;
		debug2("running rollup at %s", slurm_ctime2(&start_time));
		acct_storage_g_roll_usage(db_conn, 0, 0, 1, &rollup_stats);
		acct_storage_g_commit(db_conn, 1);
		running_rollup = 0;
		slurm_mutex_unlock(&rollup_lock);

		slurm_mutex_lock(&rpc_mutex);
		for (i = 0; i < ROLLUP_COUNT; i++) {
			if (rollup_stats.rollup_time[i] == 0)
				continue;
			rpc_stats.rollup_count[i]++;
			rpc_stats.rollup_time[i] +=
				rollup_stats.rollup_time[i];
			rpc_stats.rollup_max_time[i] =
				MAX(rpc_stats.rollup_max_time[i],
				    rollup_stats.rollup_time[i]);
		}
		slurm_mutex_unlock(&rpc_mutex);

		/* get the time now we have rolled usage */
		start_time = time(NULL);

		if (!slurm_localtime_r(&start_time, &tm)) {
			fatal("Couldn't get localtime for rollup handler %ld",
			      (long)start_time);
			return NULL;
		}

		/* sleep until the next hour */
		tm.tm_sec = 0;
		tm.tm_min = 0;
		tm.tm_hour++;
		tm.tm_isdst = -1;
		next_time = slurm_mktime(&tm);

		sleep((next_time - start_time));

		start_time = next_time;

		/* Just in case some new uids were added to the system
		   pick them up here. */
		assoc_mgr_set_missing_uids();
		/* repeat ;) */

	}

	return NULL;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
/*
 * _show_it - list the slurm configuration per the supplied arguments
 * IN argc - count of arguments
 * IN argv - list of arguments
 * undocumented association options wopi and wopl
 * without parent info and without parent limits
 */
static void _show_it (int argc, char *argv[])
{
	int error_code = SLURM_SUCCESS;
	int command_len = 0;

	if (!argv[0])
		goto helpme;

	command_len = strlen(argv[0]);

	/* reset the connection to get the most recent stuff */
	acct_storage_g_commit(db_conn, 0);

	/* First identify the entity to list */
	if (strncasecmp(argv[0], "Accounts", MAX(command_len, 2)) == 0
	    || !strncasecmp(argv[0], "Acct", MAX(command_len, 4))) {
		error_code = sacctmgr_list_account((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "Associations",
				MAX(command_len, 2)) == 0) {
		error_code = sacctmgr_list_assoc((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "Clusters",
				MAX(command_len, 2)) == 0) {
		error_code = sacctmgr_list_cluster((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "Configuration",
				MAX(command_len, 2)) == 0) {
		error_code = sacctmgr_list_config(true);
	} else if (strncasecmp(argv[0], "Events",
				MAX(command_len, 1)) == 0) {
		error_code = sacctmgr_list_event((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "Problems",
				MAX(command_len, 1)) == 0) {
		error_code = sacctmgr_list_problem((argc - 1), &argv[1]);
	} else if (!strncasecmp(argv[0], "RunawayJobs", MAX(command_len, 2)) ||
		   !strncasecmp(argv[0], "OrphanJobs", MAX(command_len, 1)) ||
		   !strncasecmp(argv[0], "LostJobs", MAX(command_len, 1))) {
		error_code = sacctmgr_list_runaway_jobs((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "QOS", MAX(command_len, 1)) == 0) {
		error_code = sacctmgr_list_qos((argc - 1), &argv[1]);
	} else if (!strncasecmp(argv[0], "Resource", MAX(command_len, 4))) {
		error_code = sacctmgr_list_res((argc - 1), &argv[1]);
	} else if (!strncasecmp(argv[0], "Reservations", MAX(command_len, 4)) ||
		   !strncasecmp(argv[0], "Resv", MAX(command_len, 4))) {
		error_code = sacctmgr_list_reservation((argc - 1), &argv[1]);
	} else if (!strncasecmp(argv[0], "Transactions", MAX(command_len, 1))
		   || !strncasecmp(argv[0], "Txn", MAX(command_len, 1))) {
		error_code = sacctmgr_list_txn((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "Users", MAX(command_len, 1)) == 0) {
		error_code = sacctmgr_list_user((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "WCKeys", MAX(command_len, 1)) == 0) {
		error_code = sacctmgr_list_wckey((argc - 1), &argv[1]);
	} else if (strncasecmp(argv[0], "tres", MAX(command_len, 2)) == 0) {
		error_code = sacctmgr_list_tres(argc - 1, &argv[1]);
	} else {
	helpme:
		exit_code = 1;
		fprintf(stderr, "No valid entity in list command\n");
		fprintf(stderr, "Input line must include ");
		fprintf(stderr, "\"Account\", \"Association\", "
			"\"Cluster\", \"Configuration\",\n\"Event\", "
			"\"Problem\", \"QOS\", \"Resource\", \"Reservation\", "
			"\"RunAwayJobs\", \"Transaction\", \"TRES\", "
			"\"User\", or \"WCKey\"\n");
	}

	if (error_code != SLURM_SUCCESS) {
		exit_code = 1;
	}
}
Ejemplo n.º 10
0
static void * _service_connection(void *arg)
{
	slurmdbd_conn_t *conn = (slurmdbd_conn_t *) arg;
	uint32_t nw_size = 0, msg_size = 0, uid = NO_VAL;
	char *msg = NULL;
	ssize_t msg_read = 0, offset = 0;
	bool fini = false, first = true;
	Buf buffer = NULL;
	int rc = SLURM_SUCCESS;

	debug2("Opened connection %d from %s", conn->newsockfd, conn->ip);

	while (!fini) {
		if (!_fd_readable(conn->newsockfd))
			break;		/* problem with this socket */
		msg_read = read(conn->newsockfd, &nw_size, sizeof(nw_size));
		if (msg_read == 0)	/* EOF */
			break;
		if (msg_read != sizeof(nw_size)) {
			error("Could not read msg_size from "
			      "connection %d(%s) uid(%d)",
			      conn->newsockfd, conn->ip, uid);
			break;
		}
		msg_size = ntohl(nw_size);
		if ((msg_size < 2) || (msg_size > MAX_MSG_SIZE)) {
			error("Invalid msg_size (%u) from "
			      "connection %d(%s) uid(%d)",
			      msg_size, conn->newsockfd, conn->ip, uid);
			break;
		}

		msg = xmalloc(msg_size);
		offset = 0;
		while (msg_size > offset) {
			if (!_fd_readable(conn->newsockfd))
				break;		/* problem with this socket */
			msg_read = read(conn->newsockfd, (msg + offset),
					(msg_size - offset));
			if (msg_read <= 0) {
				error("read(%d): %m", conn->newsockfd);
				break;
			}
			offset += msg_read;
		}
		if (msg_size == offset) {
			rc = proc_req(
				conn, msg, msg_size, first, &buffer, &uid);
			first = false;
			if (rc != SLURM_SUCCESS && rc != ACCOUNTING_FIRST_REG) {
				error("Processing last message from "
				      "connection %d(%s) uid(%d)",
				      conn->newsockfd, conn->ip, uid);
				if (rc == ESLURM_ACCESS_DENIED
				    || rc == SLURM_PROTOCOL_VERSION_ERROR)
					fini = true;
			}
		} else {
			buffer = make_dbd_rc_msg(conn->rpc_version,
						 SLURM_ERROR, "Bad offset", 0);
			fini = true;
		}

		(void) _send_resp(conn->newsockfd, buffer);
		xfree(msg);
	}

	if (conn->ctld_port) {
		if (!shutdown_time) {
			slurmdb_cluster_rec_t cluster_rec;
			ListIterator itr;
			slurmdbd_conn_t *slurmdbd_conn;
			memset(&cluster_rec, 0, sizeof(slurmdb_cluster_rec_t));
			cluster_rec.name = conn->cluster_name;
			cluster_rec.control_host = conn->ip;
			cluster_rec.control_port = conn->ctld_port;
			cluster_rec.cpu_count = conn->cluster_cpus;
			debug("cluster %s has disconnected",
			      conn->cluster_name);

			clusteracct_storage_g_fini_ctld(
				conn->db_conn, &cluster_rec);

			slurm_mutex_lock(&registered_lock);
			itr = list_iterator_create(registered_clusters);
			while ((slurmdbd_conn = list_next(itr))) {
				if (conn == slurmdbd_conn) {
					list_delete_item(itr);
					break;
				}
			}
			list_iterator_destroy(itr);
			slurm_mutex_unlock(&registered_lock);
		}
		/* needs to be the last thing done */
		acct_storage_g_commit(conn->db_conn, 1);
	}

	acct_storage_g_close_connection(&conn->db_conn);
	if (slurm_close(conn->newsockfd) < 0)
		error("close(%d): %m(%s)",  conn->newsockfd, conn->ip);
	else
		debug2("Closed connection %d uid(%d)", conn->newsockfd, uid);

	xfree(conn->cluster_name);
	xfree(conn);
	_free_server_thread(pthread_self());
	return NULL;
}
Ejemplo n.º 11
0
/*
 * _process_command - process the user's command
 * IN argc - count of arguments
 * IN argv - the arguments
 * RET 0 or errno (only for errors fatal to sacctmgr)
 */
static int
_process_command (int argc, char *argv[])
{
	int command_len = 0;
	if (argc < 1) {
		exit_code = 1;
		if (quiet_flag == -1)
			fprintf(stderr, "no input");
		return 0;
	}

	command_len = strlen(argv[0]);

	if (strncasecmp (argv[0], "associations",
			 MAX(command_len, 3)) == 0) {
		with_assoc_flag = 1;
	} else if (strncasecmp (argv[0], "dump", MAX(command_len, 3)) == 0) {
		sacctmgr_dump_cluster((argc - 1), &argv[1]);
	} else if (strncasecmp (argv[0], "help", MAX(command_len, 2)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for keyword:%s\n",
				 argv[0]);
		}
		_usage ();
	} else if (strncasecmp (argv[0], "load", MAX(command_len, 2)) == 0) {
		load_sacctmgr_cfg_file((argc - 1), &argv[1]);
	} else if (strncasecmp (argv[0], "oneliner",
				MAX(command_len, 1)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for keyword:%s\n",
				 argv[0]);
		}
		one_liner = 1;
	} else if (strncasecmp (argv[0], "quiet", MAX(command_len, 4)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr, "too many arguments for keyword:%s\n",
				 argv[0]);
		}
		quiet_flag = 1;
	} else if ((strncasecmp (argv[0], "exit", MAX(command_len, 4)) == 0) ||
		   (strncasecmp (argv[0], "\\q", MAX(command_len, 2)) == 0) ||
		   (strncasecmp (argv[0], "quit", MAX(command_len, 4)) == 0)) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for keyword:%s\n",
				 argv[0]);
		}
		exit_flag = 1;
	} else if ((strncasecmp (argv[0], "add", MAX(command_len, 3)) == 0) ||
		   (strncasecmp (argv[0], "create",
				 MAX(command_len, 3)) == 0)) {
		_add_it((argc - 1), &argv[1]);
	} else if ((strncasecmp (argv[0], "archive",
				 MAX(command_len, 3)) == 0)) {
		_archive_it((argc - 1), &argv[1]);
	} else if ((strncasecmp (argv[0], "show", MAX(command_len, 3)) == 0) ||
		   (strncasecmp (argv[0], "list", MAX(command_len, 3)) == 0)) {
		_show_it((argc - 1), &argv[1]);
	} else if (!strncasecmp (argv[0], "modify", MAX(command_len, 1))
		   || !strncasecmp (argv[0], "update", MAX(command_len, 1))) {
		_modify_it((argc - 1), &argv[1]);
	} else if ((strncasecmp (argv[0], "delete",
				 MAX(command_len, 3)) == 0) ||
		   (strncasecmp (argv[0], "remove",
				 MAX(command_len, 3)) == 0)) {
		_delete_it((argc - 1), &argv[1]);
	} else if (strncasecmp (argv[0], "verbose", MAX(command_len, 4)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for %s keyword\n",
				 argv[0]);
		}
		quiet_flag = -1;
	} else if (strncasecmp (argv[0], "readonly",
				MAX(command_len, 4)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for %s keyword\n",
				 argv[0]);
		}
		readonly_flag = 1;
	} else if (strncasecmp (argv[0], "reconfigure",
				MAX(command_len, 4)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for %s keyword\n",
				 argv[0]);
		}

		slurmdb_reconfig(db_conn);
	} else if (strncasecmp (argv[0], "rollup", MAX(command_len, 2)) == 0) {
		time_t my_start = 0;
		time_t my_end = 0;
		uint16_t archive_data = 0;
		if (argc > 4) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for %s keyword\n",
				 argv[0]);
		}

		if (argc > 1)
			my_start = parse_time(argv[1], 1);
		if (argc > 2)
			my_end = parse_time(argv[2], 1);
		if (argc > 3)
			archive_data = atoi(argv[3]);
		if (acct_storage_g_roll_usage(db_conn, my_start,
					     my_end, archive_data)
		   == SLURM_SUCCESS) {
			if (commit_check("Would you like to commit rollup?")) {
				acct_storage_g_commit(db_conn, 1);
			} else {
				printf(" Rollup Discarded\n");
				acct_storage_g_commit(db_conn, 0);
			}
		}
	} else if (strncasecmp (argv[0], "version", MAX(command_len, 4)) == 0) {
		if (argc > 1) {
			exit_code = 1;
			fprintf (stderr,
				 "too many arguments for %s keyword\n",
				 argv[0]);
		}
		_print_version();
	} else {
		exit_code = 1;
		fprintf (stderr, "invalid keyword: %s\n", argv[0]);
	}

	return 0;
}
Ejemplo n.º 12
0
extern int sacctmgr_archive_load(int argc, char *argv[])
{
	int rc = SLURM_SUCCESS;
	slurmdb_archive_rec_t *arch_rec =
		xmalloc(sizeof(slurmdb_archive_rec_t));
	int i=0, command_len = 0;
	struct stat st;

	for (i=0; i<argc; i++) {
		int end = parse_option_end(argv[i]);
		if (!end)
			command_len=strlen(argv[i]);
		else {
			command_len=end-1;
			if (argv[i][end] == '=') {
				end++;
			}
		}

		if (!end
		   || !strncasecmp (argv[i], "File", MAX(command_len, 1))) {
			arch_rec->archive_file =
				strip_quotes(argv[i]+end, NULL, 0);
		} else if (!strncasecmp (argv[i], "Insert",
					 MAX(command_len, 2))) {
			arch_rec->insert = strip_quotes(argv[i]+end, NULL, 1);
		} else {
			exit_code=1;
			fprintf(stderr, " Unknown option: %s\n", argv[i]);
		}
	}

	if (exit_code) {
		slurmdb_destroy_archive_rec(arch_rec);
		return SLURM_ERROR;
	}

	if (arch_rec->archive_file) {
		char *fullpath;
		char cwd[MAXPATHLEN + 1];
		int  mode = R_OK;

		if ((getcwd(cwd, MAXPATHLEN)) == NULL)
			fatal("getcwd failed: %m");

		if ((fullpath = search_path(cwd, arch_rec->archive_file,
					    true, mode))) {
			xfree(arch_rec->archive_file);
			arch_rec->archive_file = fullpath;
		}

		if (stat(arch_rec->archive_file, &st) < 0) {
			exit_code = errno;
			fprintf(stderr, " load: Failed to stat %s: %m\n "
				"Note: For archive load, the file must be on "
				"the calling host.\n",
				arch_rec->archive_file);
			return SLURM_ERROR;
		}
	}

	rc = jobacct_storage_g_archive_load(db_conn, arch_rec);
	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 loading archive file: %s\n",
			slurm_strerror(rc));
		rc = SLURM_ERROR;
	}

	slurmdb_destroy_archive_rec(arch_rec);

	return rc;
}
Ejemplo n.º 13
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: %m\n "
				"Note: For archive dump, "
				"the directory must be on "
				"the calling host.\n",
				arch_cond->archive_dir);
			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: %m\n "
				"Note: For archive dump, the script must be on "
				"the calling host.\n",
				arch_cond->archive_script);
			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;
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
extern int sacctmgr_delete_federation(int argc, char **argv)
{
	int rc = SLURM_SUCCESS;
	slurmdb_federation_cond_t *fed_cond =
		xmalloc(sizeof(slurmdb_federation_cond_t));
	int i=0;
	List ret_list = NULL;
	int cond_set = 0, prev_set;

	slurmdb_init_federation_cond(fed_cond, 0);
	fed_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++;
		prev_set = _set_cond(&i, argc, argv, fed_cond, NULL);
		cond_set |= prev_set;
	}

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

	if (!list_count(fed_cond->federation_list)) {
		exit_code=1;
		fprintf(stderr,
			"problem with delete request.  "
			"Nothing given to delete.\n");
		slurmdb_destroy_federation_cond(fed_cond);
		return SLURM_SUCCESS;
	}
	notice_thread_init();
	ret_list = acct_storage_g_remove_federations(db_conn, my_uid, fed_cond);
	rc = errno;
	notice_thread_fini();

	slurmdb_destroy_federation_cond(fed_cond);

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

		printf(" Deleting federations...\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;
}
Ejemplo n.º 17
0
extern int sacctmgr_add_qos(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    int i=0, limit_set=0;
    ListIterator itr = NULL;
    slurmdb_qos_rec_t *qos = NULL;
    slurmdb_qos_rec_t *start_qos = xmalloc(sizeof(slurmdb_qos_rec_t));
    List name_list = list_create(slurm_destroy_char);
    char *description = NULL;
    char *name = NULL;
    List qos_list = NULL;
    char *qos_str = NULL;

    slurmdb_init_qos_rec(start_qos, 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++;

        limit_set += _set_rec(&i, argc, argv, name_list, start_qos);
    }

    if(exit_code) {
        list_destroy(name_list);
        xfree(description);
        return SLURM_ERROR;
    } else if(!list_count(name_list)) {
        list_destroy(name_list);
        slurmdb_destroy_qos_rec(start_qos);
        exit_code=1;
        fprintf(stderr, " Need name of qos to add.\n");
        return SLURM_SUCCESS;
    }

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

        if(!g_qos_list) {
            exit_code=1;
            fprintf(stderr, " Problem getting qos's "
                    "from database.  "
                    "Contact your admin.\n");
            list_destroy(name_list);
            xfree(description);
            return SLURM_ERROR;
        }
    }

    qos_list = list_create(slurmdb_destroy_qos_rec);

    itr = list_iterator_create(name_list);
    while((name = list_next(itr))) {
        qos = NULL;
        if(!sacctmgr_find_qos_from_list(g_qos_list, name)) {
            qos = xmalloc(sizeof(slurmdb_qos_rec_t));
            slurmdb_init_qos_rec(qos, 0);
            qos->name = xstrdup(name);
            if(start_qos->description)
                qos->description =
                    xstrdup(start_qos->description);
            else
                qos->description = xstrdup(name);

            qos->grace_time = start_qos->grace_time;
            qos->grp_cpu_mins = start_qos->grp_cpu_mins;
            qos->grp_cpus = start_qos->grp_cpus;
            qos->grp_jobs = start_qos->grp_jobs;
            qos->grp_mem = start_qos->grp_mem;
            qos->grp_nodes = start_qos->grp_nodes;
            qos->grp_submit_jobs = start_qos->grp_submit_jobs;
            qos->grp_wall = start_qos->grp_wall;

            qos->max_cpu_mins_pj = start_qos->max_cpu_mins_pj;
            qos->max_cpu_run_mins_pu =
                start_qos->max_cpu_run_mins_pu;
            qos->max_cpus_pj = start_qos->max_cpus_pj;
            qos->max_cpus_pu = start_qos->max_cpus_pu;
            qos->max_jobs_pu = start_qos->max_jobs_pu;
            qos->max_nodes_pj = start_qos->max_nodes_pj;
            qos->max_nodes_pu = start_qos->max_nodes_pu;
            qos->max_submit_jobs_pu = start_qos->max_submit_jobs_pu;
            qos->max_wall_pj = start_qos->max_wall_pj;

            qos->preempt_list =
                copy_char_list(start_qos->preempt_list);
            qos->preempt_mode = start_qos->preempt_mode;

            qos->priority = start_qos->priority;

            qos->usage_factor = start_qos->usage_factor;
            qos->usage_thres = start_qos->usage_thres;

            xstrfmtcat(qos_str, "  %s\n", name);
            list_append(qos_list, qos);
        }
    }
    list_iterator_destroy(itr);
    list_destroy(name_list);

    if (g_qos_list) {
        list_destroy(g_qos_list);
        g_qos_list = NULL;
    }

    if(!list_count(qos_list)) {
        printf(" Nothing new added.\n");
        goto end_it;
    }

    if(qos_str) {
        printf(" Adding QOS(s)\n%s", qos_str);
        printf(" Settings\n");
        if(description)
            printf("  Description    = %s\n", description);
        else
            printf("  Description    = %s\n", "QOS Name");

        sacctmgr_print_qos_limits(start_qos);

        xfree(qos_str);
    }

    notice_thread_init();
    if(list_count(qos_list))
        rc = acct_storage_g_add_qos(db_conn, my_uid, qos_list);
    else
        goto end_it;

    notice_thread_fini();

    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 adding QOS: %s\n",
                slurm_strerror(rc));
        rc = SLURM_ERROR;
    }

end_it:
    list_destroy(qos_list);
    xfree(description);

    return rc;
}
Ejemplo n.º 18
0
extern int sacctmgr_add_account(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    int i=0;
    ListIterator itr = NULL, itr_c = NULL;
    slurmdb_account_rec_t *acct = NULL;
    slurmdb_association_rec_t *assoc = NULL;
    slurmdb_association_cond_t assoc_cond;
    List name_list = list_create(slurm_destroy_char);
    List cluster_list = list_create(slurm_destroy_char);
    char *cluster = NULL;
    char *name = NULL;
    List acct_list = NULL;
    List assoc_list = NULL;
    List local_assoc_list = NULL;
    List local_account_list = NULL;
    char *acct_str = NULL;
    char *assoc_str = NULL;
    int limit_set = 0;
    slurmdb_account_rec_t *start_acct =
        xmalloc(sizeof(slurmdb_account_rec_t));
    slurmdb_association_rec_t *start_assoc =
        xmalloc(sizeof(slurmdb_association_rec_t));

    slurmdb_init_association_rec(start_assoc, 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++;
        limit_set += _set_rec(&i, argc, argv, name_list, cluster_list,
                              start_acct, start_assoc);
    }
    if (exit_code)
        return SLURM_ERROR;

    if (!name_list || !list_count(name_list)) {
        list_destroy(name_list);
        list_destroy(cluster_list);
        slurmdb_destroy_association_rec(start_assoc);
        slurmdb_destroy_account_rec(start_acct);
        exit_code=1;
        fprintf(stderr, " Need name of account to add.\n");
        return SLURM_SUCCESS;
    } else {
        slurmdb_account_cond_t account_cond;
        memset(&account_cond, 0, sizeof(slurmdb_account_cond_t));
        memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));

        assoc_cond.acct_list = name_list;
        account_cond.assoc_cond = &assoc_cond;

        local_account_list = acct_storage_g_get_accounts(
                                 db_conn, my_uid, &account_cond);
    }

    if (!local_account_list) {
        exit_code=1;
        fprintf(stderr, " Problem getting accounts from database.  "
                "Contact your admin.\n");
        list_destroy(name_list);
        list_destroy(cluster_list);
        slurmdb_destroy_association_rec(start_assoc);
        slurmdb_destroy_account_rec(start_acct);
        return SLURM_ERROR;
    }

    if (!start_assoc->parent_acct)
        start_assoc->parent_acct = xstrdup("root");

    if (!cluster_list || !list_count(cluster_list)) {
        slurmdb_cluster_rec_t *cluster_rec = NULL;
        List tmp_list =
            acct_storage_g_get_clusters(db_conn, my_uid, NULL);
        if (!tmp_list) {
            exit_code=1;
            fprintf(stderr,
                    " Problem getting clusters from database.  "
                    "Contact your admin.\n");
            list_destroy(name_list);
            list_destroy(cluster_list);
            slurmdb_destroy_association_rec(start_assoc);
            slurmdb_destroy_account_rec(start_acct);
            list_destroy(local_account_list);
            return SLURM_ERROR;
        }

        if (!list_count(tmp_list)) {
            exit_code=1;
            fprintf(stderr,
                    "  Can't add accounts, no cluster "
                    "defined yet.\n"
                    " Please contact your administrator.\n");
            list_destroy(name_list);
            list_destroy(cluster_list);
            slurmdb_destroy_association_rec(start_assoc);
            slurmdb_destroy_account_rec(start_acct);
            list_destroy(local_account_list);
            return SLURM_ERROR;
        }
        if (!cluster_list)
            list_create(slurm_destroy_char);
        else
            list_flush(cluster_list);

        itr_c = list_iterator_create(tmp_list);
        while((cluster_rec = list_next(itr_c))) {
            list_append(cluster_list, xstrdup(cluster_rec->name));
        }
        list_iterator_destroy(itr_c);
        list_destroy(tmp_list);
    } else {
        List temp_list = NULL;
        slurmdb_cluster_cond_t cluster_cond;

        slurmdb_init_cluster_cond(&cluster_cond, 0);
        cluster_cond.cluster_list = cluster_list;

        temp_list = acct_storage_g_get_clusters(db_conn, my_uid,
                                                &cluster_cond);

        itr_c = list_iterator_create(cluster_list);
        itr = list_iterator_create(temp_list);
        while((cluster = list_next(itr_c))) {
            slurmdb_cluster_rec_t *cluster_rec = NULL;

            list_iterator_reset(itr);
            while((cluster_rec = list_next(itr))) {
                if (!strcasecmp(cluster_rec->name, cluster))
                    break;
            }
            if (!cluster_rec) {
                exit_code=1;
                fprintf(stderr, " This cluster '%s' "
                        "doesn't exist.\n"
                        "        Contact your admin "
                        "to add it to accounting.\n",
                        cluster);
                list_delete_item(itr_c);
            }
        }
        list_iterator_destroy(itr);
        list_iterator_destroy(itr_c);
        list_destroy(temp_list);

        if (!list_count(cluster_list)) {
            slurmdb_destroy_association_rec(start_assoc);
            slurmdb_destroy_account_rec(start_acct);
            list_destroy(local_account_list);
            return SLURM_ERROR;
        }
    }


    acct_list = list_create(slurmdb_destroy_account_rec);
    assoc_list = list_create(slurmdb_destroy_association_rec);

    memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));

    assoc_cond.acct_list = list_create(NULL);
    itr = list_iterator_create(name_list);
    while((name = list_next(itr)))
        list_append(assoc_cond.acct_list, name);
    list_iterator_destroy(itr);
    list_append(assoc_cond.acct_list, start_assoc->parent_acct);

    assoc_cond.cluster_list = cluster_list;
    local_assoc_list = acct_storage_g_get_associations(
                           db_conn, my_uid, &assoc_cond);
    list_destroy(assoc_cond.acct_list);
    if (!local_assoc_list) {
        exit_code=1;
        fprintf(stderr, " Problem getting associations from database.  "
                "Contact your admin.\n");
        list_destroy(name_list);
        list_destroy(cluster_list);
        slurmdb_destroy_association_rec(start_assoc);
        slurmdb_destroy_account_rec(start_acct);
        list_destroy(local_account_list);
        return SLURM_ERROR;
    }

    itr = list_iterator_create(name_list);
    while((name = list_next(itr))) {
        if (!name[0]) {
            exit_code=1;
            fprintf(stderr, " No blank names are "
                    "allowed when adding.\n");
            rc = SLURM_ERROR;
            continue;
        }

        acct = NULL;
        if (!sacctmgr_find_account_from_list(local_account_list, name)) {
            acct = xmalloc(sizeof(slurmdb_account_rec_t));
            acct->assoc_list =
                list_create(slurmdb_destroy_association_rec);
            acct->name = xstrdup(name);
            if (start_acct->description)
                acct->description =
                    xstrdup(start_acct->description);
            else
                acct->description = xstrdup(name);

            if (start_acct->organization)
                acct->organization =
                    xstrdup(start_acct->organization);
            else if (strcmp(start_assoc->parent_acct, "root"))
                acct->organization =
                    xstrdup(start_assoc->parent_acct);
            else
                acct->organization = xstrdup(name);

            xstrfmtcat(acct_str, "  %s\n", name);
            list_append(acct_list, acct);
        }

        itr_c = list_iterator_create(cluster_list);
        while((cluster = list_next(itr_c))) {
            if (sacctmgr_find_account_base_assoc_from_list(
                        local_assoc_list, name, cluster)) {
                //printf(" already have this assoc\n");
                continue;
            }
            if (!sacctmgr_find_account_base_assoc_from_list(
                        local_assoc_list, start_assoc->parent_acct,
                        cluster)) {
                exit_code=1;
                fprintf(stderr, " Parent account '%s' "
                        "doesn't exist on "
                        "cluster %s\n"
                        "        Contact your admin "
                        "to add this account.\n",
                        start_assoc->parent_acct, cluster);
                continue;
            }

            assoc = xmalloc(sizeof(slurmdb_association_rec_t));
            slurmdb_init_association_rec(assoc, 0);
            assoc->acct = xstrdup(name);
            assoc->cluster = xstrdup(cluster);
            assoc->def_qos_id = start_assoc->def_qos_id;
            assoc->parent_acct = xstrdup(start_assoc->parent_acct);
            assoc->shares_raw = start_assoc->shares_raw;

            assoc->grp_cpu_mins = start_assoc->grp_cpu_mins;
            assoc->grp_cpu_run_mins = start_assoc->grp_cpu_run_mins;
            assoc->grp_cpus = start_assoc->grp_cpus;
            assoc->grp_jobs = start_assoc->grp_jobs;
            assoc->grp_mem = start_assoc->grp_mem;
            assoc->grp_nodes = start_assoc->grp_nodes;
            assoc->grp_submit_jobs = start_assoc->grp_submit_jobs;
            assoc->grp_wall = start_assoc->grp_wall;

            assoc->max_cpu_mins_pj = start_assoc->max_cpu_mins_pj;
            assoc->max_cpus_pj = start_assoc->max_cpus_pj;
            assoc->max_jobs = start_assoc->max_jobs;
            assoc->max_nodes_pj = start_assoc->max_nodes_pj;
            assoc->max_submit_jobs = start_assoc->max_submit_jobs;
            assoc->max_wall_pj = start_assoc->max_wall_pj;

            assoc->qos_list = copy_char_list(start_assoc->qos_list);

            if (acct)
                list_append(acct->assoc_list, assoc);
            else
                list_append(assoc_list, assoc);
            xstrfmtcat(assoc_str,
                       "  A = %-10.10s"
                       " C = %-10.10s\n",
                       assoc->acct,
                       assoc->cluster);

        }
        list_iterator_destroy(itr_c);
    }
    list_iterator_destroy(itr);
    list_destroy(local_account_list);
    list_destroy(local_assoc_list);


    if (!list_count(acct_list) && !list_count(assoc_list)) {
        printf(" Nothing new added.\n");
        rc = SLURM_ERROR;
        goto end_it;
    } else if (!assoc_str) {
        exit_code=1;
        fprintf(stderr, " No associations created.\n");
        goto end_it;
    }

    if (acct_str) {
        printf(" Adding Account(s)\n%s", acct_str);
        printf(" Settings\n");
        if (start_acct->description)
            printf("  Description     = %s\n",
                   start_acct->description);
        else
            printf("  Description     = %s\n", "Account Name");

        if (start_acct->organization)
            printf("  Organization    = %s\n",
                   start_acct->organization);
        else
            printf("  Organization    = %s\n",
                   "Parent/Account Name");

        xfree(acct_str);
    }

    if (assoc_str) {
        printf(" Associations\n%s", assoc_str);
        xfree(assoc_str);
    }

    if (limit_set) {
        printf(" Settings\n");
        sacctmgr_print_assoc_limits(start_assoc);
    }

    notice_thread_init();
    if (list_count(acct_list))
        rc = acct_storage_g_add_accounts(db_conn, my_uid, acct_list);


    if (rc == SLURM_SUCCESS) {
        if (list_count(assoc_list))
            rc = acct_storage_g_add_associations(db_conn, my_uid,
                                                 assoc_list);
    } else {
        exit_code=1;
        fprintf(stderr, " Problem adding accounts: %s\n",
                slurm_strerror(rc));
        rc = SLURM_ERROR;
        notice_thread_fini();
        goto end_it;
    }
    notice_thread_fini();

    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,
                " error: Problem adding account associations: %s\n",
                slurm_strerror(rc));
        rc = SLURM_ERROR;
    }

end_it:
    list_destroy(name_list);
    list_destroy(cluster_list);
    list_destroy(acct_list);
    list_destroy(assoc_list);

    slurmdb_destroy_association_rec(start_assoc);
    slurmdb_destroy_account_rec(start_acct);
    return rc;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
/* main - slurmctld main function, start various threads and process RPCs */
int main(int argc, char **argv)
{
	pthread_attr_t thread_attr;
	char node_name_short[128];
	char node_name_long[128];
	void *db_conn = NULL;
	assoc_init_args_t assoc_init_arg;

	_init_config();
	log_init(argv[0], log_opts, LOG_DAEMON, NULL);
	if (read_slurmdbd_conf())
		exit(1);
	_parse_commandline(argc, argv);
	_update_logging(true);
	_update_nice();

	if (slurm_auth_init(NULL) != SLURM_SUCCESS) {
		fatal("Unable to initialize %s authentication plugin",
		      slurmdbd_conf->auth_type);
	}
	if (slurm_acct_storage_init(NULL) != SLURM_SUCCESS) {
		fatal("Unable to initialize %s accounting storage plugin",
		      slurmdbd_conf->storage_type);
	}

	slurmdbd_defs_init(slurmdbd_conf->auth_info);

	_kill_old_slurmdbd();
	if (foreground == 0)
		_daemonize();

	/*
	 * Need to create pidfile here in case we setuid() below
	 * (init_pidfile() exits if it can't initialize pid file).
	 * On Linux we also need to make this setuid job explicitly
	 * able to write a core dump.
	 */
	_init_pidfile();
	_become_slurm_user();
	if (foreground == 0)
		_set_work_dir();
	log_config();
	_init_dbd_stats();

#ifdef PR_SET_DUMPABLE
	if (prctl(PR_SET_DUMPABLE, 1) < 0)
		debug ("Unable to set dumpable to 1");
#endif /* PR_SET_DUMPABLE */

	if (xsignal_block(dbd_sigarray) < 0)
		error("Unable to block signals");

	/* Create attached thread for signal handling */
	slurm_attr_init(&thread_attr);
	if (pthread_create(&signal_handler_thread, &thread_attr,
			   _signal_handler, NULL))
		fatal("pthread_create %m");
	slurm_attr_destroy(&thread_attr);

	registered_clusters = list_create(NULL);

	slurm_attr_init(&thread_attr);
	if (pthread_create(&commit_handler_thread, &thread_attr,
			   _commit_handler, NULL))
		fatal("pthread_create %m");
	slurm_attr_destroy(&thread_attr);

	memset(&assoc_init_arg, 0, sizeof(assoc_init_args_t));

	/* If we are tacking wckey we need to cache
	   wckeys, if we aren't only cache the users, qos */
	assoc_init_arg.cache_level = ASSOC_MGR_CACHE_USER |
		ASSOC_MGR_CACHE_QOS | ASSOC_MGR_CACHE_TRES;
	if (slurmdbd_conf->track_wckey)
		assoc_init_arg.cache_level |= ASSOC_MGR_CACHE_WCKEY;

	db_conn = acct_storage_g_get_connection(NULL, 0, true, NULL);
	if (assoc_mgr_init(db_conn, &assoc_init_arg, errno) == SLURM_ERROR) {
		error("Problem getting cache of data");
		acct_storage_g_close_connection(&db_conn);
		goto end_it;
	}

	if (reset_lft_rgt) {
		int rc;
		if ((rc = acct_storage_g_reset_lft_rgt(
			     db_conn, slurmdbd_conf->slurm_user_id,
			     lft_rgt_list)) != SLURM_SUCCESS)
			fatal("Error when trying to reset lft and rgt's");

		if (acct_storage_g_commit(db_conn, 1))
			fatal("commit failed, meaning reset failed");
		FREE_NULL_LIST(lft_rgt_list);
	}

	if (gethostname(node_name_long, sizeof(node_name_long)))
		fatal("getnodename: %m");
	if (gethostname_short(node_name_short, sizeof(node_name_short)))
		fatal("getnodename_short: %m");

	while (1) {
		if (slurmdbd_conf->dbd_backup &&
		    (!xstrcmp(node_name_short, slurmdbd_conf->dbd_backup) ||
		     !xstrcmp(node_name_long, slurmdbd_conf->dbd_backup) ||
		     !xstrcmp(slurmdbd_conf->dbd_backup, "localhost"))) {
			info("slurmdbd running in background mode");
			have_control = false;
			backup = true;
			/* make sure any locks are released */
			acct_storage_g_commit(db_conn, 1);
			run_dbd_backup();
			if (!shutdown_time)
				assoc_mgr_refresh_lists(db_conn, 0);
		} else if (slurmdbd_conf->dbd_host &&
			   (!xstrcmp(slurmdbd_conf->dbd_host, node_name_short)||
			    !xstrcmp(slurmdbd_conf->dbd_host, node_name_long) ||
			    !xstrcmp(slurmdbd_conf->dbd_host, "localhost"))) {
			backup = false;
			have_control = true;
		} else {
			fatal("This host not configured to run SlurmDBD "
			      "((%s or %s) != %s | (backup) %s)",
			      node_name_short, node_name_long,
			      slurmdbd_conf->dbd_host,
			      slurmdbd_conf->dbd_backup);
		}

		if (!shutdown_time) {
			/* Create attached thread to process incoming RPCs */
			slurm_attr_init(&thread_attr);
			if (pthread_create(&rpc_handler_thread, &thread_attr,
					   rpc_mgr, NULL))
				fatal("pthread_create error %m");
			slurm_attr_destroy(&thread_attr);
		}

		if (!shutdown_time) {
			/* Create attached thread to do usage rollup */
			slurm_attr_init(&thread_attr);
			if (pthread_create(&rollup_handler_thread,
					   &thread_attr,
					   _rollup_handler, db_conn))
				fatal("pthread_create error %m");
			slurm_attr_destroy(&thread_attr);
		}

		/* Daemon is fully operational here */
		if (!shutdown_time || primary_resumed) {
			shutdown_time = 0;
			info("slurmdbd version %s started",
			     SLURM_VERSION_STRING);
			if (backup)
				run_dbd_backup();
		}

		_request_registrations(db_conn);
		acct_storage_g_commit(db_conn, 1);

		/* this is only ran if not backup */
		if (rollup_handler_thread) {
			pthread_join(rollup_handler_thread, NULL);
			rollup_handler_thread = 0;
		}
		if (rpc_handler_thread) {
			pthread_join(rpc_handler_thread, NULL);
			rpc_handler_thread = 0;
		}

		if (backup && primary_resumed && !restart_backup) {
			shutdown_time = 0;
			info("Backup has given up control");
		}

		if (shutdown_time)
			break;
	}
	/* Daemon termination handled here */

end_it:

	if (signal_handler_thread && (!backup || !restart_backup))
		pthread_join(signal_handler_thread, NULL);
	if (commit_handler_thread)
		pthread_join(commit_handler_thread, NULL);

	acct_storage_g_commit(db_conn, 1);
	acct_storage_g_close_connection(&db_conn);

	if (slurmdbd_conf->pid_file &&
	    (unlink(slurmdbd_conf->pid_file) < 0)) {
		verbose("Unable to remove pidfile '%s': %m",
			slurmdbd_conf->pid_file);
	}

	FREE_NULL_LIST(registered_clusters);

	if (backup && restart_backup) {
		info("Primary has come back but backup is "
		     "running the rollup. To avoid contention, "
		     "the backup dbd will now restart.");
		_restart_self(argc, argv);
	}

	assoc_mgr_fini(NULL);
	slurm_acct_storage_fini();
	slurm_auth_fini();
	log_fini();
	free_slurmdbd_conf();
	_free_dbd_stats();
	slurmdbd_defs_fini();
	exit(0);
}
Ejemplo n.º 21
0
extern int sacctmgr_add_res(int argc, char *argv[])

{
    int rc = SLURM_SUCCESS;
    int i=0, limit_set=0;
    ListIterator itr = NULL;
    ListIterator clus_itr = NULL;
    slurmdb_res_rec_t *res = NULL;
    slurmdb_res_rec_t *found_res = NULL;
    slurmdb_res_rec_t *start_res = xmalloc(sizeof(slurmdb_res_rec_t));
    List cluster_list = list_create(slurm_destroy_char);
    List name_list = list_create(slurm_destroy_char);
    char *name = NULL;
    List res_list = NULL;
    char *res_str = NULL;

    slurmdb_init_res_rec(start_res, 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++;

        limit_set += _set_res_rec(&i, argc, argv, name_list,
                                  cluster_list, start_res);
    }

    if (exit_code) {
        FREE_NULL_LIST(name_list);
        FREE_NULL_LIST(cluster_list);
        slurmdb_destroy_res_rec(start_res);
        return SLURM_ERROR;
    } else if (!list_count(name_list)) {
        FREE_NULL_LIST(name_list);
        FREE_NULL_LIST(cluster_list);
        slurmdb_destroy_res_rec(start_res);
        exit_code=1;
        fprintf(stderr, " Need name of resource to add.\n");
        return SLURM_SUCCESS;
    }

    if (!start_res->server) {
        /* assign some server name */
        start_res->server = xstrdup("slurmdb");
    }

    if (!g_res_list) {
        slurmdb_res_cond_t res_cond;
        slurmdb_init_res_cond(&res_cond, 0);
        res_cond.with_clusters = 1;
        g_res_list = acct_storage_g_get_res(db_conn, my_uid, &res_cond);
        if (!g_res_list) {
            exit_code=1;
            fprintf(stderr, " Problem getting system resources "
                    "from database.  "
                    "Contact your admin.\n");
            FREE_NULL_LIST(name_list);
            FREE_NULL_LIST(cluster_list);
            slurmdb_destroy_res_rec(start_res);
            return SLURM_ERROR;
        }
    }

    res_list = list_create(slurmdb_destroy_res_rec);

    itr = list_iterator_create(name_list);
    if (cluster_list)
        clus_itr = list_iterator_create(cluster_list);
    while ((name = list_next(itr))) {
        bool added = 0;
        found_res = sacctmgr_find_res_from_list(
                        g_res_list, NO_VAL, name, start_res->server);
        if (!found_res) {
            if (start_res->type == SLURMDB_RESOURCE_NOTSET) {
                exit_code=1;
                fprintf(stderr,
                        " Need to designate a resource "
                        "type to initially add '%s'.\n", name);
                break;

            } else if (start_res->count == NO_VAL) {
                exit_code=1;
                fprintf(stderr,
                        " Need to designate a resource "
                        "count to initially add '%s'.\n", name);
                break;
            }
            added = 1;
            res = xmalloc(sizeof(slurmdb_res_rec_t));
            slurmdb_init_res_rec(res, 0);
            res->name = xstrdup(name);
            res->description =
                xstrdup(start_res->description ?
                        start_res->description : name);
            res->manager = xstrdup(start_res->manager);
            res->server = xstrdup(start_res->server);
            res->count = start_res->count;
            res->flags = start_res->flags;
            res->type = start_res->type;

            xstrfmtcat(res_str, "  %s@%s\n",
                       res->name, res->server);
            list_append(res_list, res);
        }

        if (cluster_list && list_count(cluster_list)) {
            ListIterator found_itr = NULL;
            slurmdb_clus_res_rec_t *clus_res;
            char *cluster;
            uint16_t start_used = 0;

            if (found_res) {
                found_itr = list_iterator_create(
                                found_res->clus_res_list);
                res = xmalloc(sizeof(slurmdb_res_rec_t));
                slurmdb_init_res_rec(res, 0);
                res->id = found_res->id;
                res->type = found_res->type;
                start_used = res->percent_used =
                                 found_res->percent_used;
            }

            res->clus_res_list = list_create(
                                     slurmdb_destroy_clus_res_rec);

            while ((cluster = list_next(clus_itr))) {
                clus_res = NULL;
                if (found_res) {
                    while ((clus_res =
                                list_next(found_itr))) {
                        if (!strcmp(clus_res->cluster,
                                    cluster))
                            break;
                    }
                    list_iterator_reset(found_itr);
                }

                if (!clus_res) {
                    if (!added) {
                        added = 1;
                        xstrfmtcat(res_str,
                                   "  %s@%s\n", name,
                                   res->server);
                        list_append(res_list, res);
                    }
                    /* make sure we don't overcommit */
                    res->percent_used +=
                        start_res->percent_used;
                    if (res->percent_used > 100) {
                        exit_code=1;
                        fprintf(stderr,
                                " Adding this %d "
                                "clusters to resource "
                                "%s@%s at %u%% each "
                                ", with %u%% already "
                                "used,  would go over "
                                "100%%.  Please redo "
                                "your math and "
                                "resubmit.\n",
                                list_count(
                                    cluster_list),
                                res->name, res->server,
                                start_res->percent_used,
                                start_used);
                        break;
                    }
                    clus_res = xmalloc(
                                   sizeof(slurmdb_clus_res_rec_t));
                    list_append(res->clus_res_list,
                                clus_res);
                    clus_res->cluster = xstrdup(cluster);
                    clus_res->percent_allowed =
                        start_res->percent_used;
                    xstrfmtcat(res_str,
                               "   Cluster - %s\t%u%%\n",
                               cluster,
                               clus_res->percent_allowed);
                    /* FIXME: make sure we don't
                       overcommit */
                }
            }
            if (res->percent_used > 100)
                break;

            if (found_res)
                list_iterator_destroy(found_itr);

            if (!added)
                slurmdb_destroy_res_rec(res);

            list_iterator_reset(clus_itr);
        }
    }

    if (cluster_list)
        list_iterator_destroy(clus_itr);

    list_iterator_destroy(itr);

    FREE_NULL_LIST(name_list);
    FREE_NULL_LIST(cluster_list);

    if (exit_code) {
        rc = SLURM_ERROR;
        goto end_it;
    }

    if (!list_count(res_list)) {
        printf(" Nothing new added.\n");
        rc = SLURM_ERROR;
        goto end_it;
    }

    if (res_str) {
        char *tmp_str;
        switch (res->type) {
        case SLURMDB_RESOURCE_LICENSE:
            tmp_str = "License";
            break;
        default:
            tmp_str = "Unknown";
        }
        printf(" Adding Resource(s)\n%s", res_str);
        printf(" Settings\n");
        if (res->name)
            printf("  Name           = %s\n", res->name);
        if (res->server)
            printf("  Server         = %s\n", res->server);
        if (res->description)
            printf("  Description    = %s\n", res->description);
        if (res->manager)
            printf("  Manager        = %s\n", res->manager);
        if (res->count != NO_VAL)
            printf("  Count          = %u\n", res->count);
        printf("  Type           = %s\n", tmp_str);

        xfree(res_str);
    }

    if (list_count(res_list)) {
        notice_thread_init();
        rc = acct_storage_g_add_res(db_conn, my_uid, res_list);
        notice_thread_fini();
    } else
        goto end_it;
    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 adding system resource: %s\n",
                slurm_strerror(rc));
        rc = SLURM_ERROR;
    }

end_it:
    FREE_NULL_LIST(res_list);
    slurmdb_destroy_res_rec(start_res);
    return rc;
}