forked from JointCloud/pcm-coordinator
160 lines
4.4 KiB
Go
160 lines
4.4 KiB
Go
package tianhe
|
|
|
|
/*
|
|
#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 *rec = NULL;
|
|
|
|
//slurmdb_init_qos_rec()
|
|
|
|
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;
|
|
}
|
|
|
|
slurmdb_qos_rec_t *qos_from_list(struct qos_info *qos_rec_t, int i) {
|
|
return (slurmdb_qos_rec_t *) &qos_rec_t->array[i];
|
|
}
|
|
|
|
slurmdb_qos_rec_t *qos_from_list_by_name(slurmdb_qos_rec_t *qos_rec_array, char* qos_name) {
|
|
int i;
|
|
int arraysize = sizeof(qos_rec_array);
|
|
for (i=0; i<arraysize; i++)
|
|
{
|
|
if (strcmp(qos_name, (qos_rec_array[i]).name) == 0)
|
|
{
|
|
break;
|
|
} else {
|
|
return NULL;
|
|
}
|
|
}
|
|
return (slurmdb_qos_rec_t *) &(qos_rec_array[i]);
|
|
}
|
|
*/
|
|
import "C"
|
|
import pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
|
|
|
|
func Get_Qos() []*pbslurm.SlurmdbQosRec {
|
|
var go_qos_buffer pbslurm.QosInfoMsg
|
|
c_qos_buffer := C.Get_qos_list()
|
|
|
|
go_qos_buffer.RecordCount = uint32(c_qos_buffer.record_count)
|
|
for i := uint32(0); i < go_qos_buffer.RecordCount; i++ {
|
|
qos := C.qos_from_list(&c_qos_buffer, C.int(i))
|
|
go_qos := Qos_convert_c_to_go(qos)
|
|
go_qos_buffer.SlurmdbQosRec = append(go_qos_buffer.SlurmdbQosRec, &go_qos)
|
|
}
|
|
return go_qos_buffer.SlurmdbQosRec
|
|
}
|
|
|
|
func GetQosByName(name string) pbslurm.SlurmdbQosRec {
|
|
qos := pbslurm.SlurmdbQosRec{}
|
|
qos_list := C.Get_qos_list()
|
|
c_qos := C.qos_from_list_by_name(qos_list.array, C.CString(name))
|
|
|
|
if c_qos == nil {
|
|
return qos
|
|
}
|
|
go_qos := Qos_convert_c_to_go(c_qos)
|
|
return go_qos
|
|
}
|
|
|
|
func Qos_convert_c_to_go(c_struct *C.slurmdb_qos_rec_t) pbslurm.SlurmdbQosRec {
|
|
var go_struct pbslurm.SlurmdbQosRec
|
|
|
|
go_struct.Description = C.GoString(c_struct.description)
|
|
go_struct.Flags = uint32(c_struct.flags)
|
|
go_struct.GrpCpus = uint32(c_struct.grp_cpus)
|
|
go_struct.GraceTime = uint32(c_struct.grace_time)
|
|
go_struct.GrpCpuMins = uint64(c_struct.grp_cpu_mins)
|
|
go_struct.GrpCpuRunMins = uint64(c_struct.grp_cpu_run_mins)
|
|
go_struct.GrpJobs = uint32(c_struct.grp_jobs)
|
|
go_struct.GrpMem = uint32(c_struct.grp_mem)
|
|
go_struct.GrpNodes = uint32(c_struct.grp_nodes)
|
|
go_struct.GrpSubmitJobs = uint32(c_struct.grp_submit_jobs)
|
|
go_struct.GrpWall = uint32(c_struct.grp_wall)
|
|
go_struct.Id = uint32(c_struct.id)
|
|
go_struct.MaxCpusPj = uint32(c_struct.max_cpus_pj)
|
|
go_struct.MaxCpuMinsPj = uint64(c_struct.max_cpu_mins_pj)
|
|
go_struct.MaxCpusPu = uint32(c_struct.max_cpus_pu)
|
|
go_struct.MaxJobsPu = uint32(c_struct.max_jobs_pu)
|
|
go_struct.MaxCpuRunMinsPu = uint64(c_struct.max_cpu_run_mins_pu)
|
|
go_struct.MaxNodesPj = uint32(c_struct.max_nodes_pj)
|
|
go_struct.MaxNodesPu = uint32(c_struct.max_nodes_pu)
|
|
go_struct.MaxSubmitJobsPu = uint32(c_struct.max_submit_jobs_pu)
|
|
go_struct.MaxWallPj = uint32(c_struct.max_wall_pj)
|
|
go_struct.Name = C.GoString(c_struct.name)
|
|
go_struct.Priority = uint32(c_struct.priority)
|
|
//go_struct.PreemptList = c_struct.preempt_list
|
|
go_struct.PreemptMode = uint32(c_struct.preempt_mode)
|
|
go_struct.UsageThres = float64(c_struct.usage_factor)
|
|
go_struct.UsageFactor = float64(c_struct.usage_thres)
|
|
|
|
return go_struct
|
|
}
|