You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slurm_node.go 6.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package slurmer
  2. /*
  3. #cgo LDFLAGS: -lslurm
  4. #include<stdlib.h>
  5. #include<slurm/slurm.h>
  6. #include<slurm/slurm_errno.h>
  7. inline uint8_t uint8_ptr(uint8_t* pointer) {
  8. if (NULL == pointer) {
  9. return -1;}
  10. return *pointer;
  11. }
  12. inline int8_t int8_ptr(int8_t* pointer) {
  13. if (NULL == pointer) {
  14. return -1;}
  15. return *pointer;
  16. }
  17. uint16_t uint16_ptr(uint16_t* pointer) {
  18. if (NULL == pointer) {
  19. return -1;}
  20. return *pointer;
  21. }
  22. inline int16_t int16_ptr(int16_t* pointer) {
  23. if (NULL == pointer) {
  24. return -1;}
  25. return *pointer;
  26. }
  27. inline uint32_t uint32_ptr(uint32_t* pointer) {
  28. if (NULL == pointer) {
  29. return -1;}
  30. return *pointer;
  31. }
  32. inline int32_t int32_ptr(int32_t* pointer) {
  33. if (NULL == pointer) {
  34. return -1;}
  35. return *pointer;
  36. }
  37. inline uint64_t uint64_ptr(uint64_t* pointer) {
  38. if (NULL == pointer) {
  39. return -1;}
  40. return *pointer;
  41. }
  42. inline int64_t int64_ptr(int16_t* pointer) {
  43. if (NULL == pointer) {
  44. return -1;}
  45. return *pointer;
  46. }
  47. struct node_info_msg *get_node_info(){
  48. struct node_info_msg* node_buffer;
  49. if(slurm_load_node ((time_t) NULL,
  50. &node_buffer, SHOW_ALL))
  51. return NULL;
  52. return node_buffer;
  53. }
  54. struct node_info_msg *get_single_node_info(char* name){
  55. struct node_info_msg* node_buffer;
  56. if( slurm_load_node_single (&node_buffer, name, SHOW_DETAIL))
  57. return NULL;
  58. return node_buffer;
  59. }
  60. struct node_info* node_from_list(struct node_info_msg *list, int i){
  61. return &list->node_array[i];
  62. }
  63. void free_node_buffer(void* buffer){
  64. slurm_free_node_info_msg ((struct node_info_msg*)buffer);
  65. }
  66. */
  67. import "C"
  68. import (
  69. pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
  70. "context"
  71. "strings"
  72. )
  73. type NodeInfoMsg struct {
  74. LastUpdate int64
  75. RecordCount uint32
  76. ErrorCode uint32
  77. NodeInfoList []pbslurm.NodeInfo
  78. }
  79. func Node_info_convert_c_to_go(c_struct *C.struct_node_info) pbslurm.NodeInfo {
  80. var go_struct pbslurm.NodeInfo
  81. go_struct.Arch = C.GoString(c_struct.arch)
  82. go_struct.Boards = uint32(c_struct.boards)
  83. go_struct.BootTime = int64(c_struct.boot_time)
  84. go_struct.Cores = uint32(c_struct.cores)
  85. go_struct.CpuLoad = uint32(c_struct.cpu_load)
  86. go_struct.Cpus = uint32(c_struct.cpus)
  87. go_struct.Features = C.GoString(c_struct.features)
  88. go_struct.Gres = C.GoString(c_struct.gres)
  89. go_struct.Name = C.GoString(c_struct.name)
  90. go_struct.NodeAddr = C.GoString(c_struct.node_addr)
  91. go_struct.NodeHostname = C.GoString(c_struct.node_hostname)
  92. go_struct.NodeState = uint32(c_struct.node_state)
  93. go_struct.Os = C.GoString(c_struct.os)
  94. go_struct.RealMemory = uint64(c_struct.real_memory)
  95. go_struct.Reason = C.GoString(c_struct.reason)
  96. go_struct.ReasonTime = int64(c_struct.reason_time)
  97. go_struct.ReasonUid = uint32(c_struct.reason_uid)
  98. go_struct.SlurmdStartTime = int64(c_struct.slurmd_start_time)
  99. go_struct.Sockets = uint32(c_struct.sockets)
  100. go_struct.Threads = uint32(c_struct.threads)
  101. go_struct.TmpDisk = uint32(c_struct.tmp_disk)
  102. go_struct.Weight = uint32(c_struct.weight)
  103. return go_struct
  104. }
  105. func (slurmStruct SlurmStruct) ListNodes(ctx context.Context, req *pbslurm.ListNodesReq) (*pbslurm.ListNodesResp, error) {
  106. nodeList := Get_all_nodes()
  107. var resp = pbslurm.ListNodesResp{}
  108. for _, node := range nodeList.NodeInfoList {
  109. nodeInfoResult := pbslurm.NodeInfo{}
  110. nodeInfoResult.Cpus = uint32(node.Cpus)
  111. nodeInfoResult.Boards = uint32(node.Boards)
  112. nodeInfoResult.RealMemory = node.RealMemory
  113. nodeInfoResult.Sockets = uint32(node.Sockets)
  114. nodeInfoResult.Threads = uint32(node.Threads)
  115. resp.NodeInfos = append(resp.NodeInfos, &nodeInfoResult)
  116. }
  117. return &resp, nil
  118. }
  119. func Get_all_nodes() NodeInfoMsg {
  120. var go_node_buffer NodeInfoMsg
  121. c_node_buffer := C.get_node_info()
  122. if c_node_buffer == nil {
  123. go_node_buffer.LastUpdate = int64(0)
  124. go_node_buffer.RecordCount = uint32(0)
  125. go_node_buffer.ErrorCode = uint32(C.slurm_get_errno())
  126. return go_node_buffer
  127. }
  128. go_node_buffer.LastUpdate = int64(c_node_buffer.last_update)
  129. go_node_buffer.RecordCount = uint32(c_node_buffer.record_count)
  130. go_node_buffer.NodeInfoList = make([]pbslurm.NodeInfo, c_node_buffer.record_count, c_node_buffer.record_count)
  131. for i := uint32(0); i < go_node_buffer.RecordCount; i++ {
  132. node := C.node_from_list(c_node_buffer, C.int(i))
  133. go_node := Node_info_convert_c_to_go(node)
  134. go_node_buffer.NodeInfoList[i] = go_node
  135. }
  136. C.slurm_free_node_info_msg(c_node_buffer)
  137. return go_node_buffer
  138. }
  139. func NodeDescriptorConvertCToGo(cStruct *C.struct_node_info) pbslurm.NodeInfo {
  140. var goStruct pbslurm.NodeInfo
  141. goStruct.Name = C.GoString(cStruct.name)
  142. return goStruct
  143. }
  144. func GetNodeInfo() NodeInfoMsg {
  145. var goNodeBuffer NodeInfoMsg
  146. cNodeBuffer := C.get_node_info()
  147. goNodeBuffer.RecordCount = uint32(cNodeBuffer.record_count)
  148. goNodeBuffer.NodeInfoList = make([]pbslurm.NodeInfo, cNodeBuffer.record_count, cNodeBuffer.record_count)
  149. for i := uint32(0); i < goNodeBuffer.RecordCount; i++ {
  150. Node := C.node_from_list(cNodeBuffer, C.int(i))
  151. goNode := NodeDescriptorConvertCToGo(Node)
  152. goNodeBuffer.NodeInfoList[i] = goNode
  153. }
  154. return goNodeBuffer
  155. }
  156. func (slurmStruct SlurmStruct) GetNode(ctx context.Context, req *pbslurm.GetNodeReq) (*pbslurm.GetNodeResp, error) {
  157. NodeList := GetNodeInfo()
  158. resp := pbslurm.GetNodeResp{}
  159. for _, node := range NodeList.NodeInfoList {
  160. nodeInfoResult := node
  161. if strings.Contains(node.Name, req.NodeName) {
  162. resp.NodeInfos = append(resp.NodeInfos, &nodeInfoResult)
  163. }
  164. }
  165. return &resp, nil
  166. }
  167. /*func (slurmStruct SlurmStruct) GetNodeByName(ctx context.Context, req *pbnode.NodeInfoMsgReq) (*pbnode.NodeInfoMsgResp, error) {
  168. node := Get_node_info(req.NodeName)
  169. var resp = pbnode.NodeInfoMsgResp{}
  170. for _, node := range node.Node_list {
  171. nodeInfoResult := pbnode.Node_Info{}
  172. nodeInfoResult.Cpus = uint32(node.Cpus)
  173. nodeInfoResult.Boards = uint32(node.Boards)
  174. nodeInfoResult.RealMemory = node.RealMemory
  175. nodeInfoResult.Sockets = uint32(node.Sockets)
  176. nodeInfoResult.Threads = uint32(node.Threads)
  177. resp.NodeList = append(resp.NodeList, &nodeInfoResult)
  178. }
  179. return &resp, nil
  180. }*/

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.