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 (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 }
It("returns false when not found", func() { Expect(container.HasTags(executor.Tags{"a": "c"})).To(BeFalse()) }) }) }) Describe("Subtract", func() { const ( defaultDiskMB = 20 defaultMemoryMB = 30 defaultContainers = 3 ) It("returns false when the number of containers is less than 1", func() { resources := executor.NewExecutorResources(defaultMemoryMB, defaultDiskMB, 0) resourceToSubtract := executor.NewResource(defaultMemoryMB-1, defaultDiskMB-1, "rootfs") Expect(resources.Subtract(&resourceToSubtract)).To(BeFalse()) }) It("returns false when disk size exceeds total available disk size", func() { resources := executor.NewExecutorResources(defaultMemoryMB, 10, defaultContainers) resourceToSubtract := executor.NewResource(defaultMemoryMB-1, 20, "rootfs") Expect(resources.Subtract(&resourceToSubtract)).To(BeFalse()) }) It("returns false when memory exceeds total available memory", func() { resources := executor.NewExecutorResources(10, defaultDiskMB, defaultContainers) resourceToSubtract := executor.NewResource(20, defaultDiskMB-1, "rootfs") Expect(resources.Subtract(&resourceToSubtract)).To(BeFalse()) }) })
returnedContainers, err := depotClient.ListContainers(executor.Tags{}) Expect(err).NotTo(HaveOccurred()) Expect(returnedContainers).To(HaveLen(len(requests))) returnedContainersMap := convertSliceToMap(returnedContainers) Expect(returnedContainersMap).To(HaveLen(len(requests))) Expect(returnedContainersMap["guid-1"].State).To(Equal(executor.StateReserved)) Expect(returnedContainersMap["guid-2"].State).To(Equal(executor.StateReserved)) }) }) Context("when containers exist only garden store", func() { var containers []executor.Container BeforeEach(func() { r := executor.NewResource(512, 512, "") containers = []executor.Container{ newRunningContainer(newRunRequest("guid-1"), r), newRunningContainer(newRunRequest("guid-2"), r), } gardenStore.ListReturns(containers, nil) }) It("should return the containers from garden store", func() { returnedContainers, err := depotClient.ListContainers(executor.Tags{}) Expect(err).NotTo(HaveOccurred()) Expect(returnedContainers).To(HaveLen(len(containers))) returnedContainersMap := convertSliceToMap(returnedContainers) Expect(returnedContainersMap).To(HaveLen(len(containers))) Expect(returnedContainersMap).To(HaveKey("guid-1"))
currentTime time.Time ) 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())
totalResources = executor.ExecutorResources{ MemoryMB: 1024, DiskMB: 2048, Containers: 4, } availableResources = executor.ExecutorResources{ MemoryMB: 512, DiskMB: 256, Containers: 2, } containers = []executor.Container{ { Guid: "first", Resource: executor.NewResource(20, 10, "rootfs"), Tags: executor.Tags{ rep.LifecycleTag: rep.LRPLifecycle, rep.ProcessGuidTag: "the-first-app-guid", rep.ProcessIndexTag: "17", rep.DomainTag: "domain", }, }, { Guid: "second", Resource: executor.NewResource(40, 30, "rootfs"), Tags: executor.Tags{ rep.LifecycleTag: rep.LRPLifecycle, rep.ProcessGuidTag: "the-second-app-guid", rep.ProcessIndexTag: "92", rep.DomainTag: "domain",