func (expectation transitionExpectation) driveFromState(allocationStore *allocationstore.AllocationStore, container executor.Container) { allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags) runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags) switch expectation.from { case "non-existent": case "reserved": _, err := allocationStore.Allocate(logger, &allocationRequest) Expect(err).NotTo(HaveOccurred()) case "initializing": _, err := allocationStore.Allocate(logger, &allocationRequest) Expect(err).NotTo(HaveOccurred()) err = allocationStore.Initialize(logger, &runReq) Expect(err).NotTo(HaveOccurred()) case "failed": _, err := allocationStore.Allocate(logger, &allocationRequest) Expect(err).NotTo(HaveOccurred()) err = allocationStore.Initialize(logger, &runReq) Expect(err).NotTo(HaveOccurred()) _, err = allocationStore.Fail(logger, container.Guid, "failure-reason") Expect(err).NotTo(HaveOccurred()) default: Fail("unknown 'from' state: " + expectation.from) } }
func (a *AuctionCellRep) lrpsToAllocationRequest(lrps []rep.LRP) ([]executor.AllocationRequest, map[string]*rep.LRP, []rep.LRP) { requests := make([]executor.AllocationRequest, 0, len(lrps)) untranslatedLRPs := make([]rep.LRP, 0) lrpMap := make(map[string]*rep.LRP, len(lrps)) for i := range lrps { lrp := &lrps[i] tags := executor.Tags{} instanceGuid, err := a.generateInstanceGuid() if err != nil { untranslatedLRPs = append(untranslatedLRPs, *lrp) continue } tags[rep.DomainTag] = lrp.Domain tags[rep.ProcessGuidTag] = lrp.ProcessGuid tags[rep.ProcessIndexTag] = strconv.Itoa(int(lrp.Index)) tags[rep.LifecycleTag] = rep.LRPLifecycle tags[rep.InstanceGuidTag] = instanceGuid rootFSPath, err := PathForRootFS(lrp.RootFs, a.stackPathMap) if err != nil { untranslatedLRPs = append(untranslatedLRPs, *lrp) continue } containerGuid := rep.LRPContainerGuid(lrp.ProcessGuid, instanceGuid) lrpMap[containerGuid] = lrp resource := executor.NewResource(int(lrp.MemoryMB), int(lrp.DiskMB), rootFSPath) requests = append(requests, executor.NewAllocationRequest(containerGuid, &resource, tags)) } return requests, lrpMap, untranslatedLRPs }
func newAllocationRequest(guid string, memoryMB, diskMB int, tagses ...executor.Tags) executor.AllocationRequest { resource := executor.NewResource(memoryMB, diskMB, "linux") var tags executor.Tags if len(tagses) > 0 { tags = tagses[0] } return executor.NewAllocationRequest(guid, &resource, tags) }
func allocationRequestFromTask(task rep.Task, rootFSPath string) executor.AllocationRequest { resource := executor.NewResource(int(task.MemoryMB), int(task.DiskMB), rootFSPath) return executor.NewAllocationRequest( task.TaskGuid, &resource, executor.Tags{ rep.LifecycleTag: rep.TaskLifecycle, rep.DomainTag: task.Domain, }, ) }
func (expectation transitionExpectation) transitionToState(allocationStore *allocationstore.AllocationStore, container executor.Container) error { switch expectation.to { case "reserve": allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags) _, err := allocationStore.Allocate(logger, &allocationRequest) return err case "initialize": runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags) return allocationStore.Initialize(logger, &runReq) case "fail": _, err := allocationStore.Fail(logger, container.Guid, "failure-reason") return err default: Fail("unknown 'to' state: " + expectation.to) return nil } }
func (a *AuctionCellRep) tasksToAllocationRequests(tasks []rep.Task) ([]executor.AllocationRequest, map[string]*rep.Task, []rep.Task) { failedTasks := make([]rep.Task, 0) taskMap := make(map[string]*rep.Task, len(tasks)) requests := make([]executor.AllocationRequest, 0, len(tasks)) for i := range tasks { task := &tasks[i] taskMap[task.TaskGuid] = task rootFSPath, err := PathForRootFS(task.RootFs, a.stackPathMap) if err != nil { failedTasks = append(failedTasks, *task) continue } tags := executor.Tags{} tags[rep.LifecycleTag] = rep.TaskLifecycle tags[rep.DomainTag] = task.Domain resource := executor.NewResource(int(task.MemoryMB), int(task.DiskMB), rootFSPath) requests = append(requests, executor.NewAllocationRequest(task.TaskGuid, &resource, tags)) } return requests, taskMap, failedTasks }
) BeforeEach(func() { currentTime = time.Now() fakeClock = fakeclock.NewFakeClock(currentTime) fakeEventEmitter = &fakes.FakeEventEmitter{} allocationStore = allocationstore.NewAllocationStore(fakeClock, fakeEventEmitter) }) Describe("List", func() { Context("when a container is allocated", func() { var req executor.AllocationRequest BeforeEach(func() { resource := executor.NewResource(512, 512, "") req = executor.NewAllocationRequest("banana", &resource, nil) _, err := allocationStore.Allocate(logger, &req) Expect(err).NotTo(HaveOccurred()) }) It("is included in the list", func() { allocations := allocationStore.List() Expect(allocations).To(HaveLen(1)) Expect(allocations[0].Guid).To(Equal(req.Guid)) }) Context("and then deallocated", func() { BeforeEach(func() { deallocated := allocationStore.Deallocate(logger, req.Guid) Expect(deallocated).To(BeTrue()) })
It("does not mark any LRP Auctions as failed", func() { failedWork, err := cellRep.Perform(rep.Work{LRPs: []rep.LRP{lrpAuctionOne, lrpAuctionTwo}}) Expect(err).NotTo(HaveOccurred()) Expect(failedWork).To(BeZero()) }) }) Context("when a container fails to be allocated", func() { BeforeEach(func() { resource := executor.NewResource(int(lrpAuctionOne.MemoryMB), int(lrpAuctionOne.DiskMB), "rootfs") tags := executor.Tags{} tags[rep.ProcessGuidTag] = lrpAuctionOne.ProcessGuid allocationRequest := executor.NewAllocationRequest( rep.LRPContainerGuid(lrpAuctionOne.ProcessGuid, expectedGuidOne), &resource, tags, ) allocationFailure := executor.NewAllocationFailure(&allocationRequest, commonErr.Error()) client.AllocateContainersReturns([]executor.AllocationFailure{allocationFailure}, nil) }) It("marks the corresponding LRP Auctions as failed", func() { failedWork, err := cellRep.Perform(rep.Work{LRPs: []rep.LRP{lrpAuctionOne, lrpAuctionTwo}}) Expect(err).NotTo(HaveOccurred()) Expect(failedWork.LRPs).To(ConsistOf(lrpAuctionOne)) }) }) }) Context("when an LRP Auction specifies a preloaded RootFSes for which it cannot determine a RootFS path", func() {