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