grpc sample for slurm

This commit is contained in:
zhouqunjie 2022-10-24 17:54:35 -07:00
parent 9b0204ccd4
commit b67aab76d8
11 changed files with 257 additions and 91 deletions

View File

@ -20,14 +20,14 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type GetNodesReq struct {
type ListNodesReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *GetNodesReq) Reset() {
*x = GetNodesReq{}
func (x *ListNodesReq) Reset() {
*x = ListNodesReq{}
if protoimpl.UnsafeEnabled {
mi := &file_idl_slurm_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -35,13 +35,13 @@ func (x *GetNodesReq) Reset() {
}
}
func (x *GetNodesReq) String() string {
func (x *ListNodesReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetNodesReq) ProtoMessage() {}
func (*ListNodesReq) ProtoMessage() {}
func (x *GetNodesReq) ProtoReflect() protoreflect.Message {
func (x *ListNodesReq) ProtoReflect() protoreflect.Message {
mi := &file_idl_slurm_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -53,12 +53,12 @@ func (x *GetNodesReq) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use GetNodesReq.ProtoReflect.Descriptor instead.
func (*GetNodesReq) Descriptor() ([]byte, []int) {
// Deprecated: Use ListNodesReq.ProtoReflect.Descriptor instead.
func (*ListNodesReq) Descriptor() ([]byte, []int) {
return file_idl_slurm_proto_rawDescGZIP(), []int{0}
}
type GetNodesResp struct {
type NodeInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -71,8 +71,8 @@ type GetNodesResp struct {
Threads int32 `protobuf:"varint,6,opt,name=threads,proto3" json:"threads,omitempty"`
}
func (x *GetNodesResp) Reset() {
*x = GetNodesResp{}
func (x *NodeInfo) Reset() {
*x = NodeInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_idl_slurm_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -80,13 +80,13 @@ func (x *GetNodesResp) Reset() {
}
}
func (x *GetNodesResp) String() string {
func (x *NodeInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetNodesResp) ProtoMessage() {}
func (*NodeInfo) ProtoMessage() {}
func (x *GetNodesResp) ProtoReflect() protoreflect.Message {
func (x *NodeInfo) ProtoReflect() protoreflect.Message {
mi := &file_idl_slurm_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -98,75 +98,126 @@ func (x *GetNodesResp) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use GetNodesResp.ProtoReflect.Descriptor instead.
func (*GetNodesResp) Descriptor() ([]byte, []int) {
// Deprecated: Use NodeInfo.ProtoReflect.Descriptor instead.
func (*NodeInfo) Descriptor() ([]byte, []int) {
return file_idl_slurm_proto_rawDescGZIP(), []int{1}
}
func (x *GetNodesResp) GetBoards() int32 {
func (x *NodeInfo) GetBoards() int32 {
if x != nil {
return x.Boards
}
return 0
}
func (x *GetNodesResp) GetCpus() int32 {
func (x *NodeInfo) GetCpus() int32 {
if x != nil {
return x.Cpus
}
return 0
}
func (x *GetNodesResp) GetName() string {
func (x *NodeInfo) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *GetNodesResp) GetRealMemory() int32 {
func (x *NodeInfo) GetRealMemory() int32 {
if x != nil {
return x.RealMemory
}
return 0
}
func (x *GetNodesResp) GetSockets() int32 {
func (x *NodeInfo) GetSockets() int32 {
if x != nil {
return x.Sockets
}
return 0
}
func (x *GetNodesResp) GetThreads() int32 {
func (x *NodeInfo) GetThreads() int32 {
if x != nil {
return x.Threads
}
return 0
}
type ListNodesResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
NodeInfos []*NodeInfo `protobuf:"bytes,1,rep,name=node_infos,json=nodeInfos,proto3" json:"node_infos,omitempty"`
}
func (x *ListNodesResp) Reset() {
*x = ListNodesResp{}
if protoimpl.UnsafeEnabled {
mi := &file_idl_slurm_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListNodesResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListNodesResp) ProtoMessage() {}
func (x *ListNodesResp) ProtoReflect() protoreflect.Message {
mi := &file_idl_slurm_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListNodesResp.ProtoReflect.Descriptor instead.
func (*ListNodesResp) Descriptor() ([]byte, []int) {
return file_idl_slurm_proto_rawDescGZIP(), []int{2}
}
func (x *ListNodesResp) GetNodeInfos() []*NodeInfo {
if x != nil {
return x.NodeInfos
}
return nil
}
var File_idl_slurm_proto protoreflect.FileDescriptor
var file_idl_slurm_proto_rawDesc = []byte{
0x0a, 0x0f, 0x69, 0x64, 0x6c, 0x2f, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x05, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x22, 0x0d, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x4e,
0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x22, 0xa2, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x4e,
0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x61, 0x72,
0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73,
0x12, 0x12, 0x0a, 0x04, 0x63, 0x70, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04,
0x63, 0x70, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x61, 0x6c,
0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x72, 0x65,
0x61, 0x6c, 0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x6f, 0x63, 0x6b,
0x65, 0x74, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x6f, 0x63, 0x6b, 0x65,
0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x73, 0x18, 0x06, 0x20,
0x01, 0x28, 0x05, 0x52, 0x07, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x73, 0x32, 0x43, 0x0a, 0x0c,
0x53, 0x6c, 0x75, 0x72, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x33, 0x0a, 0x08,
0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x12, 0x2e, 0x73, 0x6c, 0x75, 0x72, 0x6d,
0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x13, 0x2e, 0x73,
0x6c, 0x75, 0x72, 0x6d, 0x2e, 0x47, 0x65, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x73,
0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2f, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x70, 0x62, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
0x6f, 0x12, 0x05, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x22, 0x0e, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74,
0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x22, 0x9e, 0x01, 0x0a, 0x08, 0x4e, 0x6f, 0x64,
0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x73, 0x12, 0x12, 0x0a,
0x04, 0x63, 0x70, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x70, 0x75,
0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x61, 0x6c, 0x4d, 0x65, 0x6d,
0x6f, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x6c, 0x4d,
0x65, 0x6d, 0x6f, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x73,
0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x73, 0x12,
0x18, 0x0a, 0x07, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05,
0x52, 0x07, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x73, 0x22, 0x3f, 0x0a, 0x0d, 0x4c, 0x69, 0x73,
0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2e, 0x0a, 0x0a, 0x6e, 0x6f,
0x64, 0x65, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f,
0x2e, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52,
0x09, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x73, 0x32, 0x46, 0x0a, 0x0c, 0x53, 0x6c,
0x75, 0x72, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x36, 0x0a, 0x09, 0x4c, 0x69,
0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x13, 0x2e, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x2e,
0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x73,
0x6c, 0x75, 0x72, 0x6d, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65,
0x73, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2f, 0x73, 0x6c, 0x75, 0x72, 0x6d, 0x70, 0x62, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -181,19 +232,21 @@ func file_idl_slurm_proto_rawDescGZIP() []byte {
return file_idl_slurm_proto_rawDescData
}
var file_idl_slurm_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_idl_slurm_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_idl_slurm_proto_goTypes = []interface{}{
(*GetNodesReq)(nil), // 0: slurm.GetNodesReq
(*GetNodesResp)(nil), // 1: slurm.GetNodesResp
(*ListNodesReq)(nil), // 0: slurm.ListNodesReq
(*NodeInfo)(nil), // 1: slurm.NodeInfo
(*ListNodesResp)(nil), // 2: slurm.ListNodesResp
}
var file_idl_slurm_proto_depIdxs = []int32{
0, // 0: slurm.SlurmService.GetNodes:input_type -> slurm.GetNodesReq
1, // 1: slurm.SlurmService.GetNodes:output_type -> slurm.GetNodesResp
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
1, // 0: slurm.ListNodesResp.node_infos:type_name -> slurm.NodeInfo
0, // 1: slurm.SlurmService.ListNodes:input_type -> slurm.ListNodesReq
2, // 2: slurm.SlurmService.ListNodes:output_type -> slurm.ListNodesResp
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_idl_slurm_proto_init() }
@ -203,7 +256,7 @@ func file_idl_slurm_proto_init() {
}
if !protoimpl.UnsafeEnabled {
file_idl_slurm_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetNodesReq); i {
switch v := v.(*ListNodesReq); i {
case 0:
return &v.state
case 1:
@ -215,7 +268,19 @@ func file_idl_slurm_proto_init() {
}
}
file_idl_slurm_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetNodesResp); i {
switch v := v.(*NodeInfo); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_idl_slurm_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListNodesResp); i {
case 0:
return &v.state
case 1:
@ -233,7 +298,7 @@ func file_idl_slurm_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_idl_slurm_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -31,20 +31,20 @@ var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = metadata.Join
func request_SlurmService_GetNodes_0(ctx context.Context, marshaler runtime.Marshaler, client SlurmServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetNodesReq
func request_SlurmService_ListNodes_0(ctx context.Context, marshaler runtime.Marshaler, client SlurmServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListNodesReq
var metadata runtime.ServerMetadata
msg, err := client.GetNodes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
msg, err := client.ListNodes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_SlurmService_GetNodes_0(ctx context.Context, marshaler runtime.Marshaler, server SlurmServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetNodesReq
func local_request_SlurmService_ListNodes_0(ctx context.Context, marshaler runtime.Marshaler, server SlurmServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListNodesReq
var metadata runtime.ServerMetadata
msg, err := server.GetNodes(ctx, &protoReq)
msg, err := server.ListNodes(ctx, &protoReq)
return msg, metadata, err
}
@ -55,7 +55,7 @@ func local_request_SlurmService_GetNodes_0(ctx context.Context, marshaler runtim
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterSlurmServiceHandlerFromEndpoint instead.
func RegisterSlurmServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server SlurmServiceServer) error {
mux.Handle("GET", pattern_SlurmService_GetNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
mux.Handle("GET", pattern_SlurmService_ListNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
@ -63,12 +63,12 @@ func RegisterSlurmServiceHandlerServer(ctx context.Context, mux *runtime.ServeMu
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/slurm.SlurmService/GetNodes", runtime.WithHTTPPathPattern("/apis/slurm"))
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/slurm.SlurmService/ListNodes", runtime.WithHTTPPathPattern("/apis/slurm/listNodes"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_SlurmService_GetNodes_0(annotatedContext, inboundMarshaler, server, req, pathParams)
resp, md, err := local_request_SlurmService_ListNodes_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
@ -76,7 +76,7 @@ func RegisterSlurmServiceHandlerServer(ctx context.Context, mux *runtime.ServeMu
return
}
forward_SlurmService_GetNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
forward_SlurmService_ListNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
@ -121,25 +121,25 @@ func RegisterSlurmServiceHandler(ctx context.Context, mux *runtime.ServeMux, con
// "SlurmServiceClient" to call the correct interceptors.
func RegisterSlurmServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client SlurmServiceClient) error {
mux.Handle("GET", pattern_SlurmService_GetNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
mux.Handle("GET", pattern_SlurmService_ListNodes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/slurm.SlurmService/GetNodes", runtime.WithHTTPPathPattern("/apis/slurm"))
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/slurm.SlurmService/ListNodes", runtime.WithHTTPPathPattern("/apis/slurm/listNodes"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_SlurmService_GetNodes_0(annotatedContext, inboundMarshaler, client, req, pathParams)
resp, md, err := request_SlurmService_ListNodes_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_SlurmService_GetNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
forward_SlurmService_ListNodes_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
@ -147,9 +147,9 @@ func RegisterSlurmServiceHandlerClient(ctx context.Context, mux *runtime.ServeMu
}
var (
pattern_SlurmService_GetNodes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"apis", "slurm"}, ""))
pattern_SlurmService_ListNodes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"apis", "slurm", "listNodes"}, ""))
)
var (
forward_SlurmService_GetNodes_0 = runtime.ForwardResponseMessage
forward_SlurmService_ListNodes_0 = runtime.ForwardResponseMessage
)

View File

@ -23,7 +23,7 @@ const _ = grpc.SupportPackageIsVersion7
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SlurmServiceClient interface {
// Echo 样例接口
GetNodes(ctx context.Context, in *GetNodesReq, opts ...grpc.CallOption) (*GetNodesResp, error)
ListNodes(ctx context.Context, in *ListNodesReq, opts ...grpc.CallOption) (*ListNodesResp, error)
}
type slurmServiceClient struct {
@ -34,9 +34,9 @@ func NewSlurmServiceClient(cc grpc.ClientConnInterface) SlurmServiceClient {
return &slurmServiceClient{cc}
}
func (c *slurmServiceClient) GetNodes(ctx context.Context, in *GetNodesReq, opts ...grpc.CallOption) (*GetNodesResp, error) {
out := new(GetNodesResp)
err := c.cc.Invoke(ctx, "/slurm.SlurmService/GetNodes", in, out, opts...)
func (c *slurmServiceClient) ListNodes(ctx context.Context, in *ListNodesReq, opts ...grpc.CallOption) (*ListNodesResp, error) {
out := new(ListNodesResp)
err := c.cc.Invoke(ctx, "/slurm.SlurmService/ListNodes", in, out, opts...)
if err != nil {
return nil, err
}
@ -48,7 +48,7 @@ func (c *slurmServiceClient) GetNodes(ctx context.Context, in *GetNodesReq, opts
// for forward compatibility
type SlurmServiceServer interface {
// Echo 样例接口
GetNodes(context.Context, *GetNodesReq) (*GetNodesResp, error)
ListNodes(context.Context, *ListNodesReq) (*ListNodesResp, error)
mustEmbedUnimplementedSlurmServiceServer()
}
@ -56,8 +56,8 @@ type SlurmServiceServer interface {
type UnimplementedSlurmServiceServer struct {
}
func (UnimplementedSlurmServiceServer) GetNodes(context.Context, *GetNodesReq) (*GetNodesResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetNodes not implemented")
func (UnimplementedSlurmServiceServer) ListNodes(context.Context, *ListNodesReq) (*ListNodesResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListNodes not implemented")
}
func (UnimplementedSlurmServiceServer) mustEmbedUnimplementedSlurmServiceServer() {}
@ -72,20 +72,20 @@ func RegisterSlurmServiceServer(s grpc.ServiceRegistrar, srv SlurmServiceServer)
s.RegisterService(&SlurmService_ServiceDesc, srv)
}
func _SlurmService_GetNodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetNodesReq)
func _SlurmService_ListNodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListNodesReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SlurmServiceServer).GetNodes(ctx, in)
return srv.(SlurmServiceServer).ListNodes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/slurm.SlurmService/GetNodes",
FullMethod: "/slurm.SlurmService/ListNodes",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SlurmServiceServer).GetNodes(ctx, req.(*GetNodesReq))
return srv.(SlurmServiceServer).ListNodes(ctx, req.(*ListNodesReq))
}
return interceptor(ctx, in, info, handler)
}
@ -98,8 +98,8 @@ var SlurmService_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*SlurmServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetNodes",
Handler: _SlurmService_GetNodes_Handler,
MethodName: "ListNodes",
Handler: _SlurmService_ListNodes_Handler,
},
},
Streams: []grpc.StreamDesc{},

View File

@ -44,7 +44,18 @@
}
}
},
"slurmGetNodesResp": {
"slurmListNodesResp": {
"type": "object",
"properties": {
"nodeInfos": {
"type": "array",
"items": {
"$ref": "#/definitions/slurmNodeInfo"
}
}
}
},
"slurmNodeInfo": {
"type": "object",
"properties": {
"boards": {

View File

@ -3,10 +3,9 @@ package slurm;
option go_package = "/slurmpb";
message GetNodesReq{}
message ListNodesReq{}
message GetNodesResp {
message NodeInfo{
int32 boards = 1 ;
int32 cpus = 2 ;
string name = 3 ;
@ -15,9 +14,13 @@ message GetNodesResp {
int32 threads = 6 ;
}
message ListNodesResp {
repeated NodeInfo node_infos =1;
}
// Slurm Services
service SlurmService {
// Echo
rpc GetNodes(GetNodesReq) returns (GetNodesResp);
rpc ListNodes(ListNodesReq) returns (ListNodesResp);
}

View File

@ -3,5 +3,5 @@ config_version: 3
http:
rules:
- selector: slurm.SlurmService.GetNodes
get: "/apis/slurm"
- selector: slurm.SlurmService.ListNodes
get: "/apis/slurm/listNodes"

30
adaptor/pcm_slurm/main.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
slurmserver "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/server"
"code.gitlink.org.cn/JCCE/PCM.git/common/config"
"code.gitlink.org.cn/JCCE/PCM.git/common/global"
"code.gitlink.org.cn/JCCE/PCM.git/common/server"
"go.uber.org/zap"
"google.golang.org/grpc"
)
func main() {
// 初始化配置以及数据库
config.InitConfig()
// 新建一个zap logger实例
logger, _ := zap.NewDevelopment()
// logger.Sugar().Fatal 直接可以少几行判错的代码
logger.Sugar().Fatal(server.RunGRPCServer(&server.GRPCConfig{
Name: "pcm_slurm",
Addr: global.S.SlurmInfo.Address,
RegisterFunc: func(g *grpc.Server) {
slurmpb.RegisterSlurmServiceServer(g, &slurmserver.Server{})
},
Logger: logger,
}))
}

View File

@ -0,0 +1,23 @@
package server
import (
slurmpb "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
"context"
"github.com/golang/glog"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type Server struct {
slurmpb.UnimplementedSlurmServiceServer
}
// ListNodes return all slurm nodes
func (s *Server) ListNodes(ctx context.Context, req *slurmpb.ListNodesReq) (*slurmpb.ListNodesResp, error) {
resp, err := ListNodes(ctx, req)
if err != nil {
glog.Errorf("ListSlurmNodes error %+v", err)
return nil, status.Errorf(codes.Internal, err.Error())
}
return resp, nil
}

View File

@ -0,0 +1,24 @@
package server
import (
nodeinfo "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/cgo/src/slurm/nodeinfo"
pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
"context"
)
func ListNodes(ctx context.Context, req *pbslurm.ListNodesReq) (*pbslurm.ListNodesResp, error) {
nodeList := nodeinfo.Get_all_nodes()
var resp = pbslurm.ListNodesResp{}
for _, node := range nodeList.Node_list {
nodeInfoResult := pbslurm.NodeInfo{}
nodeInfoResult.Cpus = int32(node.Cpus)
nodeInfoResult.Boards = int32(node.Boards)
nodeInfoResult.RealMemory = int32(node.Real_memory)
nodeInfoResult.Sockets = int32(node.Sockets)
nodeInfoResult.Threads = int32(node.Threads)
resp.NodeInfos = append(resp.NodeInfos, &nodeInfoResult)
}
return &resp, nil
}

View File

@ -0,0 +1,10 @@
package service
import (
pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
"context"
)
type Slurmer interface {
ListNodes(ctx context.Context, req *pbslurm.ListNodesReq) (resp *pbslurm.ListNodesResp, err error) //list slurm nodes
}

View File

@ -45,7 +45,7 @@ func main() {
registerFunc: podpb.RegisterPodServiceHandlerFromEndpoint,
},
{
name: "slurm",
name: "pcm_slurm",
addr: global.S.SlurmInfo.Address,
registerFunc: slurmpb.RegisterSlurmServiceHandlerFromEndpoint,
},