diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/app/slurm/slurmCore/api/etc/slurmcore-api.yaml b/app/slurm/slurmCore/api/etc/slurmcore-api.yaml index 58ee9aa..bbcc583 100644 --- a/app/slurm/slurmCore/api/etc/slurmcore-api.yaml +++ b/app/slurm/slurmCore/api/etc/slurmcore-api.yaml @@ -6,4 +6,10 @@ Port: 8899 ShuguangRpcConf: Endpoints: - 127.0.0.1:2001 + NonBlock: true + +#rpc +TianheRpcConf: + Endpoints: + - 127.0.0.1:2002 NonBlock: true \ No newline at end of file diff --git a/app/slurm/slurmCore/api/internal/config/config.go b/app/slurm/slurmCore/api/internal/config/config.go index d160d0f..b014955 100644 --- a/app/slurm/slurmCore/api/internal/config/config.go +++ b/app/slurm/slurmCore/api/internal/config/config.go @@ -9,4 +9,5 @@ type Config struct { rest.RestConf ShuguangRpcConf zrpc.RpcClientConf + TianheRpcConf zrpc.RpcClientConf } diff --git a/app/slurm/slurmCore/api/internal/logic/listhistoryjoblogic.go b/app/slurm/slurmCore/api/internal/logic/listhistoryjoblogic.go index 3299ba8..b114d4c 100644 --- a/app/slurm/slurmCore/api/internal/logic/listhistoryjoblogic.go +++ b/app/slurm/slurmCore/api/internal/logic/listhistoryjoblogic.go @@ -1,7 +1,7 @@ package logic import ( - "PCM/app/slurm/slurmShuguang/rpc/slurmShuguang" + "PCM/app/slurm/slurmTianhe/rpc/slurmTianhe" "PCM/common/tool" "PCM/common/xerr" "context" @@ -30,13 +30,13 @@ func NewListHistoryJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Li func (l *ListHistoryJobLogic) ListHistoryJob(req *types.ListHistoryJobReq) (resp *types.ListHistoryJobResp, err error) { - shuguangReq := &slurmShuguang.ListHistoryJobReq{} - err = copier.CopyWithOption(shuguangReq, req, copier.Option{Converters: tool.Converters}) - if err != nil { - return nil, err - } - //copier.Copy(shuguangReq, req) - listHistoryJobResp, err := l.svcCtx.ShuguangRpc.ListHistoryJob(l.ctx, shuguangReq) + //shuguangReq := &slurmShuguang.ListHistoryJobReq{} + //err = copier.CopyWithOption(shuguangReq, req, copier.Option{Converters: tool.Converters}) + //listHistoryJobResp, err := l.svcCtx.ShuguangRpc.ListHistoryJob(l.ctx, shuguangReq) + + tianheReq := &slurmTianhe.ListHistoryJobReq{} + err = copier.CopyWithOption(tianheReq, req, copier.Option{Converters: tool.Converters}) + listHistoryJobResp, err := l.svcCtx.TianheRpc.ListHistoryJob(l.ctx, tianheReq) if err != nil { return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get db job list"), "Failed to get db job list err : %v ,req:%+v", err, req) @@ -52,7 +52,7 @@ func (l *ListHistoryJobLogic) ListHistoryJob(req *types.ListHistoryJobReq) (resp return nil, err } for i := range resp.HistoryJobs { - resp.HistoryJobs[i].SlurmVersion = "shuguang" + resp.HistoryJobs[i].SlurmVersion = "tianhe" } return resp, nil diff --git a/app/slurm/slurmCore/api/internal/svc/serviceContext.go b/app/slurm/slurmCore/api/internal/svc/serviceContext.go index 48047c4..21f3743 100644 --- a/app/slurm/slurmCore/api/internal/svc/serviceContext.go +++ b/app/slurm/slurmCore/api/internal/svc/serviceContext.go @@ -3,6 +3,7 @@ package svc import ( "PCM/app/slurm/slurmCore/api/internal/config" "PCM/app/slurm/slurmShuguang/rpc/slurmshuguangclient" + "PCM/app/slurm/slurmTianhe/rpc/slurmtianheclient" "github.com/zeromicro/go-zero/zrpc" ) @@ -10,6 +11,7 @@ type ServiceContext struct { Config config.Config ShuguangRpc slurmshuguangclient.SlurmShuguang + TianheRpc slurmtianheclient.SlurmTianhe } func NewServiceContext(c config.Config) *ServiceContext { @@ -17,5 +19,6 @@ func NewServiceContext(c config.Config) *ServiceContext { Config: c, ShuguangRpc: slurmshuguangclient.NewSlurmShuguang(zrpc.MustNewClient(c.ShuguangRpcConf)), + TianheRpc: slurmtianheclient.NewSlurmTianhe(zrpc.MustNewClient(c.TianheRpcConf)), } } diff --git a/app/slurm/slurmCore/api/slurmcore.go b/app/slurm/slurmCore/api/slurmcore.go index bb77ffd..1ca2a94 100644 --- a/app/slurm/slurmCore/api/slurmcore.go +++ b/app/slurm/slurmCore/api/slurmcore.go @@ -13,7 +13,7 @@ import ( ) // C:\Users\Administrator\GolandProjects\PCM\app\slurm\slurmShuguang\rpc -var configFile = flag.String("f", "C:\\Users\\Administrator\\GolandProjects\\PCM\\app\\slurm\\slurmCore\\api\\etc\\slurmcore-api.yaml", "the config file") +var configFile = flag.String("f", "app/slurm/slurmCore/api/etc/slurmcore-api.yaml", "the config file") func main() { flag.Parse() diff --git a/app/slurm/slurmTianhe/rpc/etc/slurmtianhe.yaml b/app/slurm/slurmTianhe/rpc/etc/slurmtianhe.yaml new file mode 100644 index 0000000..96b2fa0 --- /dev/null +++ b/app/slurm/slurmTianhe/rpc/etc/slurmtianhe.yaml @@ -0,0 +1,3 @@ +Name: slurmtianhe.rpc +ListenOn: 0.0.0.0:2002 + diff --git a/app/slurm/slurmTianhe/rpc/internal/config/config.go b/app/slurm/slurmTianhe/rpc/internal/config/config.go new file mode 100755 index 0000000..c1f85b9 --- /dev/null +++ b/app/slurm/slurmTianhe/rpc/internal/config/config.go @@ -0,0 +1,7 @@ +package config + +import "github.com/zeromicro/go-zero/zrpc" + +type Config struct { + zrpc.RpcServerConf +} diff --git a/app/slurm/slurmTianhe/rpc/internal/logic/listhistoryjoblogic.go b/app/slurm/slurmTianhe/rpc/internal/logic/listhistoryjoblogic.go new file mode 100644 index 0000000..0877dbc --- /dev/null +++ b/app/slurm/slurmTianhe/rpc/internal/logic/listhistoryjoblogic.go @@ -0,0 +1,155 @@ +package logic + +/* +#cgo LDFLAGS: -lslurmdb + +#include +#include +#include +#include +#include +#include +#include +#include + +slurmdb_job_rec_t *get_all_slurmdb_job() { + + slurmdb_job_cond_t *job_cond = NULL; + void *conn = slurmdb_connection_get(); + + List joblist = slurmdb_jobs_get(conn, job_cond); + + uint16_t listsize = slurm_list_count(joblist); + //qosinfo.record_count = size; + slurmdb_job_rec_t *jobarray = malloc(listsize * sizeof(slurmdb_job_rec_t)); + + ListIterator itr = slurm_list_iterator_create(joblist); + + slurmdb_job_rec_t *rec = NULL; + int i = 0; + while ((rec = slurm_list_next(itr))) { + jobarray[i] = *rec; + i++; + } + slurmdb_connection_close(&conn); + slurm_list_destroy(joblist); + //int arraysize = sizeof(jobarray); + //printf("%d\n", arraysize); + return jobarray; +} + +slurmdb_job_rec_t *job_from_array(slurmdb_job_rec_t *job_rec_array, int i) { + return (slurmdb_job_rec_t *) &(job_rec_array[i]); +} + +slurmdb_job_rec_t *job_from_array_by_id(slurmdb_job_rec_t *job_rec_array, int job_id) { + int i; + int arraysize = sizeof(job_rec_array); + for (i=0; i slurmTianhe.historyJob + 1, // 1: slurmTianhe.slurmTianhe.ListHistoryJob:input_type -> slurmTianhe.ListHistoryJobReq + 2, // 2: slurmTianhe.slurmTianhe.ListHistoryJob:output_type -> slurmTianhe.ListHistoryJobResp + 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_slurmTianhe_proto_init() } +func file_slurmTianhe_proto_init() { + if File_slurmTianhe_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_slurmTianhe_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HistoryJob); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_slurmTianhe_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListHistoryJobReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_slurmTianhe_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListHistoryJobResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_slurmTianhe_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_slurmTianhe_proto_goTypes, + DependencyIndexes: file_slurmTianhe_proto_depIdxs, + MessageInfos: file_slurmTianhe_proto_msgTypes, + }.Build() + File_slurmTianhe_proto = out.File + file_slurmTianhe_proto_rawDesc = nil + file_slurmTianhe_proto_goTypes = nil + file_slurmTianhe_proto_depIdxs = nil +} diff --git a/app/slurm/slurmTianhe/rpc/slurmTianhe/slurmTianhe_grpc.pb.go b/app/slurm/slurmTianhe/rpc/slurmTianhe/slurmTianhe_grpc.pb.go new file mode 100644 index 0000000..2d7d2b8 --- /dev/null +++ b/app/slurm/slurmTianhe/rpc/slurmTianhe/slurmTianhe_grpc.pb.go @@ -0,0 +1,107 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.21.8 +// source: slurmTianhe.proto + +package slurmTianhe + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// SlurmTianheClient is the client API for SlurmTianhe service. +// +// 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 SlurmTianheClient interface { + // ListHistoryJob list all jobs from slurmdb + ListHistoryJob(ctx context.Context, in *ListHistoryJobReq, opts ...grpc.CallOption) (*ListHistoryJobResp, error) +} + +type slurmTianheClient struct { + cc grpc.ClientConnInterface +} + +func NewSlurmTianheClient(cc grpc.ClientConnInterface) SlurmTianheClient { + return &slurmTianheClient{cc} +} + +func (c *slurmTianheClient) ListHistoryJob(ctx context.Context, in *ListHistoryJobReq, opts ...grpc.CallOption) (*ListHistoryJobResp, error) { + out := new(ListHistoryJobResp) + err := c.cc.Invoke(ctx, "/slurmTianhe.slurmTianhe/ListHistoryJob", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SlurmTianheServer is the server API for SlurmTianhe service. +// All implementations must embed UnimplementedSlurmTianheServer +// for forward compatibility +type SlurmTianheServer interface { + // ListHistoryJob list all jobs from slurmdb + ListHistoryJob(context.Context, *ListHistoryJobReq) (*ListHistoryJobResp, error) + mustEmbedUnimplementedSlurmTianheServer() +} + +// UnimplementedSlurmTianheServer must be embedded to have forward compatible implementations. +type UnimplementedSlurmTianheServer struct { +} + +func (UnimplementedSlurmTianheServer) ListHistoryJob(context.Context, *ListHistoryJobReq) (*ListHistoryJobResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListHistoryJob not implemented") +} +func (UnimplementedSlurmTianheServer) mustEmbedUnimplementedSlurmTianheServer() {} + +// UnsafeSlurmTianheServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to SlurmTianheServer will +// result in compilation errors. +type UnsafeSlurmTianheServer interface { + mustEmbedUnimplementedSlurmTianheServer() +} + +func RegisterSlurmTianheServer(s grpc.ServiceRegistrar, srv SlurmTianheServer) { + s.RegisterService(&SlurmTianhe_ServiceDesc, srv) +} + +func _SlurmTianhe_ListHistoryJob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListHistoryJobReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SlurmTianheServer).ListHistoryJob(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/slurmTianhe.slurmTianhe/ListHistoryJob", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SlurmTianheServer).ListHistoryJob(ctx, req.(*ListHistoryJobReq)) + } + return interceptor(ctx, in, info, handler) +} + +// SlurmTianhe_ServiceDesc is the grpc.ServiceDesc for SlurmTianhe service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var SlurmTianhe_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "slurmTianhe.slurmTianhe", + HandlerType: (*SlurmTianheServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ListHistoryJob", + Handler: _SlurmTianhe_ListHistoryJob_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "slurmTianhe.proto", +} diff --git a/app/slurm/slurmTianhe/rpc/slurmtianhe.go b/app/slurm/slurmTianhe/rpc/slurmtianhe.go new file mode 100644 index 0000000..3fe67db --- /dev/null +++ b/app/slurm/slurmTianhe/rpc/slurmtianhe.go @@ -0,0 +1,39 @@ +package main + +import ( + "flag" + "fmt" + + "PCM/app/slurm/slurmTianhe/rpc/internal/config" + "PCM/app/slurm/slurmTianhe/rpc/internal/server" + "PCM/app/slurm/slurmTianhe/rpc/internal/svc" + "PCM/app/slurm/slurmTianhe/rpc/slurmTianhe" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/core/service" + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +var configFile = flag.String("f", "app/slurm/slurmTianhe/rpc/etc/slurmtianhe.yaml", "the config file") + +func main() { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c) + ctx := svc.NewServiceContext(c) + + s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { + slurmTianhe.RegisterSlurmTianheServer(grpcServer, server.NewSlurmTianheServer(ctx)) + + if c.Mode == service.DevMode || c.Mode == service.TestMode { + reflection.Register(grpcServer) + } + }) + defer s.Stop() + + fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) + s.Start() +} diff --git a/app/slurm/slurmTianhe/rpc/slurmtianheclient/slurmtianhe.go b/app/slurm/slurmTianhe/rpc/slurmtianheclient/slurmtianhe.go new file mode 100644 index 0000000..83531f1 --- /dev/null +++ b/app/slurm/slurmTianhe/rpc/slurmtianheclient/slurmtianhe.go @@ -0,0 +1,40 @@ +// Code generated by goctl. DO NOT EDIT. +// Source: slurmTianhe.proto + +package slurmtianheclient + +import ( + "context" + + "PCM/app/slurm/slurmTianhe/rpc/slurmTianhe" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + HistoryJob = slurmTianhe.HistoryJob + ListHistoryJobReq = slurmTianhe.ListHistoryJobReq + ListHistoryJobResp = slurmTianhe.ListHistoryJobResp + + SlurmTianhe interface { + // ListHistoryJob list all jobs from slurmdb + ListHistoryJob(ctx context.Context, in *ListHistoryJobReq, opts ...grpc.CallOption) (*ListHistoryJobResp, error) + } + + defaultSlurmTianhe struct { + cli zrpc.Client + } +) + +func NewSlurmTianhe(cli zrpc.Client) SlurmTianhe { + return &defaultSlurmTianhe{ + cli: cli, + } +} + +// ListHistoryJob list all jobs from slurmdb +func (m *defaultSlurmTianhe) ListHistoryJob(ctx context.Context, in *ListHistoryJobReq, opts ...grpc.CallOption) (*ListHistoryJobResp, error) { + client := slurmTianhe.NewSlurmTianheClient(m.cli.Conn()) + return client.ListHistoryJob(ctx, in, opts...) +} diff --git a/go.mod b/go.mod index c6bcb69..a3e399e 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module PCM go 1.19 require ( + github.com/bitly/go-simplejson v0.5.0 github.com/jinzhu/copier v0.3.5 github.com/pkg/errors v0.9.1 github.com/shopspring/decimal v1.3.1 @@ -14,7 +15,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect - github.com/bitly/go-simplejson v0.5.0 // indirect + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/coreos/go-semver v0.3.0 // indirect @@ -22,7 +23,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fatih/color v1.13.0 // indirect - github.com/favadi/protoc-go-inject-tag v1.4.0 // indirect github.com/felixge/fgprof v0.9.3 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/go.sum b/go.sum index 82f2790..adec432 100644 --- a/go.sum +++ b/go.sum @@ -399,6 +399,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -451,8 +453,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/favadi/protoc-go-inject-tag v1.4.0 h1:K3KXxbgRw5WT4f43LbglARGz/8jVsDOS7uMjG4oNvXY= -github.com/favadi/protoc-go-inject-tag v1.4.0/go.mod h1:AZ+PK+QDKUOLlBRG0rYiKkUX5Hw7+7GTFzlU99GFSbQ= github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=