64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
/*
|
|
|
|
Copyright (c) [2023] [pcm]
|
|
[pcm-coordinator] is licensed under Mulan PSL v2.
|
|
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
You may obtain a copy of Mulan PSL v2 at:
|
|
http://license.coscl.org.cn/MulanPSL2
|
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
See the Mulan PSL v2 for more details.
|
|
|
|
*/
|
|
|
|
package scheduler
|
|
|
|
import (
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/pkg/response"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/scheduler/algorithm/providerPricing"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type hpcScheduler struct {
|
|
yamlString string
|
|
}
|
|
|
|
func NewHpcScheduler(val string) *hpcScheduler {
|
|
return &hpcScheduler{yamlString: val}
|
|
}
|
|
|
|
func (h *hpcScheduler) getNewStructForDb(task *response.TaskInfo, resource string, participantId int64) (interface{}, error) {
|
|
hpc := models.Hpc{}
|
|
utils.Convert(task.Metadata, &hpc)
|
|
hpc.Id = utils.GenSnowflakeID()
|
|
hpc.TaskId = task.TaskId
|
|
hpc.Status = constants.Saved
|
|
hpc.ParticipantId = participantId
|
|
hpc.YamlString = h.yamlString
|
|
return hpc, nil
|
|
}
|
|
|
|
func (h *hpcScheduler) pickOptimalStrategy(task *providerPricing.Task, providers ...*providerPricing.Provider) (*providerPricing.Strategy, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (h *hpcScheduler) genTaskAndProviders(task *response.TaskInfo, dbEngin *gorm.DB) (*providerPricing.Task, []*providerPricing.Provider) {
|
|
var proParams []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"
|
|
dbEngin.Raw(sqlstr).Scan(&proParams)
|
|
|
|
var providerList []*providerPricing.Provider
|
|
for _, p := range proParams {
|
|
provider := providerPricing.NewProvider(p.Participant_id, p.Cpu_avail, p.Mem_avail, p.Disk_avail, 0.0, 0.0, 0.0)
|
|
providerList = append(providerList, provider)
|
|
}
|
|
|
|
t := providerPricing.NewTask(0, 1, 2, 75120000, 301214500, 1200, 2, 6, 2000)
|
|
|
|
return t, providerList
|
|
}
|