|
- package slurmer
-
- /*
- #cgo LDFLAGS: -lslurmdb
-
- #include <stdio.h>
- #include <slurm/slurm.h>
- #include <slurm/slurmdb.h>
- #include <memory.h>
- #include <malloc.h>
-
- typedef struct account_info_msg {
- uint32_t record_count;
- slurmdb_account_rec_t *account_array;
- } account_info_msg_t;
-
- typedef struct slurmdb_account_rec{
- List assoc_list;
- List coord_accts;
- char *description;
- char *name;
- char *organization;
- } slurmdb_account_rec_pcm;
-
- struct account_info_msg get_account_info() {
- struct account_info_msg accountinfo;
- List accountList = NULL;
- slurmdb_account_cond_t *account_cond = NULL;
- void *db_conn;
- db_conn = slurmdb_connection_get();
- accountList = slurmdb_accounts_get(db_conn, account_cond);
- slurmdb_connection_close(&db_conn);
-
- slurmdb_account_rec_t *rec = NULL;
- ListIterator itr = slurm_list_iterator_create(accountList);
- int i = 0;
- uint32_t length;
- length = slurm_list_count(accountList);
- accountinfo.record_count = length;
- accountinfo.account_array = malloc(length * sizeof(slurmdb_account_rec_t));
- while ((rec = slurm_list_next(itr))) {
- accountinfo.account_array[i] = *rec;
- i++;
- }
- return accountinfo;
- }
-
- struct slurmdb_account_rec *account_from_list(struct account_info_msg *list, int i) {
- return (struct slurmdb_account_rec *) &list->account_array[i];
- }
-
- */
- import "C"
- import (
- pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
- "context"
- )
-
- type AcctInfoMsg struct {
- LastUpdate int64
- RecordCount uint32
- AcctInfoList []pbslurm.AccountInfo
- }
-
- func AcctDescriptorConvertCToGo(cStruct *C.struct_slurmdb_account_rec) pbslurm.AccountInfo {
- var goStruct pbslurm.AccountInfo
- goStruct.Name = C.GoString(cStruct.name)
- return goStruct
- }
-
- func GetAcctInfo() AcctInfoMsg {
- var goAcctBuffer AcctInfoMsg
- cAcctBuffer := C.get_account_info()
- goAcctBuffer.RecordCount = uint32(cAcctBuffer.record_count)
- goAcctBuffer.AcctInfoList = make([]pbslurm.AccountInfo, cAcctBuffer.record_count, cAcctBuffer.record_count)
-
- for i := uint32(0); i < goAcctBuffer.RecordCount; i++ {
- Acct := C.account_from_list(&cAcctBuffer, C.int(i))
- goAcct := AcctDescriptorConvertCToGo(Acct)
- goAcctBuffer.AcctInfoList[i] = goAcct
- }
- return goAcctBuffer
- }
-
- func (slurmStruct SlurmStruct) ListAccounts(ctx context.Context, req *pbslurm.ListAccountsReq) (*pbslurm.ListAccountsResp, error) {
-
- AcctList := GetAcctInfo()
-
- resp := pbslurm.ListAccountsResp{}
- for _, Acct := range AcctList.AcctInfoList {
- AcctInfoResult := pbslurm.AccountInfo{}
- AcctInfoResult.Name = Acct.Name
-
- resp.AccountInfos = append(resp.AccountInfos, &AcctInfoResult)
- }
-
- return &resp, nil
- }
-
- func (slurmStruct SlurmStruct) GetAccount(ctx context.Context, req *pbslurm.GetAccountReq) (*pbslurm.GetAccountResp, error) {
-
- AcctList := GetAcctInfo()
-
- resp := pbslurm.GetAccountResp{}
- for _, Acct := range AcctList.AcctInfoList {
- AcctInfoResult := pbslurm.AccountInfo{}
- AcctInfoResult.Name = Acct.Name
-
- resp.AccountInfos = append(resp.AccountInfos, &AcctInfoResult)
- }
-
- return &resp, nil
- }
|