feat: add scheduler configuration support

Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
chlins 2025-07-16 15:07:02 +08:00
parent 2a30115765
commit fdab4fa0ac
3 changed files with 45 additions and 14 deletions

View File

@ -26,6 +26,7 @@ const (
type Scheduler struct {
BaseModel
Config JSONMap `gorm:"column:config;comment:configuration" json:"config"`
Hostname string `gorm:"column:host_name;type:varchar(256);index:uk_scheduler,unique;not null;comment:hostname" json:"host_name"`
IDC string `gorm:"column:idc;type:varchar(1024);comment:internet data center" json:"idc"`
Location string `gorm:"column:location;type:varchar(1024);comment:location" json:"location"`

View File

@ -21,6 +21,7 @@ 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) {
@ -39,6 +40,15 @@ func (s *service) CreateScheduler(ctx context.Context, json types.CreateSchedule
SchedulerClusterID: json.SchedulerClusterID,
}
if json.Config != nil {
config, err := structure.StructToMap(json.Config)
if err != nil {
return nil, err
}
scheduler.Config = config
}
if err := s.db.WithContext(ctx).Create(&scheduler).Error; err != nil {
return nil, err
}
@ -60,8 +70,20 @@ 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 (
config map[string]any
err error
)
if json.Config != nil {
config, err = structure.StructToMap(json.Config)
if err != nil {
return nil, err
}
}
scheduler := models.Scheduler{}
if err := s.db.WithContext(ctx).First(&scheduler, id).Updates(models.Scheduler{
Config: config,
IDC: json.IDC,
Location: json.Location,
IP: json.IP,

View File

@ -16,11 +16,14 @@
package types
import "time"
type SchedulerParams struct {
ID uint `uri:"id" binding:"required"`
}
type CreateSchedulerRequest struct {
Config *SchedulerConfig `json:"config" binding:"omitempty"`
Hostname string `json:"host_name" binding:"required"`
IDC string `json:"idc" binding:"omitempty"`
Location string `json:"location" binding:"omitempty"`
@ -31,6 +34,7 @@ type CreateSchedulerRequest struct {
}
type UpdateSchedulerRequest struct {
Config *SchedulerConfig `json:"config" binding:"omitempty"`
IDC string `json:"idc" binding:"omitempty"`
Location string `json:"location" binding:"omitempty"`
IP string `json:"ip" binding:"omitempty"`
@ -50,3 +54,7 @@ type GetSchedulersQuery struct {
State string `form:"state" binding:"omitempty,oneof=active inactive"`
SchedulerClusterID uint `form:"scheduler_cluster_id" binding:"omitempty"`
}
type SchedulerConfig struct {
ManagerKeepAliveInterval time.Duration `json:"manager_keep_alive_interval" binding:"required"`
}