func (f *FakeCell) SpinUp(serviceClient bbs.ServiceClient) {
	//make a test-friendly AuctionRepDelegate using the auction package's SimulationRepDelegate
	f.SimulationRep = simulationrep.New(f.stack, "Z0", rep.Resources{
		DiskMB:     100,
		MemoryMB:   100,
		Containers: 100,
	})

	//spin up an http auction server
	logger := lager.NewLogger(f.cellID)
	logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))

	fakeLRPStopper := new(fake_lrp_stopper.FakeLRPStopper)
	fakeExecutorClient := new(executorfakes.FakeClient)
	fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)

	handlers := rephandlers.New(f.SimulationRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger)
	router, err := rata.NewRouter(rep.Routes, handlers)
	Expect(err).NotTo(HaveOccurred())
	f.server = httptest.NewServer(router)

	presence := models.NewCellPresence(
		f.cellID,
		f.server.URL,
		"az1",
		models.NewCellCapacity(512, 1024, 124),
		[]string{},
		[]string{})

	f.heartbeater = ifrit.Invoke(serviceClient.NewCellPresenceRunner(logger, &presence, time.Second))
}
示例#2
0
文件: maintain.go 项目: jiangytcn/rep
func (m *Maintainer) createHeartbeater() (ifrit.Runner, error) {
	resources, err := m.executorClient.TotalResources(m.logger)
	if err != nil {
		return nil, err
	}

	cellCapacity := models.NewCellCapacity(int32(resources.MemoryMB), int32(resources.DiskMB), int32(resources.Containers))
	cellPresence := models.NewCellPresence(m.CellID, m.RepAddress, m.Zone, cellCapacity, m.RootFSProviders, m.PreloadedRootFSes)
	return m.serviceClient.NewCellPresenceRunner(m.logger, &cellPresence, m.RetryInterval), nil
}
示例#3
0
func newCellPresence(cellID string) *models.CellPresence {
	presence := models.NewCellPresence(
		cellID,
		"cell.example.com",
		"the-zone",
		models.NewCellCapacity(128, 1024, 6),
		[]string{},
		[]string{},
	)
	return &presence
}
		Context("when a Task is running", func() {
			BeforeEach(func() {
				err := etcdDB.DesireTask(logger, model_helpers.NewValidTaskDefinition(), taskGuid, domain)
				Expect(err).NotTo(HaveOccurred())

				_, err = etcdDB.StartTask(logger, taskGuid, "cell-id")
				Expect(err).NotTo(HaveOccurred())
			})

			It("emits a running metric", func() {
				Expect(sender.GetValue("TasksRunning").Value).To(Equal(float64(1)))
			})

			Context("when the associated cell is present", func() {
				BeforeEach(func() {
					cellPresence := models.NewCellPresence("cell-id", "1.2.3.4", "the-zone", models.NewCellCapacity(128, 1024, 3), []string{}, []string{})
					registerCell(cellPresence)
				})

				It("leaves the task running", func() {
					returnedTask, err := etcdDB.TaskByGuid(logger, taskGuid)
					Expect(err).NotTo(HaveOccurred())
					Expect(returnedTask.State).To(Equal(models.Task_Running))
				})
			})

			Context("when the associated cell is missing", func() {
				It("should mark the Task as completed & failed", func() {
					returnedTask, err := etcdDB.TaskByGuid(logger, taskGuid)
					Expect(err).NotTo(HaveOccurred())
					Expect(returnedTask.State).To(Equal(models.Task_Completed))
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("CellPresence", func() {
	var cellPresence models.CellPresence

	var payload string

	var capacity models.CellCapacity

	BeforeEach(func() {
		capacity = models.NewCellCapacity(128, 1024, 3)
		rootfsProviders := []string{"provider-1"}
		preloadedRootFSes := []string{"provider-2"}
		cellPresence = models.NewCellPresence("some-id", "some-address", "some-zone", capacity, rootfsProviders, preloadedRootFSes)

		payload = `{
    "cell_id":"some-id",
    "rep_address": "some-address",
    "zone": "some-zone",
    "capacity": {
       "memory_mb": 128,
       "disk_mb": 1024,
       "containers": 3
		 },
		 "rootfs_providers": {
			 "provider-1": [],
			 "preloaded": ["provider-2"]
		 }
   }`
	. "github.com/onsi/gomega"
	"github.com/tedsuo/ifrit/ginkgomon"
)

var _ = Describe("Convergence API", func() {
	Describe("ConvergeLRPs", func() {
		var processGuid string

		BeforeEach(func() {
			bbsRunner = testrunner.New(bbsBinPath, bbsArgs)
			bbsProcess = ginkgomon.Invoke(bbsRunner)

			cellPresence := models.NewCellPresence(
				"some-cell",
				"cell.example.com",
				"the-zone",
				models.NewCellCapacity(128, 1024, 6),
				[]string{},
				[]string{},
			)
			consulHelper.RegisterCell(&cellPresence)
			processGuid = "some-process-guid"
			etcdHelper.CreateValidDesiredLRP(processGuid)
		})

		AfterEach(func() {
			ginkgomon.Kill(bbsProcess)
		})

		It("converges the lrps", func() {
			err := client.ConvergeLRPs()
			Expect(err).NotTo(HaveOccurred())
示例#7
0
				BeforeEach(func() {
					taskDef = model_helpers.NewValidTaskDefinition()
					err := etcdDB.DesireTask(logger, taskDef, taskGuid, domain)
					Expect(err).NotTo(HaveOccurred())

					_, err = etcdDB.StartTask(logger, taskGuid, cellId)
					Expect(err).NotTo(HaveOccurred())
				})

				itMarksTaskAsCancelled()

				Context("when the cell is present", func() {
					var cellPresence models.CellPresence

					BeforeEach(func() {
						cellPresence = models.NewCellPresence(cellId, "cell.example.com", "the-zone", models.NewCellCapacity(128, 1024, 6), []string{}, []string{})
						registerCell(cellPresence)
					})

					It("cancels the task", func() {
						Expect(fakeRepClient.CancelTaskCallCount()).To(Equal(1))

						Expect(fakeRepClientFactory.CreateClientCallCount()).To(Equal(1))
						Expect(fakeRepClientFactory.CreateClientArgsForCall(0)).To(Equal(cellPresence.RepAddress))

						Expect(fakeRepClient.CancelTaskCallCount()).To(Equal(1))
						cancelledTaskGuid := fakeRepClient.CancelTaskArgsForCall(0)
						Expect(cancelledTaskGuid).To(Equal(taskGuid))
					})
				})
示例#8
0
	Describe("ConvergeTasks", func() {
		Context("when the request is normal", func() {
			var (
				kickTaskDuration            = int64(10 * time.Second)
				expirePendingTaskDuration   = int64(10 * time.Second)
				expireCompletedTaskDuration = int64(10 * time.Second)
				cellSet                     models.CellSet
			)

			BeforeEach(func() {
				requestBody = &models.ConvergeTasksRequest{
					KickTaskDuration:            kickTaskDuration,
					ExpirePendingTaskDuration:   expirePendingTaskDuration,
					ExpireCompletedTaskDuration: expireCompletedTaskDuration,
				}
				cellPresence := models.NewCellPresence("cell-id", "1.1.1.1", "z1", models.CellCapacity{}, nil, nil)
				cellSet = models.CellSet{"cell-id": &cellPresence}
				fakeServiceClient.CellsReturns(cellSet, nil)
			})

			JustBeforeEach(func() {
				request := newTestRequest(requestBody)
				handler.ConvergeTasks(responseRecorder, request)
			})

			It("calls ConvergeTasks", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
				Expect(fakeTaskDB.ConvergeTasksCallCount()).To(Equal(1))
				taskLogger, actualCellSet, actualKickDuration, actualPendingDuration, actualCompletedDuration := fakeTaskDB.ConvergeTasksArgsForCall(0)
				Expect(taskLogger.SessionName()).To(ContainSubstring("converge-tasks"))
				Expect(actualCellSet).To(BeEquivalentTo(cellSet))
示例#9
0
			BeforeEach(func() {
				err := etcdDB.DesireLRP(logger, lrp)
				Expect(err).NotTo(HaveOccurred())
			})

			It("should delete it", func() {
				err := etcdDB.RemoveDesiredLRP(logger, lrp.ProcessGuid)
				Expect(err).NotTo(HaveOccurred())

				_, err = etcdDB.DesiredLRPByProcessGuid(logger, lrp.ProcessGuid)
				Expect(err).To(HaveOccurred())
				Expect(err).To(Equal(models.ErrResourceNotFound))
			})

			Context("when there are running instances on a present cell", func() {
				cellPresence := models.NewCellPresence("the-cell-id", "cell.example.com", "az1", models.NewCellCapacity(128, 1024, 6), []string{}, []string{})

				BeforeEach(func() {
					consulHelper.RegisterCell(&cellPresence)

					for i := int32(0); i < lrp.Instances; i++ {
						instanceKey := models.NewActualLRPInstanceKey(fmt.Sprintf("some-instance-guid-%d", i), cellPresence.CellID)
						err := etcdDB.ClaimActualLRP(logger, lrp.ProcessGuid, i, &instanceKey)
						Expect(err).NotTo(HaveOccurred())
					}
				})

				It("stops all actual lrps for the desired lrp", func() {
					originalStopCallCount := fakeRepClient.StopLRPInstanceCallCount()

					err := etcdDB.RemoveDesiredLRP(logger, lrp.ProcessGuid)
		metricSender = fake.NewFakeMetricSender()
		metrics.Initialize(metricSender, nil)

		bbsClient = &fake_bbs.FakeInternalClient{}
		repClientFactory = &repfakes.FakeClientFactory{}
		repClient = &repfakes.FakeClient{}
		repClientFactory.CreateClientReturns(repClient)
		logger = lagertest.NewTestLogger("delegate")

		delegate = auctionrunnerdelegate.New(repClientFactory, bbsClient, logger)
	})

	Describe("fetching cell reps", func() {
		Context("when the BSS succeeds", func() {
			BeforeEach(func() {
				cellPresence1 := models.NewCellPresence("cell-A", "cell-a.url", "zone-1", models.NewCellCapacity(123, 456, 789), []string{}, []string{})
				cellPresence2 := models.NewCellPresence("cell-B", "cell-b.url", "zone-1", models.NewCellCapacity(123, 456, 789), []string{}, []string{})
				cells := []*models.CellPresence{&cellPresence1, &cellPresence2}

				bbsClient.CellsReturns(cells, nil)
			})

			It("creates rep clients with the correct addresses", func() {
				_, err := delegate.FetchCellReps()
				Expect(err).NotTo(HaveOccurred())
				Expect(repClientFactory.CreateClientCallCount()).To(Equal(2))
				urls := []string{
					repClientFactory.CreateClientArgsForCall(0),
					repClientFactory.CreateClientArgsForCall(1),
				}
				Expect(urls).To(ConsistOf("cell-a.url", "cell-b.url"))
示例#11
0
					Since:                777,
				}
				etcdHelper.SetRawActualLRP(actualLRP)
			})

			JustBeforeEach(func() {
				etcdDB.RetireActualLRP(logger, &lrpKey)
			})

			Context("when the cell", func() {
				Context("is present", func() {
					BeforeEach(func() {
						cellPresence = models.NewCellPresence(
							cellID,
							"cell1.addr",
							"the-zone",
							models.NewCellCapacity(128, 1024, 6),
							[]string{},
							[]string{},
						)
						consulHelper.RegisterCell(&cellPresence)
					})

					It("stops the LRPs", func() {
						Expect(fakeRepClientFactory.CreateClientCallCount()).To(Equal(1))
						Expect(fakeRepClientFactory.CreateClientArgsForCall(0)).To(Equal(cellPresence.RepAddress))

						Expect(fakeRepClient.StopLRPInstanceCallCount()).Should(Equal(1))
						stoppedKey, stoppedInstanceKey := fakeRepClient.StopLRPInstanceArgsForCall(0)
						Expect(stoppedKey).To(Equal(lrpKey))
						Expect(stoppedInstanceKey).To(Equal(instanceKey))
					})
示例#12
0
	}, func() {
		CleanupBuildArtifacts()
	})

	BeforeEach(func() {
		etcdRunner.Start()
		consulRunner.Start()
		consulRunner.WaitUntilReady()

		bbsProcess = ginkgomon.Invoke(bbsrunner.New(binPaths.Bbs, bbsArgs))
		bbsClient = bbs.NewClient(fmt.Sprint("http://", bbsArgs.Address))

		consulSession = consulRunner.NewSession("a-session")

		capacity := models.NewCellCapacity(512, 1024, 124)
		cellPresence := models.NewCellPresence("the-cell-id", "1.2.3.4", "the-zone", capacity, []string{}, []string{})

		value, err := json.Marshal(cellPresence)
		Expect(err).NotTo(HaveOccurred())

		_, err = consulSession.SetPresence(bbs.CellSchemaPath(cellPresence.CellID), value)
		Expect(err).NotTo(HaveOccurred())

	})

	AfterEach(func() {
		ginkgomon.Kill(bbsProcess)
		ginkgomon.Kill(convergerProcess)
		consulRunner.Stop()
		etcdRunner.Stop()
	})