extern int as_mysql_add_accts(mysql_conn_t *mysql_conn, uint32_t uid, List acct_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_account_rec_t *object = NULL; char *cols = NULL, *vals = NULL, *query = NULL, *txn_query = NULL; time_t now = time(NULL); char *user_name = NULL; char *extra = NULL, *tmp_extra = NULL; int affect_rows = 0; List assoc_list = list_create(slurmdb_destroy_association_rec); if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; user_name = uid_to_string((uid_t) uid); itr = list_iterator_create(acct_list); while ((object = list_next(itr))) { if (!object->name || !object->name[0] || !object->description || !object->description[0] || !object->organization || !object->organization[0]) { error("We need an account name, description, and " "organization to add. %s %s %s", object->name, object->description, object->organization); rc = SLURM_ERROR; continue; } xstrcat(cols, "creation_time, mod_time, name, " "description, organization"); xstrfmtcat(vals, "%ld, %ld, '%s', '%s', '%s'", now, now, object->name, object->description, object->organization); xstrfmtcat(extra, ", description='%s', organization='%s'", object->description, object->organization); query = xstrdup_printf( "insert into %s (%s) values (%s) " "on duplicate key update deleted=0, mod_time=%ld %s;", acct_table, cols, vals, now, extra); if (debug_flags & DEBUG_FLAG_DB_ASSOC) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(cols); xfree(vals); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add acct"); xfree(extra); continue; } affect_rows = last_affected_rows(mysql_conn); /* if (debug_flags & DEBUG_FLAG_DB_ASSOC) */ /* DB_DEBUG(mysql_conn->conn, "affected %d", affect_rows); */ if (!affect_rows) { if (debug_flags & DEBUG_FLAG_DB_ASSOC) DB_DEBUG(mysql_conn->conn, "nothing changed"); xfree(extra); continue; } /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); if (txn_query) xstrfmtcat(txn_query, ", (%ld, %u, '%s', '%s', '%s')", now, DBD_ADD_ACCOUNTS, object->name, user_name, tmp_extra); else xstrfmtcat(txn_query, "insert into %s " "(timestamp, action, name, actor, info) " "values (%ld, %u, '%s', '%s', '%s')", txn_table, now, DBD_ADD_ACCOUNTS, object->name, user_name, tmp_extra); xfree(tmp_extra); xfree(extra); if (!object->assoc_list) continue; list_transfer(assoc_list, object->assoc_list); } list_iterator_destroy(itr); xfree(user_name); if (rc != SLURM_ERROR) { if (txn_query) { xstrcat(txn_query, ";"); rc = mysql_db_query(mysql_conn, txn_query); xfree(txn_query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); rc = SLURM_SUCCESS; } } } else xfree(txn_query); if (list_count(assoc_list)) { if (as_mysql_add_assocs(mysql_conn, uid, assoc_list) == SLURM_ERROR) { error("Problem adding user associations"); rc = SLURM_ERROR; } } list_destroy(assoc_list); return rc; }
extern int as_mysql_add_clusters(mysql_conn_t *mysql_conn, uint32_t uid, List cluster_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_cluster_rec_t *object = NULL; char *cols = NULL, *vals = NULL, *extra = NULL, *query = NULL, *tmp_extra = NULL; time_t now = time(NULL); char *user_name = NULL; int affect_rows = 0; int added = 0; List assoc_list = NULL; slurmdb_assoc_rec_t *assoc = NULL; if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_SUPER_USER)) return ESLURM_ACCESS_DENIED; assoc_list = list_create(slurmdb_destroy_assoc_rec); user_name = uid_to_string((uid_t) uid); /* Since adding tables make it so you can't roll back, if there is an error there is no way to easily remove entries in the database, so we will create the tables first and then after that works out then add them to the mix. */ itr = list_iterator_create(cluster_list); while ((object = list_next(itr))) { if (!object->name || !object->name[0]) { error("We need a cluster name to add."); rc = SLURM_ERROR; list_remove(itr); continue; } if ((rc = create_cluster_tables(mysql_conn, object->name)) != SLURM_SUCCESS) { xfree(extra); xfree(cols); xfree(vals); added = 0; if (mysql_errno(mysql_conn->db_conn) == ER_WRONG_TABLE_NAME) rc = ESLURM_BAD_NAME; goto end_it; } } /* Now that all the tables were created successfully lets go ahead and add it to the system. */ list_iterator_reset(itr); while ((object = list_next(itr))) { xstrcat(cols, "creation_time, mod_time, acct"); xstrfmtcat(vals, "%ld, %ld, 'root'", now, now); xstrfmtcat(extra, ", mod_time=%ld", now); if (object->root_assoc) setup_assoc_limits(object->root_assoc, &cols, &vals, &extra, QOS_LEVEL_SET, 1); xstrfmtcat(query, "insert into %s (creation_time, mod_time, " "name, classification) " "values (%ld, %ld, '%s', %u) " "on duplicate key update deleted=0, mod_time=%ld, " "control_host='', control_port=0, " "classification=%u, flags=0", cluster_table, now, now, object->name, object->classification, now, object->classification); if (debug_flags & DEBUG_FLAG_DB_ASSOC) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add cluster %s", object->name); xfree(extra); xfree(cols); xfree(vals); added=0; break; } affect_rows = last_affected_rows(mysql_conn); if (!affect_rows) { debug2("nothing changed %d", affect_rows); xfree(extra); xfree(cols); xfree(vals); continue; } xstrfmtcat(query, "insert into \"%s_%s\" (%s, lft, rgt) " "values (%s, 1, 2) " "on duplicate key update deleted=0, " "id_assoc=LAST_INSERT_ID(id_assoc)%s;", object->name, assoc_table, cols, vals, extra); xfree(cols); xfree(vals); if (debug_flags & DEBUG_FLAG_DB_ASSOC) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add cluster root assoc"); xfree(extra); added=0; break; } /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); xstrfmtcat(query, "insert into %s " "(timestamp, action, name, actor, info) " "values (%ld, %u, '%s', '%s', '%s');", txn_table, now, DBD_ADD_CLUSTERS, object->name, user_name, tmp_extra); xfree(tmp_extra); xfree(extra); debug4("%d(%s:%d) query\n%s", mysql_conn->conn, THIS_FILE, __LINE__, query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); } else { ListIterator check_itr; char *tmp_name; added++; /* add it to the list and sort */ slurm_mutex_lock(&as_mysql_cluster_list_lock); check_itr = list_iterator_create(as_mysql_cluster_list); while ((tmp_name = list_next(check_itr))) { if (!strcmp(tmp_name, object->name)) break; } list_iterator_destroy(check_itr); if (!tmp_name) { list_append(as_mysql_cluster_list, xstrdup(object->name)); list_sort(as_mysql_cluster_list, (ListCmpF)slurm_sort_char_list_asc); } else error("Cluster %s(%s) appears to already be in " "our cache list, not adding.", tmp_name, object->name); slurm_mutex_unlock(&as_mysql_cluster_list_lock); } /* Add user root by default to run from the root * association. This gets popped off so we need to * read it every time here. */ assoc = xmalloc(sizeof(slurmdb_assoc_rec_t)); slurmdb_init_assoc_rec(assoc, 0); list_append(assoc_list, assoc); assoc->cluster = xstrdup(object->name); assoc->user = xstrdup("root"); assoc->acct = xstrdup("root"); assoc->is_def = 1; if (as_mysql_add_assocs(mysql_conn, uid, assoc_list) == SLURM_ERROR) { error("Problem adding root user association"); rc = SLURM_ERROR; } } end_it: list_iterator_destroy(itr); xfree(user_name); FREE_NULL_LIST(assoc_list); if (!added) reset_mysql_conn(mysql_conn); return rc; }
extern int as_mysql_fini_ctld(mysql_conn_t *mysql_conn, slurmdb_cluster_rec_t *cluster_rec) { int rc = SLURM_SUCCESS; time_t now = time(NULL); char *query = NULL; bool free_it = false; if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; /* Here we need to check make sure we are updating the entry correctly just incase the backup has already gained control. If we check the ip and port it is a pretty safe bet we have the right ctld. */ query = xstrdup_printf( "update %s set mod_time=%ld, control_host='', " "control_port=0 where name='%s' && " "control_host='%s' && control_port=%u;", cluster_table, now, cluster_rec->name, cluster_rec->control_host, cluster_rec->control_port); if (debug_flags & DEBUG_FLAG_DB_EVENT) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) return SLURM_ERROR; if (!last_affected_rows(mysql_conn) || (slurmdbd_conf && !slurmdbd_conf->track_ctld)) return rc; /* If tres is NULL we can get the current number of tres by sending NULL for the tres param in the as_mysql_cluster_tres function. */ if (!cluster_rec->tres_str) { free_it = true; as_mysql_cluster_tres( mysql_conn, cluster_rec->control_host, &cluster_rec->tres_str, now); } /* Since as_mysql_cluster_tres could change the last_affected_rows we can't group this with the above return. */ if (!cluster_rec->tres_str) return rc; /* If we affected things we need to now drain the nodes in the * cluster. This is to give better stats on accounting that * the ctld was gone so no jobs were able to be scheduled. We * drain the nodes since the rollup functionality understands * how to deal with that and running jobs so we don't get bad * info. */ query = xstrdup_printf( "insert into \"%s_%s\" (tres, state, time_start, reason) " "values ('%s', %u, %ld, 'slurmctld disconnect');", cluster_rec->name, event_table, cluster_rec->tres_str, NODE_STATE_DOWN, (long)now); if (free_it) xfree(cluster_rec->tres_str); if (debug_flags & DEBUG_FLAG_DB_EVENT) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(query); return rc; }
extern int as_mysql_add_users(mysql_conn_t *mysql_conn, uint32_t uid, List user_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_user_rec_t *object = NULL; char *cols = NULL, *vals = NULL, *query = NULL, *txn_query = NULL; time_t now = time(NULL); char *user_name = NULL; char *extra = NULL, *tmp_extra = NULL; int affect_rows = 0; List assoc_list = list_create(slurmdb_destroy_association_rec); List wckey_list = list_create(slurmdb_destroy_wckey_rec); if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; user_name = uid_to_string((uid_t) uid); itr = list_iterator_create(user_list); while ((object = list_next(itr))) { if (!object->name || !object->name[0]) { error("We need a user name and " "default acct to add."); rc = SLURM_ERROR; continue; } xstrcat(cols, "creation_time, mod_time, name"); xstrfmtcat(vals, "%ld, %ld, '%s'", (long)now, (long)now, object->name); if (object->admin_level != SLURMDB_ADMIN_NOTSET) { xstrcat(cols, ", admin_level"); xstrfmtcat(vals, ", %u", object->admin_level); xstrfmtcat(extra, ", admin_level=%u", object->admin_level); } else xstrfmtcat(extra, ", admin_level=%u", SLURMDB_ADMIN_NONE); query = xstrdup_printf( "insert into %s (%s) values (%s) " "on duplicate key update deleted=0, mod_time=%ld %s;", user_table, cols, vals, (long)now, extra); xfree(cols); xfree(vals); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add user %s", object->name); xfree(extra); continue; } affect_rows = last_affected_rows(mysql_conn); if (!affect_rows) { debug("nothing changed"); xfree(extra); continue; } if (addto_update_list(mysql_conn->update_list, SLURMDB_ADD_USER, object) == SLURM_SUCCESS) list_remove(itr); /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); if (txn_query) xstrfmtcat(txn_query, ", (%ld, %u, '%s', '%s', '%s')", (long)now, DBD_ADD_USERS, object->name, user_name, tmp_extra); else xstrfmtcat(txn_query, "insert into %s " "(timestamp, action, name, actor, info) " "values (%ld, %u, '%s', '%s', '%s')", txn_table, (long)now, DBD_ADD_USERS, object->name, user_name, tmp_extra); xfree(tmp_extra); xfree(extra); /* For < 2.2 systems we need to set the is_def flag in the default association/wckey so as to make sure we get it set correctly. */ if (object->assoc_list) { slurmdb_association_rec_t *assoc = NULL; ListIterator assoc_itr = list_iterator_create(object->assoc_list); while ((assoc = list_next(assoc_itr))) { /* We need to mark all of the associations with this account since there could be multiple clusters here. */ if (!strcmp(assoc->acct, object->default_acct)) assoc->is_def = 1; } list_iterator_destroy(assoc_itr); list_transfer(assoc_list, object->assoc_list); } if (object->wckey_list) { if (object->default_wckey) { slurmdb_wckey_rec_t *wckey = NULL; ListIterator wckey_itr = list_iterator_create( object->wckey_list); while ((wckey = list_next(wckey_itr))) { /* We need to mark all of the wckeys with this account since there could be multiple clusters here. */ if (!strcmp(wckey->name, object->default_wckey)) wckey->is_def = 1; } list_iterator_destroy(wckey_itr); } list_transfer(wckey_list, object->wckey_list); } } list_iterator_destroy(itr); xfree(user_name); if (rc != SLURM_ERROR) { if (txn_query) { xstrcat(txn_query, ";"); rc = mysql_db_query(mysql_conn, txn_query); xfree(txn_query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); rc = SLURM_SUCCESS; } } } else xfree(txn_query); if (list_count(assoc_list)) { if (as_mysql_add_assocs(mysql_conn, uid, assoc_list) == SLURM_ERROR) { error("Problem adding user associations"); rc = SLURM_ERROR; } } list_destroy(assoc_list); if (list_count(wckey_list)) { if (as_mysql_add_wckeys(mysql_conn, uid, wckey_list) == SLURM_ERROR) { error("Problem adding user wckeys"); rc = SLURM_ERROR; } } list_destroy(wckey_list); return rc; }
extern int as_mysql_add_accts(mysql_conn_t *mysql_conn, uint32_t uid, List acct_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_account_rec_t *object = NULL; char *cols = NULL, *vals = NULL, *query = NULL, *txn_query = NULL; time_t now = time(NULL); char *user_name = NULL; char *extra = NULL, *tmp_extra = NULL; int affect_rows = 0; List assoc_list = list_create(slurmdb_destroy_assoc_rec); if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_OPERATOR)) { slurmdb_user_rec_t user; memset(&user, 0, sizeof(slurmdb_user_rec_t)); user.uid = uid; if (!is_user_any_coord(mysql_conn, &user)) { error("Only admins/operators/coordinators " "can add accounts"); return ESLURM_ACCESS_DENIED; } /* If the user is a coord of any acct they can add * accounts they are only able to make associations to * these accounts if they are coordinators of the * parent they are trying to add to */ } user_name = uid_to_string((uid_t) uid); itr = list_iterator_create(acct_list); while ((object = list_next(itr))) { if (!object->name || !object->name[0] || !object->description || !object->description[0] || !object->organization || !object->organization[0]) { error("We need an account name, description, and " "organization to add. %s %s %s", object->name, object->description, object->organization); rc = SLURM_ERROR; continue; } xstrcat(cols, "creation_time, mod_time, name, " "description, organization"); xstrfmtcat(vals, "%ld, %ld, '%s', '%s', '%s'", now, now, object->name, object->description, object->organization); xstrfmtcat(extra, ", description='%s', organization='%s'", object->description, object->organization); query = xstrdup_printf( "insert into %s (%s) values (%s) " "on duplicate key update deleted=0, mod_time=%ld %s;", acct_table, cols, vals, now, extra); if (debug_flags & DEBUG_FLAG_DB_ASSOC) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(cols); xfree(vals); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add acct"); xfree(extra); continue; } affect_rows = last_affected_rows(mysql_conn); /* if (debug_flags & DEBUG_FLAG_DB_ASSOC) */ /* DB_DEBUG(mysql_conn->conn, "affected %d", affect_rows); */ if (!affect_rows) { if (debug_flags & DEBUG_FLAG_DB_ASSOC) DB_DEBUG(mysql_conn->conn, "nothing changed"); xfree(extra); continue; } /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); if (txn_query) xstrfmtcat(txn_query, ", (%ld, %u, '%s', '%s', '%s')", now, DBD_ADD_ACCOUNTS, object->name, user_name, tmp_extra); else xstrfmtcat(txn_query, "insert into %s " "(timestamp, action, name, actor, info) " "values (%ld, %u, '%s', '%s', '%s')", txn_table, now, DBD_ADD_ACCOUNTS, object->name, user_name, tmp_extra); xfree(tmp_extra); xfree(extra); if (!object->assoc_list) continue; if (!assoc_list) assoc_list = list_create(slurmdb_destroy_assoc_rec); list_transfer(assoc_list, object->assoc_list); } list_iterator_destroy(itr); xfree(user_name); if (rc != SLURM_ERROR) { if (txn_query) { xstrcat(txn_query, ";"); rc = mysql_db_query(mysql_conn, txn_query); xfree(txn_query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); rc = SLURM_SUCCESS; } } } else xfree(txn_query); if (assoc_list && list_count(assoc_list)) { if ((rc = as_mysql_add_assocs(mysql_conn, uid, assoc_list)) != SLURM_SUCCESS) error("Problem adding accounts associations"); } FREE_NULL_LIST(assoc_list); return rc; }
extern int as_mysql_add_qos(mysql_conn_t *mysql_conn, uint32_t uid, List qos_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_qos_rec_t *object = NULL; char *cols = NULL, *extra = NULL, *vals = NULL, *query = NULL, *tmp_extra = NULL; time_t now = time(NULL); char *user_name = NULL; int affect_rows = 0; int added = 0; char *added_preempt = NULL; if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; user_name = uid_to_string((uid_t) uid); itr = list_iterator_create(qos_list); while ((object = list_next(itr))) { if (!object->name || !object->name[0]) { error("We need a qos name to add."); rc = SLURM_ERROR; continue; } xstrcat(cols, "creation_time, mod_time, name"); xstrfmtcat(vals, "%ld, %ld, '%s'", now, now, object->name); xstrfmtcat(extra, ", mod_time=%ld", now); _setup_qos_limits(object, &cols, &vals, &extra, &added_preempt, 1); if (added_preempt) { object->preempt_bitstr = bit_alloc(g_qos_count); bit_unfmt(object->preempt_bitstr, added_preempt+1); xfree(added_preempt); } xstrfmtcat(query, "insert into %s (%s) values (%s) " "on duplicate key update deleted=0, " "id=LAST_INSERT_ID(id)%s;", qos_table, cols, vals, extra); debug3("%d(%s:%d) query\n%s", mysql_conn->conn, THIS_FILE, __LINE__, query); object->id = mysql_db_insert_ret_id(mysql_conn, query); xfree(query); if (!object->id) { error("Couldn't add qos %s", object->name); added=0; xfree(cols); xfree(extra); xfree(vals); break; } affect_rows = last_affected_rows(mysql_conn); if (!affect_rows) { debug2("nothing changed %d", affect_rows); xfree(cols); xfree(extra); xfree(vals); continue; } /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); xstrfmtcat(query, "insert into %s " "(timestamp, action, name, actor, info) " "values (%ld, %u, '%s', '%s', '%s');", txn_table, now, DBD_ADD_QOS, object->name, user_name, tmp_extra); xfree(tmp_extra); xfree(cols); xfree(extra); xfree(vals); debug4("query\n%s",query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); } else { if (addto_update_list(mysql_conn->update_list, SLURMDB_ADD_QOS, object) == SLURM_SUCCESS) list_remove(itr); added++; } } list_iterator_destroy(itr); xfree(user_name); if (!added) { reset_mysql_conn(mysql_conn); } return rc; }
extern int as_mysql_add_wckeys(mysql_conn_t *mysql_conn, uint32_t uid, List wckey_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_wckey_rec_t *object = NULL; char *cols = NULL, *extra = NULL, *vals = NULL, *query = NULL, *tmp_extra = NULL; time_t now = time(NULL); char *user_name = NULL; int affect_rows = 0; int added = 0; List added_user_list = NULL; if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_OPERATOR)) return ESLURM_ACCESS_DENIED; user_name = uid_to_string((uid_t) uid); itr = list_iterator_create(wckey_list); while ((object = list_next(itr))) { if (!object->cluster || !object->cluster[0] || !object->user || !object->user[0] || !object->name) { error("We need a wckey name (%s), cluster (%s), " "and user (%s) to add.", object->name, object->cluster, object->user); rc = SLURM_ERROR; continue; } if (!added_user_list) added_user_list = list_create(NULL); list_append(added_user_list, object->user); xstrcat(cols, "creation_time, mod_time, user"); xstrfmtcat(vals, "%ld, %ld, '%s'", now, now, object->user); xstrfmtcat(extra, ", mod_time=%ld, user='******'", now, object->user); if (object->name) { xstrcat(cols, ", wckey_name"); xstrfmtcat(vals, ", '%s'", object->name); xstrfmtcat(extra, ", wckey_name='%s'", object->name); } /* When adding, if this isn't a default might as well force it to be 0 to avoid confusion since uninitialized it is NO_VAL. */ if (object->is_def == 1) { xstrcat(cols, ", is_def"); xstrcat(vals, ", 1"); xstrcat(extra, ", is_def=1"); } else { object->is_def = 0; xstrcat(cols, ", is_def"); xstrcat(vals, ", 0"); xstrcat(extra, ", is_def=0"); } xstrfmtcat(query, "insert into \"%s_%s\" (%s) values (%s) " "on duplicate key update deleted=0, " "id_wckey=LAST_INSERT_ID(id_wckey)%s;", object->cluster, wckey_table, cols, vals, extra); if (debug_flags & DEBUG_FLAG_DB_WCKEY) DB_DEBUG(mysql_conn->conn, "query\n%s", query); object->id = mysql_db_insert_ret_id(mysql_conn, query); xfree(query); if (!object->id) { error("Couldn't add wckey %s", object->name); added=0; xfree(cols); xfree(extra); xfree(vals); break; } affect_rows = last_affected_rows(mysql_conn); if (!affect_rows) { debug2("nothing changed %d", affect_rows); xfree(cols); xfree(extra); xfree(vals); continue; } /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); xstrfmtcat(query, "insert into %s " "(timestamp, action, name, actor, info, cluster) " "values (%ld, %u, 'id_wckey=%d', '%s', '%s', '%s');", txn_table, now, DBD_ADD_WCKEYS, object->id, user_name, tmp_extra, object->cluster); xfree(tmp_extra); xfree(cols); xfree(extra); xfree(vals); debug4("query\n%s",query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); } else { if (addto_update_list(mysql_conn->update_list, SLURMDB_ADD_WCKEY, object) == SLURM_SUCCESS) list_remove(itr); added++; } } list_iterator_destroy(itr); xfree(user_name); if (!added) { reset_mysql_conn(mysql_conn); goto end_it; } /* now reset all the other defaults accordingly. (if needed) */ itr = list_iterator_create(wckey_list); while ((object = list_next(itr))) { if ((object->is_def != 1) || !object->cluster || !object->user || !object->name) continue; if ((rc = _reset_default_wckey(mysql_conn, object) != SLURM_SUCCESS)) break; } list_iterator_destroy(itr); end_it: if (rc == SLURM_SUCCESS) _make_sure_users_have_default(mysql_conn, added_user_list); if (added_user_list) list_destroy(added_user_list); return rc; }
extern int as_mysql_add_federations(mysql_conn_t *mysql_conn, uint32_t uid, List federation_list) { ListIterator itr = NULL; int rc = SLURM_SUCCESS; slurmdb_federation_rec_t *object = NULL; char *cols = NULL, *vals = NULL, *extra = NULL, *query = NULL, *tmp_extra = NULL; time_t now = time(NULL); char *user_name = NULL; int affect_rows = 0; int added = 0; if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_SUPER_USER)) return ESLURM_ACCESS_DENIED; user_name = uid_to_string((uid_t) uid); itr = list_iterator_create(federation_list); while ((object = list_next(itr))) { if (object->cluster_list && (list_count(federation_list) > 1)) { xfree(user_name); error("Clusters can only be assigned to one " "federation"); errno = ESLURM_FED_CLUSTER_MULTIPLE_ASSIGNMENT; return ESLURM_FED_CLUSTER_MULTIPLE_ASSIGNMENT; } xstrcat(cols, "creation_time, mod_time, name"); xstrfmtcat(vals, "%ld, %ld, '%s'", now, now, object->name); xstrfmtcat(extra, ", mod_time=%ld", now); _setup_federation_rec_limits(object, &cols, &vals, &extra); xstrfmtcat(query, "insert into %s (%s) values (%s) " "on duplicate key update deleted=0%s", federation_table, cols, vals, extra); if (debug_flags & DEBUG_FLAG_FEDR) DB_DEBUG(mysql_conn->conn, "query\n%s", query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add federation %s", object->name); xfree(cols); xfree(vals); xfree(extra); added = 0; break; } affect_rows = last_affected_rows(mysql_conn); if (!affect_rows) { debug2("nothing changed %d", affect_rows); xfree(cols); xfree(vals); xfree(extra); continue; } if (object->cluster_list && _assign_clusters_to_federation(mysql_conn, object->name, object->cluster_list)) { xfree(cols); xfree(vals); xfree(extra); xfree(user_name); return SLURM_ERROR; } /* Add Transaction */ /* we always have a ', ' as the first 2 chars */ tmp_extra = slurm_add_slash_to_quotes(extra+2); xstrfmtcat(query, "insert into %s " "(timestamp, action, name, actor, info) " "values (%ld, %u, '%s', '%s', '%s');", txn_table, now, DBD_ADD_FEDERATIONS, object->name, user_name, tmp_extra); xfree(cols); xfree(vals); xfree(tmp_extra); xfree(extra); debug4("%d(%s:%d) query\n%s", mysql_conn->conn, THIS_FILE, __LINE__, query); rc = mysql_db_query(mysql_conn, query); xfree(query); if (rc != SLURM_SUCCESS) { error("Couldn't add txn"); } else { added++; } } list_iterator_destroy(itr); xfree(user_name); if (!added) reset_mysql_conn(mysql_conn); else as_mysql_add_feds_to_update_list(mysql_conn); return rc; }