View | Details | Raw Unified | Return to ticket 13519
Collapse All | Expand All

(-)a/src/plugins/openapi/dbv0.0.37/associations.c (-3 / +1 lines)
Lines 163-169 static int _delete_assoc(data_t *resp, void *auth, data_t *errors, Link Here
163
			 char *partition)
163
			 char *partition)
164
{
164
{
165
	int rc = SLURM_SUCCESS;
165
	int rc = SLURM_SUCCESS;
166
	List removed;
166
	List removed = NULL;
167
	slurmdb_assoc_cond_t assoc_cond = {
167
	slurmdb_assoc_cond_t assoc_cond = {
168
		.acct_list = list_create(NULL),
168
		.acct_list = list_create(NULL),
169
		.user_list = list_create(NULL),
169
		.user_list = list_create(NULL),
170
- 
171
--
172
src/plugins/openapi/dbv0.0.37/associations.c | 6 ++++--
170
src/plugins/openapi/dbv0.0.37/associations.c | 6 ++++--
173
1 file changed, 4 insertions(+), 2 deletions(-)
171
1 file changed, 4 insertions(+), 2 deletions(-)
(-)a/src/plugins/openapi/dbv0.0.37/associations.c (-4 / +4 lines)
Lines 166-172 static int _delete_assoc(data_t *resp, void *auth, data_t *errors, Link Here
166
	List removed = NULL;
166
	List removed = NULL;
167
	slurmdb_assoc_cond_t assoc_cond = {
167
	slurmdb_assoc_cond_t assoc_cond = {
168
		.acct_list = list_create(NULL),
168
		.acct_list = list_create(NULL),
169
		.user_list = list_create(NULL),
170
	};
169
	};
171
170
172
	list_append(assoc_cond.acct_list, account);
171
	list_append(assoc_cond.acct_list, account);
Lines 174-180 static int _delete_assoc(data_t *resp, void *auth, data_t *errors, Link Here
174
		assoc_cond.cluster_list = list_create(NULL);
173
		assoc_cond.cluster_list = list_create(NULL);
175
		list_append(assoc_cond.cluster_list, cluster);
174
		list_append(assoc_cond.cluster_list, cluster);
176
	}
175
	}
177
	list_append(assoc_cond.user_list, user);
176
	if (user) {
177
		assoc_cond.user_list = list_create(NULL),
178
		list_append(assoc_cond.user_list, user);
179
	}
178
	if (partition) {
180
	if (partition) {
179
		assoc_cond.partition_list = list_create(NULL);
181
		assoc_cond.partition_list = list_create(NULL);
180
		list_append(assoc_cond.partition_list, partition);
182
		list_append(assoc_cond.partition_list, partition);
181
- 
182
--
183
src/plugins/openapi/dbv0.0.37/api.c | 29 +++++++++++++++++++++++++++++
183
src/plugins/openapi/dbv0.0.37/api.c | 29 +++++++++++++++++++++++++++++
184
src/plugins/openapi/dbv0.0.37/api.h | 28 ++++++++++++++++++++++++++++
184
src/plugins/openapi/dbv0.0.37/api.h | 28 ++++++++++++++++++++++++++++
185
2 files changed, 57 insertions(+)
185
2 files changed, 57 insertions(+)
(-)a/src/plugins/openapi/dbv0.0.37/api.c (+29 lines)
Lines 195-200 extern int db_query_rc_funcname(data_t *errors, Link Here
195
	return rc;
195
	return rc;
196
}
196
}
197
197
198
extern int db_modify_rc_funcname(data_t *errors, rest_auth_context_t *auth,
199
				 void *cond, void *obj,
200
				 db_rc_modify_func_t func,
201
				 const char *func_name)
202
{
203
	List changed;
204
	int rc = SLURM_SUCCESS;
205
	void *db_conn;
206
207
	if (!(db_conn = openapi_get_db_conn(auth))) {
208
		return resp_error(errors, ESLURM_DB_CONNECTION,
209
				  "Failed connecting to slurmdbd", func_name);
210
	}
211
212
	errno = 0;
213
	if (!(changed = func(db_conn, cond, obj))) {
214
		if (errno)
215
			rc = errno;
216
		else
217
			rc = SLURM_ERROR;
218
219
		return resp_error(errors, rc, NULL, func_name);
220
	}
221
222
	FREE_NULL_LIST(changed);
223
224
	return rc;
225
}
226
198
extern int db_query_commit(data_t *errors, rest_auth_context_t *auth)
227
extern int db_query_commit(data_t *errors, rest_auth_context_t *auth)
199
{
228
{
200
	int rc;
229
	int rc;
(-)a/src/plugins/openapi/dbv0.0.37/api.h (-2 / +28 lines)
Lines 76-81 typedef List (*db_list_query_func_t)(void *db_conn, void *cond); Link Here
76
 * rc if the query was successful.
76
 * rc if the query was successful.
77
 */
77
 */
78
typedef int (*db_rc_query_func_t)(void *db_conn, List list);
78
typedef int (*db_rc_query_func_t)(void *db_conn, List list);
79
/*
80
 * Generic typedef for the DB modify functions that takes an object record and
81
 * returns an List if the query was successful or NULL on error
82
 */
83
typedef List (*db_rc_modify_func_t)(void *db_conn, void **cond, void *obj);
79
84
80
/* ------------ handlers for slurmdbd queries --------------- */
85
/* ------------ handlers for slurmdbd queries --------------- */
81
86
Lines 123-128 extern int db_query_rc_funcname(data_t *errors, Link Here
123
				db_rc_query_func_t func,
128
				db_rc_query_func_t func,
124
				const char *func_name);
129
				const char *func_name);
125
130
131
/*
132
 * Macro helper for modify database API for List output.
133
 * Converts the function name to string.
134
 */
135
#define db_modify_rc(errors, auth, cond, obj, func)                  \
136
	db_modify_rc_funcname(errors, auth, cond, obj,               \
137
			      (db_rc_modify_func_t)func, #func)
138
139
/*
140
 * Modify object in database API
141
 * IN errors - data list to append a new error
142
 * IN auth - connection authentication attr
143
 * IN cond - ptr to filter conditional to pass to func
144
 * IN obj - ptr to obj to pass to func
145
 * IN func - function ptr to call
146
 * IN func_name - string of func name (for errors)
147
 * RET SLURM_SUCCESS or error
148
 */
149
extern int db_modify_rc_funcname(data_t *errors, rest_auth_context_t *auth,
150
				 void *cond, void *obj,
151
				 db_rc_modify_func_t func,
152
				 const char *func_name);
153
126
/*
154
/*
127
 * Request database API to commit connection
155
 * Request database API to commit connection
128
 * IN errors - data list to append a new error
156
 * IN errors - data list to append a new error
129
- 
130
associations
157
associations
131
--
132
NEWS                                         |  2 +
158
NEWS                                         |  2 +
133
src/plugins/openapi/dbv0.0.37/associations.c | 60 ++++++++++++++++----
159
src/plugins/openapi/dbv0.0.37/associations.c | 60 ++++++++++++++++----
134
2 files changed, 52 insertions(+), 10 deletions(-)
160
2 files changed, 52 insertions(+), 10 deletions(-)
(-)a/NEWS (+2 lines)
Lines 60-65 documents those changes that are of interest to users and administrators. Link Here
60
 -- serializer/yaml - use dynamic buffer to allow creation of YAML outputs
60
 -- serializer/yaml - use dynamic buffer to allow creation of YAML outputs
61
    larger than 1MiB.
61
    larger than 1MiB.
62
 -- Fix minor memory leak affecting openapi users at process termination.
62
 -- Fix minor memory leak affecting openapi users at process termination.
63
 -- openapi/dbv0.0.37 - Correct issue where modifing existing association
64
    requests were silently ignored.
63
65
64
* Changes in Slurm 21.08.5
66
* Changes in Slurm 21.08.5
65
==========================
67
==========================
(-)a/src/plugins/openapi/dbv0.0.37/associations.c (-11 / +50 lines)
Lines 205-211 static int _delete_assoc(data_t *resp, void *auth, data_t *errors, Link Here
205
#define MAGIC_FOREACH_UP_ASSOC 0xbaed2a12
205
#define MAGIC_FOREACH_UP_ASSOC 0xbaed2a12
206
typedef struct {
206
typedef struct {
207
	int magic;
207
	int magic;
208
	List assoc_list;
209
	List tres_list;
208
	List tres_list;
210
	List qos_list;
209
	List qos_list;
211
	data_t *errors;
210
	data_t *errors;
Lines 222-227 static data_for_each_cmd_t _foreach_update_assoc(data_t *data, void *arg) Link Here
222
		.g_qos_list = args->qos_list,
221
		.g_qos_list = args->qos_list,
223
		.auth = args->auth,
222
		.auth = args->auth,
224
	};
223
	};
224
	int rc;
225
	List assoc_list = NULL;
226
	slurmdb_assoc_cond_t cond = {0};
227
	data_t *query_errors = data_new();
225
228
226
	xassert(args->magic == MAGIC_FOREACH_UP_ASSOC);
229
	xassert(args->magic == MAGIC_FOREACH_UP_ASSOC);
227
230
Lines 234-245 static data_for_each_cmd_t _foreach_update_assoc(data_t *data, void *arg) Link Here
234
	assoc = xmalloc(sizeof(*assoc));
237
	assoc = xmalloc(sizeof(*assoc));
235
	slurmdb_init_assoc_rec(assoc, false);
238
	slurmdb_init_assoc_rec(assoc, false);
236
239
237
	list_append(args->assoc_list, assoc);
238
239
	if (parse(PARSE_ASSOC, assoc, data, args->errors, &penv))
240
	if (parse(PARSE_ASSOC, assoc, data, args->errors, &penv))
240
		return DATA_FOR_EACH_FAIL;
241
		return DATA_FOR_EACH_FAIL;
241
242
242
	return DATA_FOR_EACH_CONT;
243
	if (assoc->acct) {
244
		cond.acct_list = list_create(NULL);
245
		list_append(cond.acct_list, assoc->acct);
246
	}
247
	if (assoc->cluster) {
248
		cond.cluster_list = list_create(NULL);
249
		list_append(cond.cluster_list, assoc->cluster);
250
	}
251
	if (assoc->partition) {
252
		cond.partition_list = list_create(NULL);
253
		list_append(cond.partition_list, assoc->partition);
254
	}
255
	if (assoc->user) {
256
		cond.user_list = list_create(NULL);
257
		list_append(cond.user_list, assoc->user);
258
	}
259
260
	if ((rc = db_query_list(query_errors, args->auth, &assoc_list,
261
				 slurmdb_associations_get, &cond)) ||
262
	    list_is_empty(assoc_list)) {
263
		FREE_NULL_LIST(assoc_list);
264
		assoc_list = list_create(slurmdb_destroy_assoc_rec);
265
		list_append(assoc_list, assoc);
266
267
		debug("%s: adding association request: acct=%s cluster=%s partition=%s user=%s",
268
		      __func__, assoc->acct, assoc->cluster, assoc->partition, assoc->user);
269
270
		rc = db_query_rc(errors, args->auth, assoc_list, slurmdb_associations_add);
271
	} else if (list_count(assoc_list) > 1) {
272
		rc = resp_error(errors, ESLURM_REST_INVALID_QUERY, "ambiguous modify request", "slurmdb_associations_get");
273
	} else {
274
		debug("%s: modifying association request: acct=%s cluster=%s partition=%s user=%s",
275
		      __func__, assoc->acct, assoc->cluster, assoc->partition, assoc->user);
276
277
		rc = db_modify_rc(errors, args->auth, &cond, assoc, slurmdb_associations_modify);
278
	}
279
280
	FREE_NULL_LIST(assoc_list);
281
	FREE_NULL_LIST(cond.acct_list);
282
	FREE_NULL_LIST(cond.cluster_list);
283
	FREE_NULL_LIST(cond.partition_list);
284
	FREE_NULL_LIST(cond.user_list);
285
	FREE_NULL_DATA(query_errors);
286
287
	return rc ? DATA_FOR_EACH_FAIL : DATA_FOR_EACH_CONT;
243
}
288
}
244
289
245
static int _update_assocations(data_t *query, data_t *resp,
290
static int _update_assocations(data_t *query, data_t *resp,
Lines 257-263 static int _update_assocations(data_t *query, data_t *resp, Link Here
257
		.magic = MAGIC_FOREACH_UP_ASSOC,
302
		.magic = MAGIC_FOREACH_UP_ASSOC,
258
		.auth = auth,
303
		.auth = auth,
259
		.errors = errors,
304
		.errors = errors,
260
		.assoc_list = list_create(slurmdb_destroy_assoc_rec),
261
	};
305
	};
262
	data_t *dassoc = get_query_key_list("associations", errors, query);
306
	data_t *dassoc = get_query_key_list("associations", errors, query);
263
307
Lines 269-281 static int _update_assocations(data_t *query, data_t *resp, Link Here
269
	    (data_list_for_each(dassoc, _foreach_update_assoc, &args) < 0))
313
	    (data_list_for_each(dassoc, _foreach_update_assoc, &args) < 0))
270
		rc = ESLURM_REST_INVALID_QUERY;
314
		rc = ESLURM_REST_INVALID_QUERY;
271
315
272
	if (!rc &&
316
	if (!rc && commit)
273
	    !(rc = db_query_rc(errors, auth, args.assoc_list,
274
			       slurmdb_associations_add)) &&
275
	    commit)
276
		rc = db_query_commit(errors, auth);
317
		rc = db_query_commit(errors, auth);
277
318
278
	FREE_NULL_LIST(args.assoc_list);
279
	FREE_NULL_LIST(args.tres_list);
319
	FREE_NULL_LIST(args.tres_list);
280
320
281
	return rc;
321
	return rc;
282
- 

Return to ticket 13519