Пример #1
0
func (db *serviceClient) NewBBSLockRunner(logger lager.Logger, bbsPresence *models.BBSPresence, retryInterval, lockTTL time.Duration) (ifrit.Runner, error) {
	bbsPresenceJSON, err := models.ToJSON(bbsPresence)
	if err != nil {
		return nil, err
	}
	return locket.NewLock(logger, db.consulClient, locket.LockSchemaPath("bbs_lock"), bbsPresenceJSON, db.clock, retryInterval, lockTTL), nil
}
Пример #2
0
				ghttp.RespondWith(200, `{"error":{},"desired_lrp_scheduling_infos":	[]}`),
			)

			fakeBBS.RouteToHandler("POST", "/v1/domains/upsert",
				ghttp.RespondWith(200, `{}`),
			)

			fakeBBS.RouteToHandler("POST", "/v1/desired_lrp/desire",
				ghttp.RespondWith(200, `{}`),
			)
		})

		JustBeforeEach(func() {
			process = startBulker(true)

			_, err := consulRunner.NewClient().KV().DeleteTree(locket.LockSchemaPath(bulkerLockName), nil)
			Expect(err).ToNot(HaveOccurred())
		})

		AfterEach(func() {
			ginkgomon.Interrupt(process, interruptTimeout)
		})

		It("exits with an error", func() {
			Eventually(process.Wait(), 5*domainTTL).Should(Receive(HaveOccurred()))
		})
	})

	Context("when the bulker initially does not have the lock", func() {
		var nsyncLockClaimerProcess ifrit.Process
Пример #3
0
func TPSWatcherLockSchemaPath() string {
	return locket.LockSchemaPath(TPSWatcherLockSchemaKey)
}
func RouteEmitterLockSchemaPath() string {
	return locket.LockSchemaPath(RouteEmitterLockSchemaKey)
}
Пример #5
0
func BBSLockSchemaPath() string {
	return locket.LockSchemaPath(BBSLockSchemaKey)
}
Пример #6
0
func CellSchemaPath(cellID string) string {
	return locket.LockSchemaPath(CellSchemaKey, cellID)
}
Пример #7
0
func CellSchemaRoot() string {
	return locket.LockSchemaPath(CellSchemaKey)
}
Пример #8
0
package main_test

import (
	"github.com/cloudfoundry-incubator/bbs/cmd/bbs/testrunner"
	"github.com/cloudfoundry-incubator/locket"
	"github.com/tedsuo/ifrit/ginkgomon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("MasterLock", func() {
	Context("when the bbs cannot obtain the bbs lock", func() {
		BeforeEach(func() {
			err := consulSession.AcquireLock(locket.LockSchemaPath("bbs_lock"), []byte{})
			Expect(err).NotTo(HaveOccurred())

			bbsRunner = testrunner.New(bbsBinPath, bbsArgs)
			bbsRunner.StartCheck = "bbs.lock.acquiring-lock"

			bbsProcess = ginkgomon.Invoke(bbsRunner)
		})

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

		It("is not reachable", func() {
			_, err := client.Domains()
			Expect(err).To(HaveOccurred())
Пример #9
0
import (
	"github.com/cloudfoundry-incubator/bbs/cmd/bbs/testrunner"
	"github.com/cloudfoundry-incubator/locket"
	"github.com/pivotal-golang/clock"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("MasterLock", func() {
	Context("when the bbs cannot obtain the bbs lock", func() {
		var competingBBSLockProcess ifrit.Process
		BeforeEach(func() {
			competingBBSLock := locket.NewLock(logger, consulClient, locket.LockSchemaPath("bbs_lock"), []byte{}, clock.NewClock(), locket.RetryInterval, locket.LockTTL)
			competingBBSLockProcess = ifrit.Invoke(competingBBSLock)

			bbsRunner = testrunner.New(bbsBinPath, bbsArgs)
			bbsRunner.StartCheck = "bbs.lock.acquiring-lock"

			bbsProcess = ginkgomon.Invoke(bbsRunner)
		})

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

		It("is not reachable", func() {
			_, err := client.Domains(logger)
			Expect(err).To(HaveOccurred())
Пример #10
0
func ConvergerLockSchemaPath() string {
	return locket.LockSchemaPath(ConvergerLockSchemaKey)
}
Пример #11
0
		itIsMissingDomain()

		It("exits with an error", func() {
			Eventually(process.Wait(), 2*domainTTL).Should(Receive(HaveOccurred()))
		})
	})

	Context("when the bulker initially does not have the lock", func() {
		var otherSession *consuladapter.Session

		BeforeEach(func() {
			heartbeatInterval = 1 * time.Second

			otherSession = consulRunner.NewSession("other-session")
			err := otherSession.AcquireLock(locket.LockSchemaPath(bulkerLockName), []byte("something-else"))
			Expect(err).NotTo(HaveOccurred())
		})

		JustBeforeEach(func() {
			process = startBulker(false)
		})

		AfterEach(func() {
			ginkgomon.Interrupt(process, interruptTimeout)
		})

		itIsMissingDomain()

		Context("when the lock becomes available", func() {
			BeforeEach(func() {
Пример #12
0
	})

	Context("when the auctioneer cannot acquire the lock on startup", func() {
		var task *rep.Task

		BeforeEach(func() {
			task = &rep.Task{
				TaskGuid: "task-guid",
				Domain:   "test",
				Resource: rep.Resource{
					MemoryMB: 124,
					DiskMB:   456,
					RootFs:   "some-rootfs",
				},
			}
			err := consulSession.AcquireLock(locket.LockSchemaPath("auctioneer_lock"), []byte{})
			Expect(err).NotTo(HaveOccurred())

			runner.StartCheck = "auctioneer.lock-bbs.lock.acquiring-lock"

			auctioneerProcess = ifrit.Background(runner)
		})

		It("should not advertise its presence, and should not be reachable", func() {
			Eventually(func() error {
				return auctioneerClient.RequestTaskAuctions([]*auctioneer.TaskStartRequest{
					&auctioneer.TaskStartRequest{*task},
				})
			}).Should(HaveOccurred())
		})
Пример #13
0
	Context("when the auctioneer cannot acquire the lock on startup", func() {
		var task *rep.Task
		var competingAuctioneerProcess ifrit.Process

		BeforeEach(func() {
			task = &rep.Task{
				TaskGuid: "task-guid",
				Domain:   "test",
				Resource: rep.Resource{
					MemoryMB: 124,
					DiskMB:   456,
					RootFs:   "some-rootfs",
				},
			}

			competingAuctioneerLock := locket.NewLock(logger, consulClient, locket.LockSchemaPath("auctioneer_lock"), []byte{}, clock.NewClock(), 500*time.Millisecond, 10*time.Second)
			competingAuctioneerProcess = ifrit.Invoke(competingAuctioneerLock)

			runner.StartCheck = "auctioneer.lock-bbs.lock.acquiring-lock"

			auctioneerProcess = ifrit.Background(runner)
		})

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

		It("should not advertise its presence, and should not be reachable", func() {
			Eventually(func() error {
				return auctioneerClient.RequestTaskAuctions([]*auctioneer.TaskStartRequest{
					&auctioneer.TaskStartRequest{*task},
Пример #14
0
func LockSchemaPath() string {
	return locket.LockSchemaPath(LockSchemaKey)
}
Пример #15
0
			Eventually(runner, 5*time.Second).Should(gbytes.Say("acquire-lock-succeeded"))

			consulRunner.DestroySession("converger")
		})

		It("exits with an error", func() {
			Eventually(runner, exitDuration).Should(Exit(1))
		})
	})

	Context("when the converger initially does not have the lock", func() {
		var otherSession *consuladapter.Session

		BeforeEach(func() {
			otherSession = consulRunner.NewSession("other-session")
			err := otherSession.AcquireLock(locket.LockSchemaPath("converge_lock"), []byte("something-else"))
			Expect(err).NotTo(HaveOccurred())

			startConverger()
		})

		itIsInactive()

		Describe("when the lock becomes available", func() {
			BeforeEach(func() {
				otherSession.Destroy()
				time.Sleep(convergeRepeatInterval + 10*time.Millisecond)
			})

			Describe("when a running task with a dead cell is present", func() {
				JustBeforeEach(createRunningTaskWithDeadCell)
Пример #16
0
func NysncBulkerLockSchemaPath() string {
	return locket.LockSchemaPath(NysncBulkerLockSchemaKey)
}