|
- /*
-
- 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/models"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/scheduler/algo"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
- "gorm.io/gorm"
- )
-
- type aiScheduler struct {
- yamlString string
- }
-
- func NewAiScheduler(val string) *aiScheduler {
- return &aiScheduler{yamlString: val}
- }
-
- func (as *aiScheduler) getNewStructForDb(task *response.TaskInfo, resource interface{}, participantId int64) (interface{}, error) {
- ai := models.Ai{
- ParticipantId: participantId,
- TaskId: task.TaskId,
- Status: "Saved",
- YamlString: as.yamlString,
- }
- utils.Convert(task.Metadata, &ai)
- return ai, nil
- }
-
- func (as *aiScheduler) pickOptimalStrategy(task *algo.Task, providers ...*algo.Provider) (*algo.Strategy, error) {
- return nil, nil
- }
-
- func (as *aiScheduler) genTaskAndProviders(task *response.TaskInfo, dbEngin *gorm.DB) (*algo.Task, []*algo.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 []*algo.Provider
- for _, p := range proParams {
- provider := algo.NewProvider(p.Participant_id, p.Cpu_avail, p.Mem_avail, p.Disk_avail, 0.0, 0.0, 0.0)
- providerList = append(providerList, provider)
- }
-
- t := algo.NewTask(0, 1, 2, 75120000, 301214500, 1200, 2, 6, 2000)
-
- return t, providerList
- }
|