You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

aiScheduler.go 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package schedulers
  13. import (
  14. "errors"
  15. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler"
  16. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/algorithm/providerPricing"
  17. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/entity"
  18. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/schedulers/option"
  19. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/service/collector"
  20. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/strategy"
  21. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/pkg/response"
  22. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
  23. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
  24. )
  25. type AiScheduler struct {
  26. yamlString string
  27. task *response.TaskInfo
  28. *scheduler.Scheduler
  29. option option.AiOption
  30. }
  31. func NewAiScheduler(val string, scheduler *scheduler.Scheduler) (*AiScheduler, error) {
  32. return &AiScheduler{yamlString: val, Scheduler: scheduler}, nil
  33. }
  34. func (as *AiScheduler) GetNewStructForDb(task *response.TaskInfo, resource string, participantId int64) (interface{}, error) {
  35. ai := models.Ai{
  36. ParticipantId: participantId,
  37. TaskId: task.TaskId,
  38. Status: "Saved",
  39. YamlString: as.yamlString,
  40. }
  41. utils.Convert(task.Metadata, &ai)
  42. return ai, nil
  43. }
  44. func (as *AiScheduler) PickOptimalStrategy() (strategy.Strategy, error) {
  45. resources, err := as.findClustersWithResource()
  46. if err != nil {
  47. return nil, err
  48. }
  49. if len(resources) < 2 /*|| as.task */ {
  50. var pros []entity.Participant
  51. for _, resource := range resources {
  52. pros = append(pros, entity.Participant{
  53. Participant_id: resource.ParticipantId,
  54. Name: resource.Name,
  55. })
  56. }
  57. strategy := strategy.NewReplicationStrategy(nil, 0)
  58. return strategy, nil
  59. }
  60. task, providerList := as.genTaskAndProviders()
  61. if err != nil {
  62. return nil, nil
  63. }
  64. strategy := strategy.NewPricingStrategy(task, providerList...)
  65. return strategy, nil
  66. }
  67. func (as *AiScheduler) genTaskAndProviders() (*providerPricing.Task, []*providerPricing.Provider) {
  68. return nil, nil
  69. }
  70. func (as *AiScheduler) AssignTask(clusters []*strategy.AssignedCluster) error {
  71. if clusters == nil {
  72. return errors.New("clusters is nil")
  73. }
  74. executorMap := *as.AiExecutor
  75. for _, cluster := range clusters {
  76. _, err := executorMap[cluster.Name].Execute(option.AiOption{})
  77. if err != nil {
  78. // TODO: database operation
  79. }
  80. // TODO: database operation
  81. }
  82. return nil
  83. }
  84. func (as *AiScheduler) findClustersWithResource() ([]*collector.ResourceSpecs, error) {
  85. var resourceSpecs []*collector.ResourceSpecs
  86. for _, resourceCollector := range *as.ResourceCollector {
  87. spec, err := resourceCollector.GetResourceSpecs()
  88. if err != nil {
  89. continue
  90. }
  91. resourceSpecs = append(resourceSpecs, spec)
  92. }
  93. if len(resourceSpecs) == 0 {
  94. return nil, errors.New("no resource found")
  95. }
  96. return resourceSpecs, nil
  97. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.