From 6d7b2cbd16c43686c696a270919455efe8a516b8 Mon Sep 17 00:00:00 2001 From: lihongyun Date: Thu, 8 Apr 2021 14:00:58 +0800 Subject: [PATCH] optimize from Reviewers Signed-off-by: lihongyun --- apis/types/task_create_request.go | 2 +- supernode/config/constants.go | 6 ++++-- supernode/daemon/mgr/progress/progress_manager.go | 2 +- supernode/daemon/mgr/progress/progress_state.go | 2 +- supernode/daemon/mgr/progress_mgr.go | 5 +++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apis/types/task_create_request.go b/apis/types/task_create_request.go index 851821767..0508e803b 100644 --- a/apis/types/task_create_request.go +++ b/apis/types/task_create_request.go @@ -102,7 +102,7 @@ type TaskCreateRequest struct { // TaskURL string `json:"taskURL,omitempty"` // peer Pattern p2p or cdn - PeerPattern int32 + PeerPattern int32 `json:"peerPattern,omitempty"` } // Validate validates this task create request diff --git a/supernode/config/constants.go b/supernode/config/constants.go index 8a0eb3eca..70ddcadb1 100644 --- a/supernode/config/constants.go +++ b/supernode/config/constants.go @@ -138,7 +138,9 @@ const ( ) // Pattern +type Pattern int32 + const ( - P2pPattern = int32(0) - CdnPattern = int32(1) + P2pPattern = Pattern(0) + CdnPattern = Pattern(1) ) diff --git a/supernode/daemon/mgr/progress/progress_manager.go b/supernode/daemon/mgr/progress/progress_manager.go index 923c446dc..0faf0a62a 100644 --- a/supernode/daemon/mgr/progress/progress_manager.go +++ b/supernode/daemon/mgr/progress/progress_manager.go @@ -95,7 +95,7 @@ func NewManager(cfg *config.Config) (*Manager, error) { } // InitProgress inits the correlation information between peers and pieces, etc. -func (pm *Manager) InitProgress(ctx context.Context, taskID, peerID, clientID string, peerPattern int32) (err error) { +func (pm *Manager) InitProgress(ctx context.Context, taskID, peerID, clientID string, peerPattern config.Pattern) (err error) { // validate the param if stringutils.IsEmptyStr(taskID) { return errors.Wrap(errortypes.ErrEmptyValue, "taskID") diff --git a/supernode/daemon/mgr/progress/progress_state.go b/supernode/daemon/mgr/progress/progress_state.go index 90095c9ea..95364012c 100644 --- a/supernode/daemon/mgr/progress/progress_state.go +++ b/supernode/daemon/mgr/progress/progress_state.go @@ -65,7 +65,7 @@ type peerState struct { serviceDownTime int64 // ServicePattern default 0 is p2p, 1 is cdn. - peerPattern int32 + peerPattern config.Pattern } type superLoadState struct { diff --git a/supernode/daemon/mgr/progress_mgr.go b/supernode/daemon/mgr/progress_mgr.go index 8b7291cee..e79c11ffc 100644 --- a/supernode/daemon/mgr/progress_mgr.go +++ b/supernode/daemon/mgr/progress_mgr.go @@ -18,6 +18,7 @@ package mgr import ( "context" + "github.com/dragonflyoss/Dragonfly/supernode/config" "github.com/dragonflyoss/Dragonfly/apis/types" "github.com/dragonflyoss/Dragonfly/pkg/atomiccount" @@ -42,13 +43,13 @@ type PeerState struct { ServiceDownTime int64 // ServicePattern default 0 is p2p, 1 is cdn. - PeerPattern int32 + PeerPattern config.Pattern } // ProgressMgr is responsible for maintaining the correspondence between peer and pieces. type ProgressMgr interface { // InitProgress inits the correlation information between peers and pieces, etc. - InitProgress(ctx context.Context, taskID, peerID, clientID string, peerPattern int32) error + InitProgress(ctx context.Context, taskID, peerID, clientID string, peerPattern config.Pattern) error // UpdateProgress updates the correlation information between peers and pieces. // 1. update the info about srcCID to tell the scheduler that corresponding peer has the piece now.