Skip to content

Commit

Permalink
feat: add features to scheduler cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Mar 30, 2023
1 parent b9a6c7d commit bf32ad7
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 22 deletions.
6 changes: 3 additions & 3 deletions 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.3
d7y.io/api v1.8.4
github.com/RichardKnop/machinery v1.10.6
github.com/Showmax/go-fqdn v1.0.0
github.com/VividCortex/mysqlerr v1.0.0
Expand Down Expand Up @@ -108,7 +108,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.10.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-echarts/go-echarts/v2 v2.2.4 // indirect
Expand Down Expand Up @@ -204,7 +204,7 @@ require (
golang.org/x/net v0.8.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
14 changes: 7 additions & 7 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.3 h1:D1WyaqjWv+Vvu04SvfXIXNbfi+W/Yx0dE4mC3o8XAWk=
d7y.io/api v1.8.3/go.mod h1:xMezpFrEljSfy/LINGkqg07BC2hzXqfTg7pzq5PIIZ8=
d7y.io/api v1.8.4 h1:2qlV2y4viuhb9FwjHFkBY+o2jUVmYE64McSoI+AAYUc=
d7y.io/api v1.8.4/go.mod h1:a68kyDomG6hyShQUFD0CorxmU3RB4/NHfUzww8S/VYg=
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 Expand Up @@ -230,8 +230,8 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.9.1 h1:PS7VIOgmSVhWUEeZwTe7z7zouA22Cr590PzXKbZHOVY=
github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0++PMirau2/yoOwVac3AbF2w=
github.com/envoyproxy/protoc-gen-validate v0.10.1 h1:c0g45+xCJhdgFGw7a5QAfdS4byAbud7miNWJ1WwEVf8=
github.com/envoyproxy/protoc-gen-validate v0.10.1/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
Expand Down Expand Up @@ -1253,7 +1253,7 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1539,8 +1539,8 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
1 change: 1 addition & 0 deletions manager/models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Scheduler struct {
IP string `gorm:"column:ip;type:varchar(256);not null;comment:ip address" json:"ip"`
Port int32 `gorm:"column:port;not null;comment:grpc service listening port" json:"port"`
State string `gorm:"column:state;type:varchar(256);default:'inactive';comment:service state" json:"state"`
Features JSONMap `gorm:"column:features;comment:feature flags" json:"features"`
SchedulerClusterID uint `gorm:"index:uk_scheduler,unique;not null;comment:scheduler cluster id"`
SchedulerCluster SchedulerCluster `json:"-"`
Models []Model `json:"-"`
Expand Down
6 changes: 6 additions & 0 deletions manager/rpcserver/manager_server_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ func (s *managerServerV1) GetScheduler(ctx context.Context, req *managerv1.GetSc
}
}

var features map[string]bool
for k, v := range scheduler.Features {
features[k] = v.(bool)
}

// Construct scheduler.
pbScheduler = managerv1.Scheduler{
Id: uint64(scheduler.ID),
Expand All @@ -337,6 +342,7 @@ func (s *managerServerV1) GetScheduler(ctx context.Context, req *managerv1.GetSc
Ip: scheduler.IP,
Port: scheduler.Port,
State: scheduler.State,
Features: features,
SchedulerClusterId: uint64(scheduler.SchedulerClusterID),
SchedulerCluster: &managerv1.SchedulerCluster{
Id: uint64(scheduler.SchedulerCluster.ID),
Expand Down
24 changes: 24 additions & 0 deletions manager/service/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@ import (

"d7y.io/dragonfly/v2/manager/models"
"d7y.io/dragonfly/v2/manager/types"
"d7y.io/dragonfly/v2/pkg/structure"
)

func (s *service) CreateScheduler(ctx context.Context, json types.CreateSchedulerRequest) (*models.Scheduler, error) {
rawFeatures := types.DefaultSchedulerFeatures
if json.Features != nil {
rawFeatures = json.Features
}

features, err := structure.StructToMap(rawFeatures)
if err != nil {
return nil, err
}

scheduler := models.Scheduler{
Hostname: json.Hostname,
IDC: json.IDC,
Location: json.Location,
IP: json.IP,
Port: json.Port,
Features: features,
SchedulerClusterID: json.SchedulerClusterID,
}

Expand All @@ -54,12 +66,24 @@ func (s *service) DestroyScheduler(ctx context.Context, id uint) error {
}

func (s *service) UpdateScheduler(ctx context.Context, id uint, json types.UpdateSchedulerRequest) (*models.Scheduler, error) {
var (
features map[string]any
err error
)
if json.Features != nil {
features, err = structure.StructToMap(json.Features)
if err != nil {
return nil, err
}
}

scheduler := models.Scheduler{}
if err := s.db.WithContext(ctx).First(&scheduler, id).Updates(models.Scheduler{
IDC: json.IDC,
Location: json.Location,
IP: json.IP,
Port: json.Port,
Features: features,
SchedulerClusterID: json.SchedulerClusterID,
}).Error; err != nil {
return nil, err
Expand Down
39 changes: 27 additions & 12 deletions manager/types/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,36 @@

package types

var (
// DefaultSchedulerFeatures is the default features of scheduler.
DefaultSchedulerFeatures = &SchedulerFeatures{
Schedule: true,
Preheat: true,
}
)

type SchedulerParams struct {
ID uint `uri:"id" binding:"required"`
}

type CreateSchedulerRequest struct {
Hostname string `json:"host_name" binding:"required"`
IDC string `json:"idc" binding:"omitempty"`
Location string `json:"location" binding:"omitempty"`
IP string `json:"ip" binding:"required"`
Port int32 `json:"port" binding:"required"`
SchedulerClusterID uint `json:"scheduler_cluster_id" binding:"required"`
Hostname string `json:"host_name" binding:"required"`
IDC string `json:"idc" binding:"omitempty"`
Location string `json:"location" binding:"omitempty"`
IP string `json:"ip" binding:"required"`
Port int32 `json:"port" binding:"required"`
Features *SchedulerFeatures `json:"features" binding:"omitempty"`
SchedulerClusterID uint `json:"scheduler_cluster_id" binding:"required"`
}

type UpdateSchedulerRequest struct {
IDC string `json:"idc" binding:"omitempty"`
Location string `json:"location" binding:"omitempty"`
IP string `json:"ip" binding:"omitempty"`
Port int32 `json:"port" binding:"omitempty"`
SchedulerID uint `json:"scheduler_id" binding:"omitempty"`
SchedulerClusterID uint `json:"scheduler_cluster_id" binding:"omitempty"`
IDC string `json:"idc" binding:"omitempty"`
Location string `json:"location" binding:"omitempty"`
IP string `json:"ip" binding:"omitempty"`
Port int32 `json:"port" binding:"omitempty"`
SchedulerID uint `json:"scheduler_id" binding:"omitempty"`
Features *SchedulerFeatures `json:"features" binding:"omitempty"`
SchedulerClusterID uint `json:"scheduler_cluster_id" binding:"omitempty"`
}

type GetSchedulersQuery struct {
Expand All @@ -48,3 +58,8 @@ type GetSchedulersQuery struct {
State string `form:"state" binding:"omitempty,oneof=active inactive"`
SchedulerClusterID uint `form:"scheduler_cluster_id" binding:"omitempty"`
}

type SchedulerFeatures struct {
Schedule bool `yaml:"schedule" mapstructure:"schedule" json:"schedule" binding:"required"`
Preheat bool `yaml:"preheat" mapstructure:"preheat" json:"preheat" binding:"required"`
}

0 comments on commit bf32ad7

Please sign in to comment.