pcm-coordinator/adaptor/pcm_slurm/service/tianhe/node.go

112 lines
3.5 KiB
Go

package tianhe
/*
#include<stdlib.h>
#include<slurm/slurm.h>
#include<slurm/slurm_errno.h>
struct node_info_msg *get_node_info(){
struct node_info_msg* node_buffer;
if(slurm_load_node ((time_t) NULL,
&node_buffer, SHOW_ALL))
return NULL;
return node_buffer;
}
struct node_info_msg *get_single_node_info(char* name){
struct node_info_msg* node_buffer;
if( slurm_load_node_single (&node_buffer, name, SHOW_DETAIL))
return NULL;
return node_buffer;
}
struct node_info* node_from_list(struct node_info_msg *list, int i){
return &list->node_array[i];
}
void free_node_buffer(void* buffer){
slurm_free_node_info_msg ((struct node_info_msg*)buffer);
}
*/
import "C"
import (
pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
)
type NodeInfoMsg struct {
LastUpdate int64
RecordCount uint32
ErrorCode uint32
NodeInfoList []pbslurm.NodeInfo
}
func Node_info_convert_c_to_go(c_struct *C.struct_node_info) pbslurm.NodeInfo {
var go_struct pbslurm.NodeInfo
go_struct.Arch = C.GoString(c_struct.arch)
go_struct.Boards = uint32(c_struct.boards)
go_struct.BootTime = int64(c_struct.boot_time)
go_struct.Cores = uint32(c_struct.cores)
go_struct.CpuLoad = uint32(c_struct.cpu_load)
go_struct.Cpus = uint32(c_struct.cpus)
go_struct.Features = C.GoString(c_struct.features)
go_struct.Gres = C.GoString(c_struct.gres)
go_struct.Name = C.GoString(c_struct.name)
go_struct.NodeAddr = C.GoString(c_struct.node_addr)
go_struct.NodeHostname = C.GoString(c_struct.node_hostname)
go_struct.NodeState = uint32(c_struct.node_state)
go_struct.Os = C.GoString(c_struct.os)
go_struct.RealMemory = uint64(c_struct.real_memory)
go_struct.Reason = C.GoString(c_struct.reason)
go_struct.ReasonTime = int64(c_struct.reason_time)
go_struct.ReasonUid = uint32(c_struct.reason_uid)
go_struct.SlurmdStartTime = int64(c_struct.slurmd_start_time)
go_struct.Sockets = uint32(c_struct.sockets)
go_struct.Threads = uint32(c_struct.threads)
go_struct.TmpDisk = uint32(c_struct.tmp_disk)
go_struct.Weight = uint32(c_struct.weight)
return go_struct
}
func NodeDescriptorConvertCToGo(cStruct *C.struct_node_info) pbslurm.NodeInfo {
var goStruct pbslurm.NodeInfo
goStruct.Name = C.GoString(cStruct.name)
return goStruct
}
func GetNodeInfo() NodeInfoMsg {
var goNodeBuffer NodeInfoMsg
cNodeBuffer := C.get_node_info()
goNodeBuffer.RecordCount = uint32(cNodeBuffer.record_count)
goNodeBuffer.NodeInfoList = make([]pbslurm.NodeInfo, cNodeBuffer.record_count, cNodeBuffer.record_count)
for i := uint32(0); i < goNodeBuffer.RecordCount; i++ {
Node := C.node_from_list(cNodeBuffer, C.int(i))
goNode := NodeDescriptorConvertCToGo(Node)
goNodeBuffer.NodeInfoList[i] = goNode
}
return goNodeBuffer
}
func Get_all_nodes() NodeInfoMsg {
var go_node_buffer NodeInfoMsg
c_node_buffer := C.get_node_info()
if c_node_buffer == nil {
go_node_buffer.LastUpdate = int64(0)
go_node_buffer.RecordCount = uint32(0)
go_node_buffer.ErrorCode = uint32(C.slurm_get_errno())
return go_node_buffer
}
go_node_buffer.LastUpdate = int64(c_node_buffer.last_update)
go_node_buffer.RecordCount = uint32(c_node_buffer.record_count)
go_node_buffer.NodeInfoList = make([]pbslurm.NodeInfo, c_node_buffer.record_count, c_node_buffer.record_count)
for i := uint32(0); i < go_node_buffer.RecordCount; i++ {
node := C.node_from_list(c_node_buffer, C.int(i))
go_node := Node_info_convert_c_to_go(node)
go_node_buffer.NodeInfoList[i] = go_node
}
C.slurm_free_node_info_msg(c_node_buffer)
return go_node_buffer
}