Skip to content

Commit

Permalink
feat: add CreateModel func to manager grpc client (#2207)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Mar 22, 2023
1 parent 7637acb commit cd94e99
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module d7y.io/dragonfly/v2
go 1.20

require (
d7y.io/api v1.8.2
d7y.io/api v1.8.3
github.com/RichardKnop/machinery v1.10.6
github.com/Showmax/go-fqdn v1.0.0
github.com/VividCortex/mysqlerr v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
d7y.io/api v1.8.2 h1:Sw+PhYMjq70t+wyG2AjhOnU/jJtctLzMs3xPySkAiPw=
d7y.io/api v1.8.2/go.mod h1:xMezpFrEljSfy/LINGkqg07BC2hzXqfTg7pzq5PIIZ8=
d7y.io/api v1.8.3 h1:D1WyaqjWv+Vvu04SvfXIXNbfi+W/Yx0dE4mC3o8XAWk=
d7y.io/api v1.8.3/go.mod h1:xMezpFrEljSfy/LINGkqg07BC2hzXqfTg7pzq5PIIZ8=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
Expand Down
7 changes: 7 additions & 0 deletions manager/rpcserver/manager_server_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/go-redis/redis/v8"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"gorm.io/gorm"

commonv1 "d7y.io/api/pkg/apis/common/v1"
Expand Down Expand Up @@ -681,6 +682,12 @@ func (s *managerServerV1) ListApplications(ctx context.Context, req *managerv1.L
return &pbListApplicationsResponse, nil
}

// TODO(MinH-09) Implement function.
// CreateModel creates model and update data of model to object storage.
func (s *managerServerV1) CreateModel(ctx context.Context, req *managerv1.CreateModelRequest) (*emptypb.Empty, error) {
return new(emptypb.Empty), nil
}

// KeepAlive with manager.
func (s *managerServerV1) KeepAlive(stream managerv1.Manager_KeepAliveServer) error {
req, err := stream.Recv()
Expand Down
7 changes: 7 additions & 0 deletions manager/rpcserver/manager_server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/go-redis/redis/v8"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"gorm.io/gorm"

commonv2 "d7y.io/api/pkg/apis/common/v2"
Expand Down Expand Up @@ -680,6 +681,12 @@ func (s *managerServerV2) ListApplications(ctx context.Context, req *managerv2.L
return &pbListApplicationsResponse, nil
}

// TODO(MinH-09) Implement function.
// CreateModel creates model and update data of model to object storage.
func (s *managerServerV2) CreateModel(ctx context.Context, req *managerv2.CreateModelRequest) (*emptypb.Empty, error) {
return new(emptypb.Empty), nil
}

// KeepAlive with manager.
func (s *managerServerV2) KeepAlive(stream managerv2.Manager_KeepAliveServer) error {
req, err := stream.Recv()
Expand Down
12 changes: 12 additions & 0 deletions pkg/rpc/manager/client/client_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ type V1 interface {
// List applications configuration.
ListApplications(context.Context, *managerv1.ListApplicationsRequest, ...grpc.CallOption) (*managerv1.ListApplicationsResponse, error)

// Create model and update data of model to object storage.
CreateModel(context.Context, *managerv1.CreateModelRequest, ...grpc.CallOption) error

// KeepAlive with manager.
KeepAlive(time.Duration, *managerv1.KeepAliveRequest, <-chan struct{}, ...grpc.CallOption)

Expand Down Expand Up @@ -180,6 +183,15 @@ func (v *v1) ListApplications(ctx context.Context, req *managerv1.ListApplicatio
return v.ManagerClient.ListApplications(ctx, req, opts...)
}

// Create model and update data of model to object storage.
func (v *v1) CreateModel(ctx context.Context, req *managerv1.CreateModelRequest, opts ...grpc.CallOption) error {
ctx, cancel := context.WithTimeout(ctx, createModelContextTimeout)
defer cancel()

_, err := v.ManagerClient.CreateModel(ctx, req, opts...)
return err
}

// List acitve schedulers configuration.
func (v *v1) KeepAlive(interval time.Duration, keepalive *managerv1.KeepAliveRequest, done <-chan struct{}, opts ...grpc.CallOption) {
log := logger.WithKeepAlive(keepalive.Hostname, keepalive.Ip, keepalive.SourceType.Enum().String(), keepalive.ClusterId)
Expand Down
12 changes: 12 additions & 0 deletions pkg/rpc/manager/client/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ type V2 interface {
// List applications configuration.
ListApplications(context.Context, *managerv2.ListApplicationsRequest, ...grpc.CallOption) (*managerv2.ListApplicationsResponse, error)

// Create model and update data of model to object storage.
CreateModel(context.Context, *managerv2.CreateModelRequest, ...grpc.CallOption) error

// KeepAlive with manager.
KeepAlive(time.Duration, *managerv2.KeepAliveRequest, <-chan struct{}, ...grpc.CallOption)

Expand Down Expand Up @@ -180,6 +183,15 @@ func (v *v2) ListApplications(ctx context.Context, req *managerv2.ListApplicatio
return v.ManagerClient.ListApplications(ctx, req, opts...)
}

// Create model and update data of model to object storage.
func (v *v2) CreateModel(ctx context.Context, req *managerv2.CreateModelRequest, opts ...grpc.CallOption) error {
ctx, cancel := context.WithTimeout(ctx, createModelContextTimeout)
defer cancel()

_, err := v.ManagerClient.CreateModel(ctx, req, opts...)
return err
}

// List acitve schedulers configuration.
func (v *v2) KeepAlive(interval time.Duration, keepalive *managerv2.KeepAliveRequest, done <-chan struct{}, opts ...grpc.CallOption) {
log := logger.WithKeepAlive(keepalive.Hostname, keepalive.Ip, keepalive.SourceType.Enum().String(), keepalive.ClusterId)
Expand Down
3 changes: 3 additions & 0 deletions pkg/rpc/manager/client/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (
// contextTimeout is timeout of grpc invoke.
contextTimeout = 2 * time.Minute

// createModelContextTimeout is timeout of CreateModel grpc invoke.
createModelContextTimeout = 30 * time.Minute

// maxRetries is maximum number of retries.
maxRetries = 3

Expand Down
19 changes: 19 additions & 0 deletions pkg/rpc/manager/client/mocks/client_v1_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/rpc/manager/client/mocks/client_v2_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cd94e99

Please sign in to comment.