|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- package slurmer
-
- /*
- #cgo LDFLAGS: -lslurm
- #include<stdlib.h>
- #include<slurm/slurm.h>
- #include<slurm/slurm_errno.h>
- inline uint8_t uint8_ptr(uint8_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- inline int8_t int8_ptr(int8_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- uint16_t uint16_ptr(uint16_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- inline int16_t int16_ptr(int16_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- inline uint32_t uint32_ptr(uint32_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- inline int32_t int32_ptr(int32_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- inline uint64_t uint64_ptr(uint64_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- inline int64_t int64_ptr(int16_t* pointer) {
- if (NULL == pointer) {
- return -1;}
- return *pointer;
- }
- 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"
- "context"
- "strings"
- )
-
- 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 (slurmStruct SlurmStruct) ListNodes(ctx context.Context, req *pbslurm.ListNodesReq) (*pbslurm.ListNodesResp, error) {
- nodeList := Get_all_nodes()
- var resp = pbslurm.ListNodesResp{}
- for _, node := range nodeList.NodeInfoList {
- nodeInfoResult := pbslurm.NodeInfo{}
- nodeInfoResult.Cpus = uint32(node.Cpus)
- nodeInfoResult.Boards = uint32(node.Boards)
- nodeInfoResult.RealMemory = node.RealMemory
- nodeInfoResult.Sockets = uint32(node.Sockets)
- nodeInfoResult.Threads = uint32(node.Threads)
- resp.NodeInfos = append(resp.NodeInfos, &nodeInfoResult)
- }
-
- return &resp, nil
- }
-
- 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
- }
-
- 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 (slurmStruct SlurmStruct) GetNode(ctx context.Context, req *pbslurm.GetNodeReq) (*pbslurm.GetNodeResp, error) {
- NodeList := GetNodeInfo()
- resp := pbslurm.GetNodeResp{}
- for _, node := range NodeList.NodeInfoList {
- nodeInfoResult := node
- if strings.Contains(node.Name, req.NodeName) {
- resp.NodeInfos = append(resp.NodeInfos, &nodeInfoResult)
- }
- }
- return &resp, nil
- }
-
- /*func (slurmStruct SlurmStruct) GetNodeByName(ctx context.Context, req *pbnode.NodeInfoMsgReq) (*pbnode.NodeInfoMsgResp, error) {
- node := Get_node_info(req.NodeName)
- var resp = pbnode.NodeInfoMsgResp{}
- for _, node := range node.Node_list {
- nodeInfoResult := pbnode.Node_Info{}
- nodeInfoResult.Cpus = uint32(node.Cpus)
- nodeInfoResult.Boards = uint32(node.Boards)
- nodeInfoResult.RealMemory = node.RealMemory
- nodeInfoResult.Sockets = uint32(node.Sockets)
- nodeInfoResult.Threads = uint32(node.Threads)
- resp.NodeList = append(resp.NodeList, &nodeInfoResult)
- }
-
- return &resp, nil
- }*/
|