Merge pull request 'scheduler refactor updated' (#6) from tzwang/pcm-coordinator:master into master

Former-commit-id: 18455bc5a0fefac5f2256aabc4e48dac546f45f5
This commit is contained in:
tzwang 2024-01-17 17:15:40 +08:00
commit 3b17ce4606
4 changed files with 56 additions and 13 deletions

View File

@ -1,6 +1,9 @@
package database package database
import "gorm.io/gorm" import (
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/scheduler/entity"
"gorm.io/gorm"
)
type CloudStorage struct { type CloudStorage struct {
dbEngin *gorm.DB dbEngin *gorm.DB
@ -10,8 +13,8 @@ func NewCloudStorage(dbEngin *gorm.DB) *CloudStorage {
return &CloudStorage{dbEngin: dbEngin} return &CloudStorage{dbEngin: dbEngin}
} }
func (c *CloudStorage) GetProviderParams() ([]providerParams, error) { func (c *CloudStorage) GetProviderParams() ([]entity.ProviderParams, error) {
var proParams []providerParams var proParams []entity.ProviderParams
sqlstr := "SELECT SUM(a.disk_avail) as disk_avail,SUM(a.mem_avail) as mem_avail,SUM(a.cpu_total * a.cpu_usable) as cpu_avail,participant_id from (SELECT * from sc_node_avail_info where created_time in (SELECT MAX(created_time) as time from sc_node_avail_info where deleted_flag = 0 GROUP BY participant_id,node_name)) a GROUP BY a.participant_id" sqlstr := "SELECT SUM(a.disk_avail) as disk_avail,SUM(a.mem_avail) as mem_avail,SUM(a.cpu_total * a.cpu_usable) as cpu_avail,participant_id from (SELECT * from sc_node_avail_info where created_time in (SELECT MAX(created_time) as time from sc_node_avail_info where deleted_flag = 0 GROUP BY participant_id,node_name)) a GROUP BY a.participant_id"
c.dbEngin.Raw(sqlstr).Scan(&proParams) c.dbEngin.Raw(sqlstr).Scan(&proParams)
if len(proParams) == 0 { if len(proParams) == 0 {
@ -20,9 +23,12 @@ func (c *CloudStorage) GetProviderParams() ([]providerParams, error) {
return proParams, nil return proParams, nil
} }
type providerParams struct { func (c *CloudStorage) FindAvailableParticipants() ([]entity.Participant, error) {
Disk_avail float64 var parts []entity.Participant
Mem_avail float64 sqlstr := "select id as participant_id, name as name from sc_participant_phy_info"
Cpu_avail float64 c.dbEngin.Raw(sqlstr).Scan(&parts)
Participant_id int64 if len(parts) == 0 {
return nil, nil
}
return parts, nil
} }

View File

@ -1,8 +1,10 @@
package database package database
import "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/scheduler/entity"
type Storage interface { type Storage interface {
GetProviderParams() ([]providerParams, error) GetProviderParams() ([]entity.ProviderParams, error)
FindAvailableCluster() FindAvailableParticipants() ([]entity.Participant, error)
} }
type NSIDSpecified interface { type NSIDSpecified interface {

View File

@ -0,0 +1,13 @@
package entity
type ProviderParams struct {
Disk_avail float64
Mem_avail float64
Cpu_avail float64
Participant_id int64
}
type Participant struct {
Name string
Participant_id int64
}

View File

@ -1,12 +1,34 @@
package strategies package strategies
import (
"github.com/pkg/errors"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/scheduler/entity"
)
type ReplicationStrategy struct { type ReplicationStrategy struct {
replicas int32
participants []entity.Participant
} }
func (ps *ReplicationStrategy) findAvailableCLuster() error { func NewReplicationStrategy(participants []entity.Participant, replicas int32) *ReplicationStrategy {
return nil return &ReplicationStrategy{replicas: replicas,
participants: participants,
}
} }
func (ps *ReplicationStrategy) Schedule() ([]*AssignedCluster, error) { func (ps *ReplicationStrategy) Schedule() ([]*AssignedCluster, error) {
return nil, nil if ps.replicas < 1 {
return nil, errors.New("replicas must be greater than 0")
}
if ps.participants == nil {
return nil, errors.New("participantId must be set")
}
var results []*AssignedCluster
for _, p := range ps.participants {
cluster := &AssignedCluster{ParticipantId: p.Participant_id, Name: p.Name, Replicas: ps.replicas}
results = append(results, cluster)
}
return results, nil
} }