Skip to content

Commit

Permalink
feat: remove Scopes and SecurityGroup in seed peer cluster (dragonfly…
Browse files Browse the repository at this point in the history
…oss#2110)

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 28, 2023
1 parent f9759ca commit 2f4cc5d
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 90 deletions.
23 changes: 0 additions & 23 deletions api/manager/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4383,12 +4383,6 @@ const docTemplate = `{
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_model.SchedulerCluster"
}
},
"scopes": {
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_model.JSONMap"
},
"security_group_id": {
"type": "integer"
},
"updated_at": {
"type": "string"
}
Expand Down Expand Up @@ -4786,9 +4780,6 @@ const docTemplate = `{
},
"name": {
"type": "string"
},
"scopes": {
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes"
}
}
},
Expand Down Expand Up @@ -5079,17 +5070,6 @@ const docTemplate = `{
}
}
},
"d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes": {
"type": "object",
"properties": {
"idc": {
"type": "string"
},
"location": {
"type": "string"
}
}
},
"d7y_io_dragonfly_v2_manager_types.SignUpRequest": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5351,9 +5331,6 @@ const docTemplate = `{
},
"name": {
"type": "string"
},
"scopes": {
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes"
}
}
},
Expand Down
23 changes: 0 additions & 23 deletions api/manager/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4376,12 +4376,6 @@
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_model.SchedulerCluster"
}
},
"scopes": {
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_model.JSONMap"
},
"security_group_id": {
"type": "integer"
},
"updated_at": {
"type": "string"
}
Expand Down Expand Up @@ -4779,9 +4773,6 @@
},
"name": {
"type": "string"
},
"scopes": {
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes"
}
}
},
Expand Down Expand Up @@ -5072,17 +5063,6 @@
}
}
},
"d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes": {
"type": "object",
"properties": {
"idc": {
"type": "string"
},
"location": {
"type": "string"
}
}
},
"d7y_io_dragonfly_v2_manager_types.SignUpRequest": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5344,9 +5324,6 @@
},
"name": {
"type": "string"
},
"scopes": {
"$ref": "#/definitions/d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes"
}
}
},
Expand Down
15 changes: 0 additions & 15 deletions api/manager/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ definitions:
items:
$ref: '#/definitions/d7y_io_dragonfly_v2_manager_model.SchedulerCluster'
type: array
scopes:
$ref: '#/definitions/d7y_io_dragonfly_v2_manager_model.JSONMap'
security_group_id:
type: integer
updated_at:
type: string
type: object
Expand Down Expand Up @@ -505,8 +501,6 @@ definitions:
type: boolean
name:
type: string
scopes:
$ref: '#/definitions/d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes'
required:
- config
- name
Expand Down Expand Up @@ -712,13 +706,6 @@ definitions:
minimum: 1
type: integer
type: object
d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes:
properties:
idc:
type: string
location:
type: string
type: object
d7y_io_dragonfly_v2_manager_types.SignUpRequest:
properties:
avatar:
Expand Down Expand Up @@ -893,8 +880,6 @@ definitions:
type: boolean
name:
type: string
scopes:
$ref: '#/definitions/d7y_io_dragonfly_v2_manager_types.SeedPeerClusterScopes'
type: object
d7y_io_dragonfly_v2_manager_types.UpdateSeedPeerRequest:
properties:
Expand Down
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.19

