Beispiel #1
0
func newCellPresence(cellID string) *models.CellPresence {
	presence := models.NewCellPresence(
		cellID,
		"cell.example.com",
		"the-zone",
		models.NewCellCapacity(128, 1024, 6),
		[]string{},
		nil,
		nil,
		nil,
	)
	return &presence
}
					&models.ActualLRPGroup{Instance: unclaimingActualLRP2}, nil
			}
			return nil, nil, models.ErrResourceNotFound
		}

		fakeLRPDB.ConvergeLRPsReturns(keysToAuction, keysWithMissingCells, keysToRetire)

		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))

		fakeServiceClient = new(fake_bbs.FakeServiceClient)
		fakeRepClientFactory = new(repfakes.FakeClientFactory)
		fakeRepClient = new(repfakes.FakeClient)
		fakeRepClientFactory.CreateClientReturns(fakeRepClient, nil)
		fakeServiceClient.CellByIdReturns(nil, errors.New("hi"))

		cellPresence := models.NewCellPresence("cell-id", "1.1.1.1", "", "z1", models.CellCapacity{}, nil, nil, nil, nil)
		cellSet = models.CellSet{"cell-id": &cellPresence}
		fakeServiceClient.CellsReturns(cellSet, nil)

		actualHub = &eventfakes.FakeHub{}
		retirer := controllers.NewActualLRPRetirer(fakeLRPDB, actualHub, fakeRepClientFactory, fakeServiceClient)
		controller = controllers.NewLRPConvergenceController(logger, fakeLRPDB, actualHub, fakeAuctioneerClient, fakeServiceClient, retirer, 2)
	})

	JustBeforeEach(func() {
		err = controller.ConvergeLRPs(logger)
	})

	It("calls ConvergeLRPs", func() {
		Expect(err).NotTo(HaveOccurred())
		Expect(fakeLRPDB.ConvergeLRPsCallCount()).To(Equal(1))
Beispiel #3
0
)

var _ = Describe("CellPresence", func() {
	var (
		cellPresence         models.CellPresence
		capacity             models.CellCapacity
		expectedProviderList []*models.Provider
	)

	BeforeEach(func() {
		capacity = models.NewCellCapacity(128, 1024, 3)
		rootfsProviders := []string{"provider-1"}
		preloadedRootFSes := []string{"provider-2", "provider-3"}
		placementTags := []string{"tag-1", "tag-2"}
		optionalPlacementTags := []string{"optional-tag-1", "optional-tag-2"}
		cellPresence = models.NewCellPresence("some-id", "some-address", "some-zone", capacity, rootfsProviders, preloadedRootFSes, placementTags, optionalPlacementTags)
		expectedProviderList = []*models.Provider{
			&models.Provider{"preloaded", []string{"provider-2", "provider-3"}},
			&models.Provider{"provider-1", []string{}},
		}
	})

	Describe("Validate", func() {
		Context("when cell presence is valid", func() {
			It("does not return an error", func() {
				Expect(cellPresence.Validate()).NotTo(HaveOccurred())
				Expect(cellPresence.GetRootfsProviders()).To(Equal(expectedProviderList))
			})
		})

		Context("when cell presence is invalid", func() {
			})
		})
	})

	Describe("ConvergeTasks", func() {
		Context("when the request is normal", func() {
			var (
				kickTaskDuration            = 10 * time.Second
				expirePendingTaskDuration   = 10 * time.Second
				expireCompletedTaskDuration = 10 * time.Second
				cellSet                     models.CellSet
				err                         error
			)

			BeforeEach(func() {
				cellPresence := models.NewCellPresence("cell-id", "1.1.1.1", "", "z1", models.CellCapacity{}, nil, nil, nil, nil)
				cellSet = models.CellSet{"cell-id": &cellPresence}
				fakeServiceClient.CellsReturns(cellSet, nil)
			})

			JustBeforeEach(func() {
				err = controller.ConvergeTasks(logger, kickTaskDuration, expirePendingTaskDuration, expireCompletedTaskDuration)
			})

			It("calls ConvergeTasks", func() {
				Expect(err).NotTo(HaveOccurred())
				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))
				Expect(actualKickDuration).To(BeEquivalentTo(kickTaskDuration))
Beispiel #5
0
var _ = Describe("Convergence API", func() {
	Describe("ConvergeLRPs", func() {
		var processGuid string

		BeforeEach(func() {
			// make the converger more aggressive by running every second
			bbsArgs.ConvergeRepeatInterval = time.Second
			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{},
				[]string{},
				[]string{},
			)
			consulHelper.RegisterCell(&cellPresence)
			processGuid = "some-process-guid"
			err := client.DesireLRP(logger, model_helpers.NewValidDesiredLRP(processGuid))
			Expect(err).NotTo(HaveOccurred())
			err = client.RemoveActualLRP(logger, processGuid, 0, nil)
			Expect(err).NotTo(HaveOccurred())
		})

		It("converges the lrps", func() {
			Eventually(func() []*models.ActualLRPGroup {
				groups, err := client.ActualLRPGroupsByProcessGuid(logger, processGuid)
				_, 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{},
						[]string{},
						[]string{},
					)
					cells["cell-id"] = &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))
				})
			})
				actualLRP.CellId = cellID
				actualLRP.ActualLRPInstanceKey = instanceKey
				actualLRPGroup.Instance.State = models.ActualLRPStateClaimed
				fakeActualLRPDB.ActualLRPGroupByProcessGuidAndIndexReturns(actualLRPGroup, nil)
			})

			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{},
							[]string{},
							[]string{},
						)

						fakeServiceClient.CellByIdReturns(&cellPresence, nil)
					})

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

						Expect(fakeServiceClient.CellByIdCallCount()).To(Equal(1))
						_, fetchedCellID := fakeServiceClient.CellByIdArgsForCall(0)
			}()

			// start convergence
			go func() {
				defer GinkgoRecover()
				logger.Info("start-lrp-convergence-loop")
				defer logger.Info("finish-lrp-convergence-loop")
				wg.Add(1)
				defer wg.Done()
				for i := 0; i < numTrials; i++ {
					sleepDuration := getSleepDuration(i, bulkCycle)
					time.Sleep(sleepDuration)
					cellSet := models.NewCellSet()
					for i := 0; i < numReps; i++ {
						cellID := fmt.Sprintf("cell-%d", i)
						presence := models.NewCellPresence(cellID, "earth", "http://planet-earth", "north", models.CellCapacity{}, nil, nil, nil, nil)
						cellSet.Add(&presence)
					}

					b.Time("BBS' internal gathering of LRPs", func() {
						activeDB.ConvergeLRPs(logger, cellSet)
					}, reporter.ReporterInfo{
						MetricName: ConvergenceGathering,
					})
				}
			}()

			// start route-emitter
			go func() {
				defer GinkgoRecover()
				logger.Info("start-route-emitter-loop")