Skip to content

Commit

Permalink
fix: manager typo and cdn peer id (#809)
Browse files Browse the repository at this point in the history
* fix: manager typo and cdn peer id 

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Nov 19, 2021
1 parent a7efb7c commit 5010ae1
Show file tree
Hide file tree
Showing 44 changed files with 369 additions and 326 deletions.
2 changes: 1 addition & 1 deletion cdn/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (css *server) GetPieceTasks(ctx context.Context, req *base.PieceTaskRequest
}
pp := &base.PiecePacket{
TaskId: req.TaskId,
DstPid: fmt.Sprintf("%s-%s_%s", iputils.HostName, req.TaskId, "CDN"),
DstPid: req.DstPid,
DstAddr: fmt.Sprintf("%s:%d", css.cfg.AdvertiseIP, css.cfg.DownloadPort),
PieceInfos: pieceInfos,
TotalPiece: task.PieceTotal,
Expand Down
2 changes: 1 addition & 1 deletion internal/idgen/peer_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func CDNPeerID(ip string) string {
return fmt.Sprintf("%s-%s", PeerID(ip), "cdn")
return fmt.Sprintf("%s_%s", PeerID(ip), "CDN")
}

func PeerID(ip string) string {
Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroyApplication(ctx *gin.Context) {
func (h *Handlers) UpdateApplication(ctx *gin.Context) {
var params types.ApplicationParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateApplicationRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroyCDN(ctx *gin.Context) {
func (h *Handlers) UpdateCDN(ctx *gin.Context) {
var params types.CDNParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateCDNRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/cdn_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroyCDNCluster(ctx *gin.Context) {
func (h *Handlers) UpdateCDNCluster(ctx *gin.Context) {
var params types.CDNClusterParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateCDNClusterRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroyConfig(ctx *gin.Context) {
func (h *Handlers) UpdateConfig(ctx *gin.Context) {
var params types.ConfigParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateConfigRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ func (h *Handlers) DestroyJob(ctx *gin.Context) {
func (h *Handlers) UpdateJob(ctx *gin.Context) {
var params types.JobParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateJobRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroyOauth(ctx *gin.Context) {
func (h *Handlers) UpdateOauth(ctx *gin.Context) {
var params types.OauthParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateOauthRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroyScheduler(ctx *gin.Context) {
func (h *Handlers) UpdateScheduler(ctx *gin.Context) {
var params types.SchedulerParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateSchedulerRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/scheduler_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroySchedulerCluster(ctx *gin.Context) {
func (h *Handlers) UpdateSchedulerCluster(ctx *gin.Context) {
var params types.SchedulerClusterParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateSchedulerClusterRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroySecurityGroup(ctx *gin.Context) {
func (h *Handlers) UpdateSecurityGroup(ctx *gin.Context) {
var params types.SecurityGroupParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateSecurityGroupRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
4 changes: 2 additions & 2 deletions manager/handlers/security_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (h *Handlers) DestroySecurityRule(ctx *gin.Context) {
func (h *Handlers) UpdateSecurityRule(ctx *gin.Context) {
var params types.SecurityRuleParams
if err := ctx.ShouldBindUri(&params); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

var json types.UpdateSecurityRuleRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.Error(err) // nolint: errcheck
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

Expand Down
3 changes: 2 additions & 1 deletion manager/model/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package model
type Application struct {
Model
Name string `gorm:"column:name;type:varchar(256);index:uk_application_name,unique;not null;comment:name" json:"name"`
DownloadRateLimit string `gorm:"column:download_rate_limit;type:varchar(1024);comment:download_rate_limit" json:"download_rate_limit"`
DownloadRateLimit uint `gorm:"column:download_rate_limit;comment:download rate limit" json:"download_rate_limit"`
URL string `gorm:"column:url;not null;comment:url" json:"url"`
State string `gorm:"column:state;type:varchar(256);default:'enable';comment:state" json:"state"`
BIO string `gorm:"column:bio;type:varchar(1024);comment:biography" json:"bio"`
UserID uint `gorm:"comment:user id" json:"user_id"`
User User `json:"-"`
SchedulerClusters []SchedulerCluster `json:"-"`
CDNClusters []CDNCluster `json:"-"`
}
6 changes: 3 additions & 3 deletions manager/model/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package model

const (
CDNStatusActive = "active"
CDNStatusInactive = "inactive"
CDNStateActive = "active"
CDNStateInactive = "inactive"
)

type CDN struct {
Expand All @@ -29,7 +29,7 @@ type CDN 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"`
DownloadPort int32 `gorm:"column:download_port;not null;comment:download service listening port" json:"download_port"`
Status string `gorm:"column:status;type:varchar(256);default:'inactive';comment:service status" json:"status"`
State string `gorm:"column:state;type:varchar(256);default:'inactive';comment:service state" json:"state"`
CDNClusterID uint `gorm:"index:uk_cdn,unique;not null;comment:cdn cluster id"`
CDNCluster CDNCluster `json:"-"`
}
3 changes: 2 additions & 1 deletion manager/model/cdn_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type CDNCluster struct {
SchedulerClusters []SchedulerCluster `gorm:"many2many:cdn_cluster_scheduler_cluster;" json:"scheduler_clusters"`
IsDefault bool `gorm:"column:is_default;not null;default:false;comment:default cdn cluster" json:"is_default"`
CDNs []CDN `json:"-"`
SecurityGroupID uint `gorm:"comment:security group id" json:"security_group_id"`
ApplicationID uint `gorm:"comment:application id" json:"application_id"`
Application Application `json:"-"`
SecurityGroupID uint `gorm:"comment:security group id" json:"security_group_id"`
SecurityGroup SecurityGroup `json:"-"`
Jobs []Job `gorm:"many2many:job_cdn_cluster;" json:"jobs"`
}
2 changes: 1 addition & 1 deletion manager/model/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Job struct {
TaskID string `gorm:"column:task_id;type:varchar(256);not null;comment:task id" json:"task_id"`
BIO string `gorm:"column:bio;type:varchar(1024);comment:biography" json:"bio"`
Type string `gorm:"column:type;type:varchar(256);comment:type" json:"type"`
Status string `gorm:"column:status;type:varchar(256);not null;default:'PENDING';comment:service status" json:"status"`
State string `gorm:"column:state;type:varchar(256);not null;default:'PENDING';comment:service state" json:"state"`
Args JSONMap `gorm:"column:args;not null;comment:task request args" json:"args"`
Result JSONMap `gorm:"column:result;comment:task result" json:"result"`
UserID uint `gorm:"column:user_id;comment:user id" json:"user_id"`
Expand Down
6 changes: 3 additions & 3 deletions manager/model/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package model

const (
SchedulerStatusActive = "active"
SchedulerStatusInactive = "inactive"
SchedulerStateActive = "active"
SchedulerStateInactive = "inactive"
)

type Scheduler struct {
Expand All @@ -30,7 +30,7 @@ type Scheduler struct {
NetConfig JSONMap `gorm:"column:net_config;comment:network configuration" json:"net_config"`
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"`
Status string `gorm:"column:status;type:varchar(256);default:'inactive';comment:service status" json:"status"`
State string `gorm:"column:state;type:varchar(256);default:'inactive';comment:service state" json:"state"`
SchedulerClusterID uint `gorm:"index:uk_scheduler,unique;not null;comment:scheduler cluster id"`
SchedulerCluster SchedulerCluster `json:"-"`
}
3 changes: 2 additions & 1 deletion manager/model/scheduler_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type SchedulerCluster struct {
IsDefault bool `gorm:"column:is_default;not null;default:false;comment:default scheduler cluster" json:"is_default"`
CDNClusters []CDNCluster `gorm:"many2many:cdn_cluster_scheduler_cluster;" json:"cdn_clusters"`
Schedulers []Scheduler `json:"-"`
ApplicationID uint `gorm:"comment:application id" json:"application_id"`
Application Application `json:"-"`
SecurityGroupID uint `gorm:"comment:security group id" json:"security_group_id"`
SecurityGroup SecurityGroup `json:"-"`
Jobs []Job `gorm:"many2many:job_scheduler_cluster;" json:"jobs"`
ApplicationID uint `gorm:"comment:application id" json:"application_id"`
}
11 changes: 9 additions & 2 deletions manager/searcher/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (

"github.com/mitchellh/mapstructure"

logger "d7y.io/dragonfly/v2/internal/dflog"
"d7y.io/dragonfly/v2/manager/model"
"d7y.io/dragonfly/v2/pkg/rpc/manager"
"d7y.io/dragonfly/v2/pkg/util/mathutils"
)

Expand Down Expand Up @@ -70,7 +72,7 @@ type Scopes struct {
}

type Searcher interface {
FindSchedulerCluster([]model.SchedulerCluster, map[string]string) (model.SchedulerCluster, bool)
FindSchedulerCluster([]model.SchedulerCluster, *manager.ListSchedulersRequest) (model.SchedulerCluster, bool)
}

type searcher struct{}
Expand All @@ -84,7 +86,8 @@ func New() Searcher {
return s
}

func (s *searcher) FindSchedulerCluster(schedulerClusters []model.SchedulerCluster, conditions map[string]string) (model.SchedulerCluster, bool) {
func (s *searcher) FindSchedulerCluster(schedulerClusters []model.SchedulerCluster, client *manager.ListSchedulersRequest) (model.SchedulerCluster, bool) {
conditions := client.HostInfo
if len(schedulerClusters) <= 0 || len(conditions) <= 0 {
return model.SchedulerCluster{}, false
}
Expand All @@ -94,6 +97,10 @@ func (s *searcher) FindSchedulerCluster(schedulerClusters []model.SchedulerClust
// Then use clusters sets to score according to scopes.
var clusters []model.SchedulerCluster
securityDomain := conditions[conditionSecurityDomain]
if securityDomain == "" {
logger.Infof("client %s %s have empty security domain", client.HostName, client.Ip)
}

for _, schedulerCluster := range schedulerClusters {
if len(schedulerCluster.Schedulers) > 0 {
if securityDomain == "" {
Expand Down
Loading

0 comments on commit 5010ae1

Please sign in to comment.