| @@ -1,22 +0,0 @@ | |||
| syntax = "proto3"; | |||
| package slurm; | |||
| option go_package = "/slurmpb"; | |||
| import "idl/static.proto"; | |||
| message ListNodesReq{ | |||
| SlurmVersion slurm_version = 1; | |||
| } | |||
| message NodeInfo{ | |||
| int32 boards = 1 ; | |||
| int32 cpus = 2 ; | |||
| string name = 3 ; | |||
| int32 real_memory = 4 ; | |||
| int32 sockets = 5 ; | |||
| int32 threads = 6 ; | |||
| } | |||
| message ListNodesResp { | |||
| repeated NodeInfo node_infos =1; | |||
| } | |||
| @@ -2,7 +2,7 @@ syntax = "proto3"; | |||
| package slurm; | |||
| option go_package = "/slurmpb"; | |||
| import "idl/node.proto"; | |||
| import "idl/slurm_node.proto"; | |||
| import "idl/slurmdb_user.proto"; | |||
| import "idl/slurmdb_assoc.proto"; | |||
| import "idl/slurmdb_account.proto"; | |||
| @@ -0,0 +1,56 @@ | |||
| syntax = "proto3"; | |||
| package slurm; | |||
| option go_package = "/slurmpb"; | |||
| import "idl/static.proto"; | |||
| message NodeInfo{ | |||
| string Arch = 1 ; | |||
| uint32 Boards = 2 ; | |||
| int64 Boot_time = 3 ; | |||
| uint32 Cores = 4 ; | |||
| uint32 Cpu_load = 5 ; | |||
| uint32 Cpus = 6 ; | |||
| string Features = 7; | |||
| string Gres = 8 ; | |||
| string Name = 9 ; | |||
| string Node_addr = 10 ; | |||
| string Node_hostname = 11 ; | |||
| uint32 Node_state = 12 ; | |||
| string Os = 13 ; | |||
| uint64 Real_memory = 14 ; | |||
| string Reason = 15 ; | |||
| int64 Reason_time = 16 ; | |||
| uint32 Reason_uid = 17 ; | |||
| int64 Slurmd_start_time = 18 ; | |||
| uint32 Sockets = 19 ; | |||
| uint32 Threads = 20 ; | |||
| uint32 Tmp_disk = 21 ; | |||
| uint32 Weight = 22 ; | |||
| } | |||
| message ListNodesReq{ | |||
| SlurmVersion slurm_version = 1; | |||
| } | |||
| message ListNodesResp { | |||
| repeated NodeInfo node_infos = 1; | |||
| } | |||
| message GetNodeReq{ | |||
| SlurmVersion slurm_version = 1; | |||
| string node_name = 2; | |||
| } | |||
| message GetNodeResp { | |||
| repeated NodeInfo node_infos = 1; | |||
| } | |||
| /*message Nodes_info_msg{ | |||
| int64 Last_update =1; | |||
| uint32 Record_count =2; | |||
| uint32 Error_code =3; | |||
| repeated NodeInfo node_infos =4; | |||
| }*/ | |||
| @@ -0,0 +1,54 @@ | |||
| syntax = "proto3"; | |||
| package slurm; | |||
| option go_package = "/slurmpb"; | |||
| import "idl/static.proto"; | |||
| message PartitionInfo{ | |||
| string Allow_alloc_nodes =1; | |||
| string Allow_groups =2; | |||
| string Alternate =3; | |||
| uint32 Cr_type =4; | |||
| uint64 Def_mem_per_cpu =5; | |||
| uint32 Default_time = 6; | |||
| uint32 Flags =7; | |||
| uint32 Grace_time =8; | |||
| uint32 Max_cpus_per_node =9; | |||
| uint64 Max_mem_per_cpu =10; | |||
| uint32 Max_nodes =11; | |||
| uint32 Max_share =12; | |||
| uint32 Max_time =13; | |||
| uint32 Min_nodes =14; | |||
| string Name =15; | |||
| int32 Node_inx =16; | |||
| string Nodes =17; | |||
| uint32 Preempt_mode =18; | |||
| uint32 State_up =19; | |||
| uint32 Total_cpus =20; | |||
| uint32 Total_nodes =21; | |||
| } | |||
| message ListPartitionsReq{ | |||
| SlurmVersion SlurmVersion = 1; | |||
| } | |||
| message ListPartitionsResp{ | |||
| repeated PartitionInfo Partition_list =1; | |||
| } | |||
| message GetPartitionReq{ | |||
| SlurmVersion slurm_version = 1; | |||
| string partition_name = 2; | |||
| } | |||
| message GetPartitionResp { | |||
| repeated PartitionInfo partition_infos = 1; | |||
| } | |||
| /*message Partition_info_msg{ | |||
| int64 Last_update =1; | |||
| uint32 Record_count =2; | |||
| uint32 Error_code =3; | |||
| repeated PartitionInfo Partition_list =4; | |||
| }*/ | |||
| @@ -0,0 +1,14 @@ | |||
| syntax = "proto3"; | |||
| package slurm; | |||
| option go_package = "/slurmpb"; | |||
| import "idl/static.proto"; | |||
| message PingInfoMsgReq{ | |||
| SlurmVersion SlurmVersion = 1; | |||
| int32 controller = 2; | |||
| } | |||
| message PingInfoMsgResp{ | |||
| int32 Ping_result =1; | |||
| } | |||
| @@ -0,0 +1,46 @@ | |||
| syntax = "proto3"; | |||
| package slurm; | |||
| option go_package = "/slurmpb"; | |||
| import "idl/static.proto"; | |||
| message ReservationInfo{ | |||
| string Accounts = 1; | |||
| int64 End_time =2; | |||
| string Features =3; | |||
| uint32 Flags =4; | |||
| string Licenses =5; | |||
| string Name =6; | |||
| uint32 Node_cnt =7; | |||
| uint32 Core_cnt =8; | |||
| int32 Node_inx =9; | |||
| string Node_list =10; | |||
| string Partition =11; | |||
| int64 Start_time =12; | |||
| string Users =13; | |||
| } | |||
| message ListReservationsReq{ | |||
| SlurmVersion SlurmVersion = 1; | |||
| } | |||
| message ListReservationsResp{ | |||
| repeated ReservationInfo Reservation_list =1; | |||
| } | |||
| message GetReservationReq{ | |||
| SlurmVersion slurm_version = 1; | |||
| string reservation_name = 2; | |||
| } | |||
| message GetReservationResp { | |||
| repeated ReservationInfo reservation_infos = 1; | |||
| } | |||
| /*message Partition_info_msg{ | |||
| int64 Last_update =1; | |||
| uint32 Record_count =2; | |||
| uint32 Error_code =3; | |||
| repeated PartitionInfo Partition_list =4; | |||
| }*/ | |||
| @@ -0,0 +1,198 @@ | |||
| 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_slurmdb_account_rec) 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 | |||
| }*/ | |||
| @@ -0,0 +1,133 @@ | |||
| package slurmer | |||
| /* | |||
| #cgo LDFLAGS: -lslurm | |||
| #include<stdlib.h> | |||
| #include<slurm/slurm.h> | |||
| struct partition_info_msg *get_partition_info(){ | |||
| struct partition_info_msg* partition_buffer; | |||
| if( slurm_load_partitions ((time_t) NULL, | |||
| &partition_buffer, SHOW_ALL)) | |||
| return NULL; | |||
| return partition_buffer; | |||
| } | |||
| struct partition_info* partition_from_list(struct partition_info_msg *list, int i){ | |||
| return &list->partition_array[i]; | |||
| } | |||
| void free_partition_buffer(void* buffer){ | |||
| slurm_free_partition_info_msg ((struct partition_info_msg*)buffer); | |||
| } | |||
| */ | |||
| import "C" | |||
| import ( | |||
| pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl" | |||
| "context" | |||
| "strings" | |||
| ) | |||
| func Partition_info_convert_c_to_go(c_struct *C.struct_partition_info) pbslurm.PartitionInfo { | |||
| var go_struct pbslurm.PartitionInfo | |||
| go_struct.AllowAllocNodes = C.GoString(c_struct.allow_alloc_nodes) | |||
| go_struct.AllowGroups = C.GoString(c_struct.allow_groups) | |||
| go_struct.Alternate = C.GoString(c_struct.alternate) | |||
| go_struct.CrType = uint32(c_struct.cr_type) | |||
| go_struct.DefMemPerCpu = uint64(c_struct.def_mem_per_cpu) | |||
| go_struct.DefaultTime = uint32(c_struct.default_time) | |||
| go_struct.Flags = uint32(c_struct.flags) | |||
| go_struct.GraceTime = uint32(c_struct.grace_time) | |||
| go_struct.MaxCpusPerNode = uint32(c_struct.max_cpus_per_node) | |||
| go_struct.MaxMemPerCpu = uint64(c_struct.max_mem_per_cpu) | |||
| go_struct.MaxNodes = uint32(c_struct.max_nodes) | |||
| go_struct.MaxShare = uint32(c_struct.max_share) | |||
| go_struct.MaxTime = uint32(c_struct.max_time) | |||
| go_struct.MinNodes = uint32(c_struct.min_nodes) | |||
| go_struct.Name = C.GoString(c_struct.name) | |||
| //go_struct.Node_inx = int32(C.int32_ptr(c_struct.node_inx)) | |||
| /*t := C.find_node_inx(c_struct.node_inx) | |||
| fmt.Printf("%d", t) | |||
| go_struct.Node_inx = make([]int32, t, t) | |||
| for i := int32(0); i < int32(t); i++ { | |||
| go_struct.Node_inx[i] = int32(C.int32_ptr(c_struct.node_inx, C.int(i))) | |||
| }*/ | |||
| go_struct.Nodes = C.GoString(c_struct.nodes) | |||
| go_struct.PreemptMode = uint32(c_struct.preempt_mode) | |||
| go_struct.StateUp = uint32(c_struct.state_up) | |||
| go_struct.TotalCpus = uint32(c_struct.total_cpus) | |||
| go_struct.TotalNodes = uint32(c_struct.total_nodes) | |||
| return go_struct | |||
| } | |||
| type PartitionInfoMsg struct { | |||
| LastUpdate int64 | |||
| RecordCount uint32 | |||
| PartitionInfoList []pbslurm.PartitionInfo | |||
| } | |||
| func Get_partitions() PartitionInfoMsg { | |||
| var go_partition_buffer PartitionInfoMsg | |||
| c_partition_buffer := C.get_partition_info() | |||
| if c_partition_buffer == nil { | |||
| go_partition_buffer.LastUpdate = int64(0) | |||
| go_partition_buffer.RecordCount = uint32(0) | |||
| return go_partition_buffer | |||
| } | |||
| go_partition_buffer.LastUpdate = int64(c_partition_buffer.last_update) | |||
| go_partition_buffer.RecordCount = uint32(c_partition_buffer.record_count) | |||
| go_partition_buffer.PartitionInfoList = make([]pbslurm.PartitionInfo, c_partition_buffer.record_count, c_partition_buffer.record_count) | |||
| for i := uint32(0); i < go_partition_buffer.RecordCount; i++ { | |||
| partition := C.partition_from_list(c_partition_buffer, C.int(i)) | |||
| go_partition := Partition_info_convert_c_to_go(partition) | |||
| go_partition_buffer.PartitionInfoList[i] = go_partition | |||
| } | |||
| C.slurm_free_partition_info_msg(c_partition_buffer) | |||
| return go_partition_buffer | |||
| } | |||
| func (slurmStruct SlurmStruct) ListPartitions(ctx context.Context, req *pbslurm.ListPartitionsReq) (*pbslurm.ListPartitionsResp, error) { | |||
| partitionList := Get_partitions() | |||
| var resp = pbslurm.ListPartitionsResp{} | |||
| for _, partition := range partitionList.PartitionInfoList { | |||
| partitionInfoResult := partition | |||
| resp.PartitionList = append(resp.PartitionList, &partitionInfoResult) | |||
| } | |||
| return &resp, nil | |||
| } | |||
| func GetPartitionsInfo() PartitionInfoMsg { | |||
| var goPartitionBuffer PartitionInfoMsg | |||
| cPartitionBuffer := C.get_partition_info() | |||
| goPartitionBuffer.RecordCount = uint32(cPartitionBuffer.record_count) | |||
| goPartitionBuffer.PartitionInfoList = make([]pbslurm.PartitionInfo, cPartitionBuffer.record_count, cPartitionBuffer.record_count) | |||
| for i := uint32(0); i < goPartitionBuffer.RecordCount; i++ { | |||
| partition := C.partition_from_list(&cPartitionBuffer, C.int(i)) | |||
| goPartition := PartitionDescriptorConvertCToGo(partition) | |||
| goPartitionBuffer.PartitionInfoList[i] = goPartition | |||
| } | |||
| return goPartitionBuffer | |||
| } | |||
| func PartitionDescriptorConvertCToGo(cStruct *C.struct_slurmdb_partition_rec) pbslurm.PartitionInfo { | |||
| var goStruct pbslurm.PartitionInfo | |||
| goStruct.Name = C.GoString(cStruct.name) | |||
| return goStruct | |||
| } | |||
| func (slurmStruct SlurmStruct) GetPartition(ctx context.Context, req *pbslurm.GetPartitionReq) (*pbslurm.GetPartitionResp, error) { | |||
| PartitionList := GetPartitionsInfo() | |||
| resp := pbslurm.GetPartitionResp{} | |||
| for _, partition := range PartitionList.PartitionInfoList { | |||
| partitionInfoResult := partition | |||
| if strings.Contains(partition.Name, req.PartitionName) { | |||
| resp.PartitionInfos = append(resp.PartitionInfos, &partitionInfoResult) | |||
| } | |||
| } | |||
| return &resp, nil | |||
| } | |||
| @@ -0,0 +1,31 @@ | |||
| package slurmer | |||
| /* | |||
| #cgo LDFLAGS: -lslurm | |||
| #include<stdlib.h> | |||
| #include<slurm/slurm.h> | |||
| #include<slurm/slurm_errno.h> | |||
| // int ping_result; | |||
| // ping_result = slurm_ping(int ping) | |||
| int slurm_ping(int controller){ | |||
| int ping_result; | |||
| ping_result = slurm_ping(controller); | |||
| return ping_result; | |||
| } | |||
| */ | |||
| import "C" | |||
| import ( | |||
| pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl" | |||
| "context" | |||
| ) | |||
| func (slurmStruct SlurmStruct) GetPingResult(ctx context.Context, req *pbslurm.PingInfoMsgReq) (*pbslurm.PingInfoMsgResp, error) { | |||
| cgoIntA := C.int(req.Controller) | |||
| Ping_result := C.slurm_ping(cgoIntA) | |||
| //C.free(unsafe.Pointer(cgoIntA)) | |||
| var resp = pbslurm.PingInfoMsgResp{} | |||
| resp.PingResult = int32(Ping_result) | |||
| return &resp, nil | |||
| } | |||
| @@ -0,0 +1,161 @@ | |||
| package slurmer | |||
| /* | |||
| #cgo LDFLAGS: -lslurm | |||
| #include<stdlib.h> | |||
| #include<slurm/slurm.h> | |||
| #include<slurm/slurm_errno.h> | |||
| struct reserve_info_msg *get_reserve_info(){ | |||
| struct reserve_info_msg* reservation_buffer; | |||
| if(slurm_load_reservations ((time_t) NULL, | |||
| &reservation_buffer)) | |||
| return NULL; | |||
| return reservation_buffer; | |||
| } | |||
| struct reserve_info* reservation_from_list(struct reserve_info_msg *list, int i){ | |||
| return &list->reservation_array[i]; | |||
| } | |||
| void free_reservation_buffer(void* buffer){ | |||
| slurm_free_reservation_info_msg ((struct reserve_info_msg*)buffer); | |||
| } | |||
| */ | |||
| import "C" | |||
| import ( | |||
| pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl" | |||
| "context" | |||
| "strings" | |||
| ) | |||
| type ReservationInfoMsg struct { | |||
| LastUpdate int64 | |||
| RecordCount uint32 | |||
| ReservationList []pbslurm.ReservationInfo | |||
| ErrorCode uint32 | |||
| } | |||
| func Reservation_info_convert_c_to_go(c_struct *C.struct_reserve_info) pbslurm.ReservationInfo { | |||
| var go_struct pbslurm.ReservationInfo | |||
| go_struct.Accounts = C.GoString(c_struct.accounts) | |||
| go_struct.EndTime = int64(c_struct.end_time) | |||
| go_struct.Features = C.GoString(c_struct.features) | |||
| go_struct.Flags = uint32(c_struct.flags) | |||
| go_struct.Licenses = C.GoString(c_struct.licenses) | |||
| go_struct.Name = C.GoString(c_struct.name) | |||
| go_struct.Features = C.GoString(c_struct.features) | |||
| go_struct.NodeCnt = uint32(c_struct.node_cnt) | |||
| go_struct.CoreCnt = uint32(c_struct.core_cnt) | |||
| /*t := C.find_node_inx(c_struct.node_inx) | |||
| fmt.Printf("%d", t) | |||
| go_struct.Node_inx = make([]int32, t, t) | |||
| for i := int32(0); i < int32(t); i++ { | |||
| go_struct.Node_inx[i] = int32(C.int32_ptr(c_struct.node_inx, C.int(i))) | |||
| }*/ | |||
| go_struct.NodeList = C.GoString(c_struct.node_list) | |||
| go_struct.Partition = C.GoString(c_struct.partition) | |||
| go_struct.StartTime = int64(c_struct.start_time) | |||
| //go_struct.clusters = C.GoString(c_struct.clusters) | |||
| return go_struct | |||
| } | |||
| func Get_all_reservation() ReservationInfoMsg { | |||
| var go_reservation_buffer ReservationInfoMsg | |||
| c_reservation_buffer := C.get_reserve_info() | |||
| if c_reservation_buffer == nil { | |||
| go_reservation_buffer.LastUpdate = int64(0) | |||
| go_reservation_buffer.RecordCount = uint32(0) | |||
| go_reservation_buffer.ErrorCode = uint32(C.slurm_get_errno()) | |||
| return go_reservation_buffer | |||
| } | |||
| go_reservation_buffer.LastUpdate = int64(c_reservation_buffer.last_update) | |||
| go_reservation_buffer.RecordCount = uint32(c_reservation_buffer.record_count) | |||
| go_reservation_buffer.ReservationList = make([]pbslurm.ReservationInfo, c_reservation_buffer.record_count, c_reservation_buffer.record_count) | |||
| for i := uint32(0); i < go_reservation_buffer.RecordCount; i++ { | |||
| reservation := C.reservation_from_list(c_reservation_buffer, C.int(i)) | |||
| go_reservation := Reservation_info_convert_c_to_go(reservation) | |||
| go_reservation_buffer.ReservationList[i] = go_reservation | |||
| } | |||
| C.slurm_free_reservation_info_msg(c_reservation_buffer) | |||
| return go_reservation_buffer | |||
| } | |||
| func (slurmStruct SlurmStruct) ListReservations(ctx context.Context, req *pbslurm.ListReservationsReq) (*pbslurm.ListReservationsResp, error) { | |||
| reservationList := Get_all_reservation() | |||
| var resp = pbslurm.ListReservationsResp{} | |||
| for _, reservation := range reservationList.ReservationList { | |||
| reservationInfoResult := reservation | |||
| resp.ReservationList = append(resp.ReservationList, &reservationInfoResult) | |||
| } | |||
| return &resp, nil | |||
| } | |||
| func GetReservationsInfo() ReservationInfoMsg { | |||
| var goReservationBuffer ReservationInfoMsg | |||
| cReservationBuffer := C.get_reservation_info() | |||
| goReservationBuffer.RecordCount = uint32(cReservationBuffer.record_count) | |||
| goReservationBuffer.ReservationList = make([]pbslurm.ReservationInfo, cReservationBuffer.record_count, cReservationBuffer.record_count) | |||
| for i := uint32(0); i < goReservationBuffer.RecordCount; i++ { | |||
| Reservation := C.reservation_from_list(&cReservationBuffer, C.int(i)) | |||
| goReservation := ReservationDescriptorConvertCToGo(Reservation) | |||
| goReservationBuffer.ReservationList[i] = goReservation | |||
| } | |||
| return goReservationBuffer | |||
| } | |||
| func ReservationDescriptorConvertCToGo(cStruct *C.struct_slurmdb_reservation_rec) pbslurm.ReservationInfo { | |||
| var goStruct pbslurm.ReservationInfo | |||
| goStruct.Name = C.GoString(cStruct.name) | |||
| return goStruct | |||
| } | |||
| func (slurmStruct SlurmStruct) GetReservation(ctx context.Context, req *pbslurm.GetReservationReq) (*pbslurm.GetReservationResp, error) { | |||
| ReservationList := GetReservationsInfo() | |||
| resp := pbslurm.GetReservationResp{} | |||
| for _, reservation := range ReservationList.ReservationList { | |||
| reservationInfoResult := reservation | |||
| if strings.Contains(reservation.Name, req.ReservationName) { | |||
| resp.ReservationInfos = append(resp.ReservationInfos, &reservationInfoResult) | |||
| } | |||
| } | |||
| return &resp, nil | |||
| } | |||
| /*func (slurmStruct SlurmStruct) GetReservationByName(ctx context.Context, req *pbslurm.ReservationInfoMsgReq) (*pbslurm.ReservationInfoMsgResp, error) { | |||
| reservation := Get_reservation_info(req.ReservationName) | |||
| var resp = pbslurm.ReservationInfoMsgResp{} | |||
| for _, reservation := range reservation.Reservation_list { | |||
| reservationInfoResult := pbslurm.Reservation_Info{} | |||
| reservationInfoResult.Name = reservation.Name | |||
| /*nodeInfoResult.Boards = uint32(node.Boards) | |||
| nodeInfoResult.RealMemory = node.Real_memory | |||
| nodeInfoResult.Sockets = uint32(node.Sockets) | |||
| nodeInfoResult.Threads = uint32(node.Threads)* | |||
| resp.ReservationList = append(resp.ReservationList, &reservationInfoResult) | |||
| } | |||
| return &resp, nil | |||
| } | |||
| func Get_reservation_info(name string) ReserveInfoMsg { | |||
| go_reservation_buffer := Get_all_reservation() | |||
| //partitionList := list.New() | |||
| for i := range go_reservation_buffer.ReservationList { | |||
| //遍历nodeList集合 | |||
| reservation := go_reservation_buffer.ReservationList[i] | |||
| fmt.Println("reservationName: " + reservation.Name) | |||
| //当集合中的名字等于传过来的值 | |||
| if name == reservation.Name { | |||
| /*partitionList.PushFront(partition.Name) | |||
| partitionList.PushFront(partition.Nodes)* | |||
| } else { | |||
| } | |||
| //fmt.Println(partition.Node_inx) | |||
| } | |||
| return go_reservation_buffer | |||
| }*/ | |||
| @@ -80,7 +80,7 @@ func GetClusterInfo() ClusterInfoMsg { | |||
| return go_cluster_buffer | |||
| } | |||
| func (slurmStruct SlurmStruct) GetAllClusters(ctx context.Context, req *pbslurm.ListClustersReq) (*pbslurm.ListClustersResp, error) { | |||
| func (slurmStruct SlurmStruct) ListClusters(ctx context.Context, req *pbslurm.ListClustersReq) (*pbslurm.ListClustersResp, error) { | |||
| clusterList := GetClusterInfo() | |||
| @@ -19,6 +19,16 @@ type Slurmer interface { | |||
| ListQoss(ctx context.Context, req *pbslurm.ListQossReq) (resp *pbslurm.ListQossResp, err error) //list slurm qoss | |||
| ListWckeys(ctx context.Context, req *pbslurm.ListWckeysReq) (resp *pbslurm.ListWckeysResp, err error) //list slurm wckeys | |||
| GetWckey(ctx context.Context, req *pbslurm.GetWckeyReq) (resp *pbslurm.GetWckeyResp, err error) //list slurm wckeys | |||
| ListClusters(ctx context.Context, req *pbslurm.ListClustersReq) (resp *pbslurm.ListClustersResp, err error) | |||
| GetCluster(ctx context.Context, req *pbslurm.GetClusterReq) (resp *pbslurm.GetClusterResp, err error) | |||
| DeleteCluster(ctx context.Context, req *pbslurm.DeleteClusterReq) (resp *pbslurm.DeleteClusterResp, err error) | |||
| AddCluster(ctx context.Context, req *pbslurm.AddClusterReq) (resp *pbslurm.AddClusterResp, err error) | |||
| ListNodes(ctx context.Context, req *pbslurm.ListNodesReq) (resp *pbslurm.ListNodesResp, err error) | |||
| GetNode(ctx context.Context, req *pbslurm.GetNodeResp) (resp *pbslurm.GetNodeResp, err error) | |||
| ListPartitions(ctx context.Context, req *pbslurm.ListPartitionsReq) (resp *pbslurm.ListPartitionsResp, err error) | |||
| GetPartition(ctx context.Context, req *pbslurm.GetPartitionReq) (resp *pbslurm.GetPartitionResp, err error) | |||
| ListReservations(ctx context.Context, req *pbslurm.ListReservationsReq) (resp *pbslurm.ListReservationsResp, err error) | |||
| GetReservation(ctx context.Context, req *pbslurm.GetReservationReq) (resp *pbslurm.GetReservationResp, err error) | |||
| } | |||
| func SelectSlurmVersion(slurmVersion pbslurm.SlurmVersion) (slurmer Slurmer, err error) { | |||