Пример #1
0
func (r *SimulationRep) State() (rep.CellState, error) {
	r.lock.Lock()
	defer r.lock.Unlock()

	lrps := []rep.LRP{}
	for _, lrp := range r.lrps {
		lrps = append(lrps, lrp)
	}

	tasks := []rep.Task{}
	for _, task := range r.tasks {
		tasks = append(tasks, task)
	}

	availableResources := r.availableResources()

	// util.RandomSleep(800, 900)

	return rep.CellState{
		RootFSProviders: rep.RootFSProviders{
			models.PreloadedRootFSScheme: rep.NewFixedSetRootFSProvider(r.stack),
		},
		AvailableResources: availableResources,
		TotalResources:     r.totalResources,
		LRPs:               lrps,
		Tasks:              tasks,
		StartingContainerCount: r.startingContainerCount,
		Zone: r.zone,
	}, nil
}
Пример #2
0
func rootFSProviders(preloaded rep.StackPathMap, arbitrary []string) rep.RootFSProviders {
	rootFSProviders := rep.RootFSProviders{}
	for _, scheme := range arbitrary {
		rootFSProviders[scheme] = rep.ArbitraryRootFSProvider{}
	}

	stacks := make([]string, 0, len(preloaded))
	for stack, _ := range preloaded {
		stacks = append(stacks, stack)
	}
	rootFSProviders["preloaded"] = rep.NewFixedSetRootFSProvider(stacks...)

	return rootFSProviders
}
Пример #3
0
		lrpKey := models.NewActualLRPKey(start.ProcessGuid, int32(index), start.Domain)
		auctions = append(auctions, auctiontypes.NewLRPAuction(rep.NewLRP(lrpKey, start.Resource), queueTime))
	}

	return auctions
}

func BuildTaskAuction(task *rep.Task, queueTime time.Time) auctiontypes.TaskAuction {
	return auctiontypes.NewTaskAuction(*task, queueTime)
}

const linuxStack = "linux"

var linuxRootFSURL = models.PreloadedRootFS(linuxStack)

var linuxOnlyRootFSProviders = rep.RootFSProviders{models.PreloadedRootFSScheme: rep.NewFixedSetRootFSProvider(linuxStack)}

const windowsStack = "windows"

var windowsRootFSURL = models.PreloadedRootFS(windowsStack)

var windowsOnlyRootFSProviders = rep.RootFSProviders{models.PreloadedRootFSScheme: rep.NewFixedSetRootFSProvider(windowsStack)}

func BuildCellState(
	zone string,
	memoryMB int32,
	diskMB int32,
	containers int,
	evacuating bool,
	startingContainerCount int,
	rootFSProviders rep.RootFSProviders,
Пример #4
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RootFSProviders", func() {
	var (
		arbitrary rep.ArbitraryRootFSProvider
		fixedSet  rep.FixedSetRootFSProvider
		providers rep.RootFSProviders

		providersJSON string
	)

	BeforeEach(func() {
		arbitrary = rep.ArbitraryRootFSProvider{}
		fixedSet = rep.NewFixedSetRootFSProvider("baz", "quux")
		providers = rep.RootFSProviders{
			"foo": arbitrary,
			"bar": fixedSet,
		}

		providersJSON = `{
				"foo": {
					"type": "arbitrary"
				},
				"bar": {
					"type": "fixed_set",
					"set": {"baz":{}, "quux":{}}
				}
			}`
Пример #5
0
				})
			})
		})

		Describe("matching the RootFS", func() {
			Context("when the cell provides a complex array of RootFSes", func() {
				BeforeEach(func() {
					state := BuildCellState(
						"the-zone",
						100,
						100,
						100,
						false,
						0,
						rep.RootFSProviders{
							"fixed-set-1": rep.NewFixedSetRootFSProvider("root-fs-1", "root-fs-2"),
							"fixed-set-2": rep.NewFixedSetRootFSProvider("root-fs-1", "root-fs-2"),
							"arbitrary-1": rep.ArbitraryRootFSProvider{},
							"arbitrary-2": rep.ArbitraryRootFSProvider{},
						},
						[]rep.LRP{},
					)
					cell = auctionrunner.NewCell(logger, "the-cell", client, state)
				})

				It("should support LRPs with various stack requirements", func() {
					score, err := cell.ScoreForLRP(BuildLRP("pg", "domain", 0, "fixed-set-1:root-fs-1", 10, 10), 0.0)
					Expect(score).To(BeNumerically(">", 0))
					Expect(err).NotTo(HaveOccurred())

					score, err = cell.ScoreForLRP(BuildLRP("pg", "domain", 0, "fixed-set-1:root-fs-2", 10, 10), 0.0)
Пример #6
0
					Tags:     nil,
				},
			}

			client.TotalResourcesReturns(totalResources, nil)
			client.RemainingResourcesReturns(availableResources, nil)
			client.ListContainersReturns(containers, nil)
		})

		It("queries the client and returns state", func() {
			state, err := cellRep.State()
			Expect(err).NotTo(HaveOccurred())

			Expect(state.Evacuating).To(BeTrue())
			Expect(state.RootFSProviders).To(Equal(rep.RootFSProviders{
				models.PreloadedRootFSScheme: rep.NewFixedSetRootFSProvider("linux"),
				"docker":                     rep.ArbitraryRootFSProvider{},
			}))

			Expect(state.AvailableResources).To(Equal(rep.Resources{
				MemoryMB:   int32(availableResources.MemoryMB),
				DiskMB:     int32(availableResources.DiskMB),
				Containers: availableResources.Containers,
			}))

			Expect(state.TotalResources).To(Equal(rep.Resources{
				MemoryMB:   int32(totalResources.MemoryMB),
				DiskMB:     int32(totalResources.DiskMB),
				Containers: totalResources.Containers,
			}))