func (s *BinPackScheduler) MatchOffers(offers []*mesos.Offer, lrpAuctions []auctiontypes.LRPAuction, taskAuctions []auctiontypes.TaskAuction) map[string] /*slaveId*/ *OfferMatch { sort.Sort(auctionrunner.SortableLRPAuctions(lrpAuctions)) sort.Sort(auctionrunner.SortableTaskAuctions(taskAuctions)) offerAggregates := aggregateOffersBySlave(offers) sort.Sort(binpackSortableOfferAggregates{offerAggregates: offerAggregates, registry: s.registry}) matches := make(map[string]*OfferMatch) for _, offers := range offerAggregates { matches[offers[0].SlaveId.GetValue()] = &OfferMatch{Offers: offers} } matches[""] = &OfferMatch{} for _, lrpAuction := range lrpAuctions { _, offers := matchLrpAuction(offerAggregates, &lrpAuction) if offers != nil { matches[offers[0].SlaveId.GetValue()].LrpAuctions = append(matches[offers[0].SlaveId.GetValue()].LrpAuctions, lrpAuction) } else { matches[""].LrpAuctions = append(matches[""].LrpAuctions, lrpAuction) } } for _, taskAuction := range taskAuctions { _, offers := matchTaskAuction(offerAggregates, &taskAuction) if offers != nil { matches[offers[0].SlaveId.GetValue()].TaskAuctions = append(matches[offers[0].SlaveId.GetValue()].TaskAuctions, taskAuction) } else { matches[""].TaskAuctions = append(matches[""].TaskAuctions, taskAuction) } } return matches }
func (s *SpreadScheduler) MatchOffers(offers []*mesos.Offer, lrpAuctions []auctiontypes.LRPAuction, taskAuctions []auctiontypes.TaskAuction) map[string]*OfferMatch { s.pendingRegistry = NewTaskRegistry() sort.Sort(auctionrunner.SortableLRPAuctions(lrpAuctions)) sort.Sort(auctionrunner.SortableTaskAuctions(taskAuctions)) offerAggregates := aggregateOffersBySlave(offers) matches := make(map[string]*OfferMatch) for _, offers := range offerAggregates { matches[offers[0].SlaveId.GetValue()] = &OfferMatch{Offers: offers} } matches[""] = &OfferMatch{} for _, lrpAuction := range lrpAuctions { sort.Sort(spreadSortableOfferAggregatesForLrp{offerAggregates: offerAggregates, registry: s.registry, pendingRegistry: s.pendingRegistry, lrpGuid: lrpAuction.ProcessGuid}) _, offers := matchLrpAuction(offerAggregates, &lrpAuction) if offers != nil { matches[offers[0].SlaveId.GetValue()].LrpAuctions = append(matches[offers[0].SlaveId.GetValue()].LrpAuctions, lrpAuction) s.pendingRegistry.AddLrp(offers[0].SlaveId.GetValue(), lrpAuction.ProcessGuid, lrpAuction.Index, mesos.TaskState_TASK_STAGING) } else { matches[""].LrpAuctions = append(matches[""].LrpAuctions, lrpAuction) } } for _, taskAuction := range taskAuctions { sort.Sort(spreadSortableOfferAggregatesForTask{offerAggregates: offerAggregates, registry: s.registry, pendingRegistry: s.pendingRegistry}) _, offers := matchTaskAuction(offerAggregates, &taskAuction) if offers != nil { matches[offers[0].SlaveId.GetValue()].TaskAuctions = append(matches[offers[0].SlaveId.GetValue()].TaskAuctions, taskAuction) s.pendingRegistry.AddTask(offers[0].SlaveId.GetValue(), taskAuction.TaskGuid, mesos.TaskState_TASK_STAGING) } else { matches[""].TaskAuctions = append(matches[""].TaskAuctions, taskAuction) } } s.pendingRegistry = nil return matches }
It("sorts by index", func() { for i := 0; i < len(lrps); i++ { Expect(lrps[i].Index).To(BeEquivalentTo(i)) } }) }) }) Describe("Task Auctions", func() { var tasks []auctiontypes.TaskAuction BeforeEach(func() { tasks = []auctiontypes.TaskAuction{ BuildTaskAuction(BuildTask("tg-6", "domain", "linux", 10, 10), time.Time{}), BuildTaskAuction(BuildTask("tg-7", "domain", "linux", 20, 10), time.Time{}), BuildTaskAuction(BuildTask("tg-8", "domain", "linux", 30, 10), time.Time{}), BuildTaskAuction(BuildTask("tg-9", "domain", "linux", 40, 10), time.Time{}), } sort.Sort(auctionrunner.SortableTaskAuctions(tasks)) }) It("sorts boulders before pebbles", func() { Expect(tasks[0].Task.TaskGuid).To((Equal("tg-9"))) Expect(tasks[1].Task.TaskGuid).To((Equal("tg-8"))) Expect(tasks[2].Task.TaskGuid).To((Equal("tg-7"))) Expect(tasks[3].Task.TaskGuid).To((Equal("tg-6"))) }) }) })