diff --git a/src/common/slurm_accounting_storage.c b/src/common/slurm_accounting_storage.c index 866d9a65d0ef69ca7d016a3d6ef3706b7d357b28..c3e7ed3b8d50b8b1797dbeb620850629529d0efe 100644 --- a/src/common/slurm_accounting_storage.c +++ b/src/common/slurm_accounting_storage.c @@ -1202,6 +1202,8 @@ extern void pack_acct_cluster_cond(void *in, Buf buffer) uint32_t count = 0; if(!object) { + pack32(0, buffer); + pack32(0, buffer); pack32(0, buffer); pack16(0, buffer); return; @@ -1219,6 +1221,10 @@ extern void pack_acct_cluster_cond(void *in, Buf buffer) } list_iterator_destroy(itr); } + + pack32(object->usage_end, buffer); + pack32(object->usage_start, buffer); + pack16((uint16_t)object->with_usage, buffer); } @@ -1239,6 +1245,9 @@ extern int unpack_acct_cluster_cond(void **object, Buf buffer) list_append(object_ptr->cluster_list, tmp_info); } } + safe_unpack32(&object_ptr->usage_end, buffer); + safe_unpack32(&object_ptr->usage_start, buffer); + safe_unpack16((uint16_t *)&object_ptr->with_usage, buffer); return SLURM_SUCCESS; @@ -1269,6 +1278,8 @@ extern void pack_acct_association_cond(void *in, Buf buffer) pack32(0, buffer); packnull(buffer); pack32(0, buffer); + pack32(0, buffer); + pack32(0, buffer); pack16(0, buffer); return; } @@ -1333,6 +1344,9 @@ extern void pack_acct_association_cond(void *in, Buf buffer) packstr(object->parent_acct, buffer); + pack32(object->usage_end, buffer); + pack32(object->usage_start, buffer); + if(object->user_list) count = list_count(object->user_list); @@ -1403,6 +1417,9 @@ extern int unpack_acct_association_cond(void **object, Buf buffer) safe_unpackstr_xmalloc(&object_ptr->parent_acct, &uint32_tmp, buffer); + safe_unpack32(&object_ptr->usage_end, buffer); + safe_unpack32(&object_ptr->usage_start, buffer); + safe_unpack32(&count, buffer); if(count) { object_ptr->user_list = list_create(slurm_destroy_char); diff --git a/src/common/slurm_accounting_storage.h b/src/common/slurm_accounting_storage.h index 5d4879b51839caf3a9cad051acf6116813e7556d..6f33806dbdfd69b9dfa93d82d0231a9516ccbc6c 100644 --- a/src/common/slurm_accounting_storage.h +++ b/src/common/slurm_accounting_storage.h @@ -87,6 +87,8 @@ typedef struct { * can run a job (seconds) */ List partition_list; /* list of char * */ char *parent_acct; /* name of parent account */ + uint32_t usage_end; + uint32_t usage_start; List user_list; /* list of char * */ uint16_t with_usage; } acct_association_cond_t; @@ -144,6 +146,8 @@ typedef struct acct_association_rec { typedef struct { List cluster_list; /* list of char * */ + uint32_t usage_end; + uint32_t usage_start; uint16_t with_usage; } acct_cluster_cond_t; diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c index b0b2d34e0169c325242bf97241cdde148f309633..f6e1b72c925f9eaab5b0779031f926d0c420a6b1 100644 --- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c +++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c @@ -117,9 +117,19 @@ extern int acct_storage_p_commit(mysql_conn_t *mysql_conn, bool commit); extern int acct_storage_p_add_associations(mysql_conn_t *mysql_conn, uint32_t uid, List association_list); + extern List acct_storage_p_get_associations(mysql_conn_t *mysql_conn, acct_association_cond_t *assoc_q); +extern int acct_storage_p_get_usage(mysql_conn_t *mysql_conn, + acct_association_rec_t *acct_assoc, + time_t start, time_t end); + +extern int clusteracct_storage_p_get_usage( + mysql_conn_t *mysql_conn, + acct_cluster_rec_t *cluster_rec, time_t start, time_t end); + + /* This function will take the object given and free it later so it * needed to be removed from a list if in one before */ @@ -4099,6 +4109,14 @@ empty: list_append(cluster_list, cluster); cluster->name = xstrdup(row[CLUSTER_REQ_NAME]); + + /* get the usage if requested */ + if(cluster_q->with_usage) { + clusteracct_storage_p_get_usage(mysql_conn, cluster, + cluster_q->usage_start, + cluster_q->usage_end); + } + cluster->control_host = xstrdup(row[CLUSTER_REQ_CH]); cluster->control_port = atoi(row[CLUSTER_REQ_CP]); query = xstrdup_printf("select %s from %s where cluster='%s' " @@ -4326,7 +4344,14 @@ empty: list_append(assoc_list, assoc); assoc->id = atoi(row[ASSOC_REQ_ID]); - + + /* get the usage if requested */ + if(assoc_q->with_usage) { + acct_storage_p_get_usage(mysql_conn, assoc, + assoc_q->usage_start, + assoc_q->usage_end); + } + if(row[ASSOC_REQ_USER][0]) assoc->user = xstrdup(row[ASSOC_REQ_USER]); assoc->acct = xstrdup(row[ASSOC_REQ_ACCT]);