|
- package slurmer
-
- import "C"
- import pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
-
- /*
- #cgo LDFLAGS: -lslurmdb
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <slurm/slurm.h>
- #include <slurm/slurmdb.h>
- #include<slurm/slurm_errno.h>
- #include <memory.h>
- #include <malloc.h>
-
- typedef struct slurmdb_qos_rec {
- char *description;
- uint32_t id;
- uint32_t flags;
- uint32_t grace_time;
- uint64_t grp_cpu_mins;
- uint64_t grp_cpu_run_mins;
- uint32_t grp_cpus;
- uint32_t grp_jobs;
- uint32_t grp_mem;
- uint32_t grp_nodes;
- uint32_t grp_submit_jobs;
- uint32_t grp_wall;
- uint64_t max_cpu_mins_pj;
- uint64_t max_cpu_run_mins_pu;
- uint32_t max_cpus_pj;
- uint32_t max_cpus_pu;
- uint32_t max_jobs_pu;
- uint32_t max_nodes_pj;
- uint32_t max_nodes_pu;
- uint32_t max_submit_jobs_pu;
- uint32_t max_wall_pj;
- char *name;
- bitstr_t *preempt_bitstr;
- List preempt_list;
- uint16_t preempt_mode;
- uint32_t priority;
- assoc_mgr_qos_usage_t *usage;
- double usage_factor;
- double usage_thres;
- } slurmdb_qos_rec_a;
-
- typedef struct qos_info {
- uint32_t record_count;
- slurmdb_qos_rec_t *array;
- } qos_info_t;
-
- struct qos_info get_qos_list() {
- struct qos_info qosinfo;
-
- slurmdb_qos_cond_t *qos_cond = NULL;
- void *conn = slurmdb_connection_get();
- List qoslist = slurmdb_qos_get(conn, qos_cond);
-
-
- uint16_t size = slurm_list_count(qoslist);
- qosinfo.record_count = size;
- qosinfo.array = malloc(size * sizeof(slurmdb_qos_rec_t));
- //slurmdb_qos_rec_t qosArray[size];
-
- slurmdb_qos_rec_t *rec = NULL;
- ListIterator itr = slurm_list_iterator_create(qoslist);
-
- int i = 0;
- while ((rec = slurm_list_next(itr))) {
- qosinfo.array[i] = *rec;
- i++;
- }
- slurmdb_connection_close(&conn);
- slurm_list_destroy(qoslist);
-
- return qosinfo;
- }
-
- struct slurmdb_qos_rec *qos_from_list(struct qos_info *qos_rec_t, int i) {
- return (struct slurmdb_qos_rec *) &qos_rec_t->array[i];
- }
- */
- import "C"
- import (
- "context"
- )
-
- type Slurmdb_qos_rec struct {
- Description string
- Id uint32
- Flags uint32
- GraceTime uint32
- GrpCpuMins uint64
- GrpCpuRunMins uint64
- GrpCpus uint32
- GrpJobs uint32
- GrpMem uint32
- GrpNodes uint32
- GrpSubmitJobs uint32
- MaxCpuMinsPj uint64
- MaxCpuRunMinsPu uint64
- MaxCpusPj uint32
- MaxCpusPu uint32
- MaxJobsPu uint32
- MaxNodesPj uint32
- MaxNodesPu uint32
- MaxSubmitJobsPu uint32
- MaxWallPj uint32
- Name string
- preemptList []string
- preempt_mode uint16
- priority uint32
- usage_factor float64
- usage_thres float64
- }
-
- type QosInfoMsg struct {
- RecordCount uint32
- QosList []pbslurm.QosInfo
- }
-
- func QosDescriptorConvertCToGo(cStruct *C.struct_slurmdb_qos_rec) pbslurm.QosInfo {
- var goStruct pbslurm.QosInfo
- goStruct.Name = C.GoString(cStruct.name)
- return goStruct
- }
-
- func GetQosInfo() QosInfoMsg {
- var goQosBuffer QosInfoMsg
- cQosBuffer := C.get_qos_list()
- goQosBuffer.RecordCount = uint32(cQosBuffer.record_count)
- goQosBuffer.QosList = make([]pbslurm.QosInfo, cQosBuffer.record_count, cQosBuffer.record_count)
-
- for i := uint32(0); i < goQosBuffer.RecordCount; i++ {
- qos := C.qos_from_list(&cQosBuffer, C.int(i))
- goQos := QosDescriptorConvertCToGo(qos)
- goQosBuffer.QosList[i] = goQos
- }
- return goQosBuffer
- }
-
- func (slurmStruct SlurmStruct) ListQoss(ctx context.Context, req *pbslurm.ListQossReq) (*pbslurm.ListQossResp, error) {
-
- qosList := GetQosInfo()
-
- resp := pbslurm.ListQossResp{}
- for _, qos := range qosList.QosList {
- qosInfoResult := qos
- //userInfoResult.Name = user.Name
-
- resp.QosInfos = append(resp.QosInfos, &qosInfoResult)
- }
-
- return &resp, nil
- }
|