require (
d7y.io/api v1.6.3
d7y.io/api v1.6.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
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.6.3 h1:AWF9VskBc1X1XTxLhnlZ/j/R3BpHOSvBfYBvBZJ4B6k=
d7y.io/api v1.6.3/go.mod h1:7G3t9YO5esDzQVUgdUrS+6yCDAMWS5c9ux8yX5L9Ync=
d7y.io/api v1.6.4 h1:h+fe8/EXAdP6lqyg0OAgbbn2JoMhe2EdbSbUHHRd9eE=
d7y.io/api v1.6.4/go.mod h1:7G3t9YO5esDzQVUgdUrS+6yCDAMWS5c9ux8yX5L9Ync=
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
1 change: 0 additions & 1 deletion manager/model/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ type SecurityGroup struct {
Name string `gorm:"column:name;type:varchar(256);index:uk_security_group_name,unique;not null;comment:name" json:"name"`
BIO string `gorm:"column:bio;type:varchar(1024);comment:biography" json:"bio"`
SecurityRules []SecurityRule `gorm:"many2many:security_group_security_rule;" json:"security_rules"`
SeedPeerClusters []SeedPeerCluster `json:"-"`
SchedulerClusters []SchedulerCluster `json:"-"`
}
3 changes: 0 additions & 3 deletions manager/model/seed_peer_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ type SeedPeerCluster struct {
Name string `gorm:"column:name;type:varchar(256);index:uk_seed_peer_cluster_name,unique;not null;comment:name" json:"name"`
BIO string `gorm:"column:bio;type:varchar(1024);comment:biography" json:"bio"`
Config JSONMap `gorm:"column:config;not null;comment:configuration" json:"config"`
Scopes JSONMap `gorm:"column:scopes;comment:match scopes" json:"scopes"`
IsDefault bool `gorm:"column:is_default;not null;default:false;comment:default seed peer cluster" json:"is_default"`
SchedulerClusters []SchedulerCluster `gorm:"many2many:seed_peer_cluster_scheduler_cluster;" json:"scheduler_clusters"`
SeedPeers []SeedPeer `json:"-"`
SecurityGroupID uint `gorm:"comment:security group id" json:"security_group_id"`
SecurityGroup SecurityGroup `json:"-"`
Jobs []Job `gorm:"many2many:job_seed_peer_cluster;" json:"jobs"`
}
7 changes: 7 additions & 0 deletions manager/rpcserver/manager_server_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ func (s *managerServerV1) GetScheduler(ctx context.Context, req *managerv1.GetSc
return nil, status.Error(codes.DataLoss, err.Error())
}

// Marshal scopes of client.
schedulerClusterScopes, err := scheduler.SchedulerCluster.Scopes.MarshalJSON()
if err != nil {
return nil, status.Error(codes.DataLoss, err.Error())
}

// Construct seed peers.
var pbSeedPeers []*managerv1.SeedPeer
for _, seedPeerCluster := range scheduler.SchedulerCluster.SeedPeerClusters {
Expand Down Expand Up @@ -338,6 +344,7 @@ func (s *managerServerV1) GetScheduler(ctx context.Context, req *managerv1.GetSc
Bio: scheduler.SchedulerCluster.BIO,
Config: schedulerClusterConfig,
ClientConfig: schedulerClusterClientConfig,
Scopes: schedulerClusterScopes,
},
SeedPeers: pbSeedPeers,
}
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 @@ -291,6 +291,12 @@ func (s *managerServerV2) GetScheduler(ctx context.Context, req *managerv2.GetSc
return nil, status.Error(codes.DataLoss, err.Error())
}

// Marshal scopes of client.
schedulerClusterScopes, err := scheduler.SchedulerCluster.Scopes.MarshalJSON()
if err != nil {
return nil, status.Error(codes.DataLoss, err.Error())
}

// Construct seed peers.
var pbSeedPeers []*managerv2.SeedPeer
for _, seedPeerCluster := range scheduler.SchedulerCluster.SeedPeerClusters {
Expand Down Expand Up @@ -338,6 +344,7 @@ func (s *managerServerV2) GetScheduler(ctx context.Context, req *managerv2.GetSc
Bio: scheduler.SchedulerCluster.BIO,
Config: schedulerClusterConfig,
ClientConfig: schedulerClusterClientConfig,
Scopes: schedulerClusterScopes,
},
SeedPeers: pbSeedPeers,
}
Expand Down
15 changes: 0 additions & 15 deletions manager/service/seed_peer_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ func (s *service) CreateSeedPeerCluster(ctx context.Context, json types.CreateSe
return nil, err
}

scopes, err := structure.StructToMap(json.Scopes)
if err != nil {
return nil, err
}

seedPeerCluster := model.SeedPeerCluster{
Name: json.Name,
BIO: json.BIO,
Config: config,
Scopes: scopes,
IsDefault: json.IsDefault,
}

Expand Down Expand Up @@ -80,20 +74,11 @@ func (s *service) UpdateSeedPeerCluster(ctx context.Context, id uint, json types
}
}

var scopes map[string]any
if json.Scopes != nil {
scopes, err = structure.StructToMap(json.Scopes)
if err != nil {
return nil, err
}
}

seedPeerCluster := model.SeedPeerCluster{}
if err := s.db.WithContext(ctx).First(&seedPeerCluster, id).Updates(model.SeedPeerCluster{
Name: json.Name,
BIO: json.BIO,
Config: config,
Scopes: scopes,
}).Error; err != nil {
return nil, err
}
Expand Down
7 changes: 0 additions & 7 deletions manager/types/seed_peer_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ type CreateSeedPeerClusterRequest struct {
Name string `json:"name" binding:"required"`
BIO string `json:"bio" binding:"omitempty"`
Config *SeedPeerClusterConfig `json:"config" binding:"required"`
Scopes *SeedPeerClusterScopes `json:"scopes" binding:"omitempty"`
IsDefault bool `json:"is_default" binding:"omitempty"`
}

type UpdateSeedPeerClusterRequest struct {
Name string `json:"name" binding:"omitempty"`
BIO string `json:"bio" binding:"omitempty"`
Config *SeedPeerClusterConfig `json:"config" binding:"omitempty"`
Scopes *SeedPeerClusterScopes `json:"scopes" binding:"omitempty"`
IsDefault bool `json:"is_default" binding:"omitempty"`
}

Expand All @@ -55,8 +53,3 @@ type GetSeedPeerClustersQuery struct {
type SeedPeerClusterConfig struct {
LoadLimit uint32 `yaml:"loadLimit" mapstructure:"loadLimit" json:"load_limit" binding:"omitempty,gte=1,lte=5000"`
}

type SeedPeerClusterScopes struct {
IDC string `yaml:"idc" mapstructure:"idc" json:"idc" binding:"omitempty"`
Location string `yaml:"location" mapstructure:"location" json:"location" binding:"omitempty"`
}

0 comments on commit 2f4cc5d

Please sign in to comment.