Beispiel #1
0
static char *_build_cluster_string(void)
{
	char *cluster_str = NULL;
	slurmdb_federation_rec_t *fed = NULL;
	slurmdb_federation_cond_t fed_cond;
	List fed_list = NULL;
	List cluster_list = list_create(NULL);

	list_append(cluster_list, slurmctld_conf.cluster_name);
	slurmdb_init_federation_cond(&fed_cond, 0);
	fed_cond.cluster_list = cluster_list;

	if ((fed_list =
	     slurmdb_federations_get(db_conn, &fed_cond)) &&
	    list_count(fed_list) == 1) {
		fed = list_pop(fed_list);
		fed_name = xstrdup(fed->name);
		list_for_each(fed->cluster_list, _foreach_cluster_list_to_str,
			      &cluster_str);
	}
	slurm_destroy_federation_rec(fed);
	FREE_NULL_LIST(cluster_list);
	FREE_NULL_LIST(fed_list);

	return cluster_str;
}
Beispiel #2
0
/* Add clusters to be removed if "setting" a federation to a specific set of
 * clusters or clearing all clusters.
 *
 * IN cluster_list: list of slurmdb_cluster_rec_t's with cluster names set that
 *                  are to be "set" on the federation the federation.
 * IN federation: name of the federation that is being added/modified.
 */
static int _add_clusters_to_remove(List cluster_list, const char *federation)
{
	List        db_list = NULL;
	ListIterator db_itr = NULL;
	slurmdb_federation_cond_t db_cond;
	slurmdb_federation_rec_t *db_rec = NULL;
	slurmdb_cluster_rec_t    *db_cluster = NULL;

	slurmdb_init_federation_cond(&db_cond, 0);
	db_cond.federation_list = list_create(slurm_destroy_char);
	list_append(db_cond.federation_list, xstrdup(federation));

	db_list = acct_storage_g_get_federations(db_conn, my_uid, &db_cond);
	if (!db_list || !list_count(db_list)) {
		fprintf(stderr, " Problem getting federations "
			"from database. Contact your admin.\n");
		return SLURM_ERROR;
	}
	FREE_NULL_LIST(db_cond.federation_list);
	db_rec = list_peek(db_list);
	db_itr = list_iterator_create(db_rec->cluster_list);
	while ((db_cluster = list_next(db_itr))) {
		bool found_cluster = false;
		slurmdb_cluster_rec_t *orig_cluster = NULL;
		ListIterator orig_itr = list_iterator_create(cluster_list);

		/* Figure out if cluster in cluster_list is already on the
		 * federation. If if is, don't add to list to remove */
		while ((orig_cluster = list_next(orig_itr))) {
			char *db_name = db_cluster->name;
			if (*db_name == '+' || *db_name == '-')
				++db_name;
			if (!xstrcmp(orig_cluster->name, db_name)) {
				found_cluster = true;
				break;
			}
		}
		list_iterator_destroy(orig_itr);
		if (found_cluster)
			continue;

		slurmdb_cluster_rec_t *cluster =
			xmalloc(sizeof(slurmdb_cluster_rec_t));
		slurmdb_init_cluster_rec(cluster, 0);
		cluster->name = xstrdup_printf("-%s", db_cluster->name);
		list_append(cluster_list, cluster);
	}
	list_iterator_destroy(db_itr);
	FREE_NULL_LIST(db_list);

	return SLURM_SUCCESS;
}
Beispiel #3
0
static int _verify_federations(List name_list, bool report_existing)
{
	int          rc        = SLURM_SUCCESS;
	char        *name      = NULL;
	List         temp_list = NULL;
	ListIterator itr       = NULL;
	ListIterator itr_c     = NULL;
	slurmdb_federation_cond_t fed_cond;

	slurmdb_init_federation_cond(&fed_cond, 0);
	fed_cond.federation_list = name_list;

	temp_list = acct_storage_g_get_federations(db_conn, my_uid, &fed_cond);
	if (!temp_list) {
		fprintf(stderr,
			" Problem getting federations 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_federation_rec_t *fed_rec = NULL;

		list_iterator_reset(itr);
		while((fed_rec = list_next(itr))) {
			if (!strcasecmp(fed_rec->name, name))
				break;
		}
		if (fed_rec && report_existing) {
			printf(" This federation %s already exists.  "
			       "Not adding.\n", name);
			list_delete_item(itr_c);
		} else if (!fed_rec && !report_existing) {
			printf(" The federation %s doesn't exist.\n", name);
			rc = SLURM_ERROR;
		}
	}
	list_iterator_destroy(itr);
	list_iterator_destroy(itr_c);
	FREE_NULL_LIST(temp_list);
	if (!list_count(name_list) || rc != SLURM_SUCCESS) {
		return SLURM_ERROR;
	}

	return SLURM_SUCCESS;
}
Beispiel #4
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;
}
Beispiel #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;
}
Beispiel #6
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;
}
Beispiel #7
0
extern int fed_mgr_init(void *db_conn)
{
	int rc = SLURM_SUCCESS;
	slurmdb_federation_cond_t fed_cond;
	List fed_list;
	slurmdb_federation_rec_t *fed = NULL;

	slurm_mutex_lock(&init_mutex);

	if (inited) {
		slurm_mutex_unlock(&init_mutex);
		return SLURM_SUCCESS;
	}

	if (!association_based_accounting)
		goto end_it;

	slurm_persist_conn_recv_server_init();

	if (running_cache) {
		debug("Database appears down, reading federations from state file.");
		fed = fed_mgr_state_load(
			slurmctld_conf.state_save_location);
		if (!fed) {
			debug2("No federation state");
			rc = SLURM_SUCCESS;
			goto end_it;
		}
	} else {
		slurmdb_init_federation_cond(&fed_cond, 0);
		fed_cond.cluster_list = list_create(NULL);
		list_append(fed_cond.cluster_list, slurmctld_cluster_name);

		fed_list = acct_storage_g_get_federations(db_conn, getuid(),
							  &fed_cond);
		FREE_NULL_LIST(fed_cond.cluster_list);
		if (!fed_list) {
			error("failed to get a federation list");
			rc = SLURM_ERROR;
			goto end_it;
		}

		if (list_count(fed_list) == 1)
			fed = list_pop(fed_list);
		else if (list_count(fed_list) > 1) {
			error("got more federations than expected");
			rc = SLURM_ERROR;
		}
		FREE_NULL_LIST(fed_list);
	}

	if (fed) {
		slurmdb_cluster_rec_t *cluster = NULL;

		if ((cluster = list_find_first(fed->cluster_list,
					       slurmdb_find_cluster_in_list,
					       slurmctld_cluster_name))) {
			_join_federation(fed, cluster, false);
		} else {
			error("failed to get cluster from federation that we requested");
			rc = SLURM_ERROR;
		}
	}

end_it:
	inited = true;
	slurm_mutex_unlock(&init_mutex);

	return rc;
}