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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/service/collector"
  19. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/scheduler/strategy"
  20. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/pkg/response"
  21. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
  22. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
  23. )
  24. type AiScheduler struct {
  25. yamlString string
  26. task *response.TaskInfo
  27. *scheduler.Scheduler
  28. }
  29. func NewAiScheduler(val string, scheduler *scheduler.Scheduler) (*AiScheduler, error) {
  30. return &AiScheduler{yamlString: val, Scheduler: scheduler}, nil
  31. }
  32. func (as *AiScheduler) GetNewStructForDb(task *response.TaskInfo, resource string, participantId int64) (interface{}, error) {
  33. ai := models.Ai{
  34. ParticipantId: participantId,
  35. TaskId: task.TaskId,
  36. Status: "Saved",
  37. YamlString: as.yamlString,
  38. }
  39. utils.Convert(task.Metadata, &ai)
  40. return ai, nil
  41. }
  42. func (as *AiScheduler) PickOptimalStrategy() (strategy.Strategy, error) {
  43. resources, err := as.findProvidersWithResource()
  44. if err != nil {
  45. return nil, err
  46. }
  47. if len(resources) < 2 /*|| as.task */ {
  48. var pros []entity.Participant
  49. for _, resource := range resources {
  50. pros = append(pros, entity.Participant{
  51. Participant_id: resource.ParticipantId,
  52. Name: resource.Name,
  53. })
  54. }
  55. strategy := strategy.NewReplicationStrategy(nil, 0)
  56. return strategy, nil
  57. }
  58. task, providerList := as.genTaskAndProviders()
  59. if err != nil {
  60. return nil, nil
  61. }
  62. strategy := strategy.NewPricingStrategy(task, providerList...)
  63. return strategy, nil
  64. }
  65. func (as *AiScheduler) genTaskAndProviders() (*providerPricing.Task, []*providerPricing.Provider) {
  66. return nil, nil
  67. }
  68. func (as *AiScheduler) AssignTask(clusters []*strategy.AssignedCluster) error {
  69. if clusters == nil {
  70. return errors.New("clusters is nil")
  71. }
  72. _ = *as.AiExecutor
  73. return nil
  74. }
  75. func (as *AiScheduler) findProvidersWithResource() ([]*collector.ResourceSpecs, error) {
  76. var resourceSpecs []*collector.ResourceSpecs
  77. for _, resourceCollector := range *as.ResourceCollector {
  78. spec, err := resourceCollector.GetResourceSpecs()
  79. if err != nil {
  80. continue
  81. }
  82. resourceSpecs = append(resourceSpecs, spec)
  83. }
  84. if len(resourceSpecs) == 0 {
  85. return nil, errors.New("no resource found")
  86. }
  87. return resourceSpecs, nil
  88. }

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.