Skip to content

Commit

Permalink
update rep to match AZ balance work in auction
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkgupta committed Jul 27, 2014
1 parent f818f5d commit 07d0d79
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
8 changes: 7 additions & 1 deletion auction_delegate/auction_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import (
)

type AuctionDelegate struct {
azNumber int
executorID string
lrpStopper lrp_stopper.LRPStopper
bbs Bbs.RepBBS
client executorapi.Client
logger lager.Logger
}

func New(executorID string, lrpStopper lrp_stopper.LRPStopper, bbs Bbs.RepBBS, client executorapi.Client, logger lager.Logger) *AuctionDelegate {
func New(azNumber int, executorID string, lrpStopper lrp_stopper.LRPStopper, bbs Bbs.RepBBS, client executorapi.Client, logger lager.Logger) *AuctionDelegate {
return &AuctionDelegate{
azNumber: azNumber,
executorID: executorID,
lrpStopper: lrpStopper,
bbs: bbs,
Expand All @@ -27,6 +29,10 @@ func New(executorID string, lrpStopper lrp_stopper.LRPStopper, bbs Bbs.RepBBS, c
}
}

func (a *AuctionDelegate) AZNumber() int {
return a.azNumber
}

func (a *AuctionDelegate) RemainingResources() (auctiontypes.Resources, error) {
resources, err := a.fetchResourcesVia(a.client.RemainingResources)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion auction_delegate/auction_delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ var _ = Describe("AuctionDelegate", func() {
var clientFetchError error
var bbs *fake_bbs.FakeRepBBS
var stopper *fake_lrp_stopper.FakeLRPStopper
var azNumber int

BeforeEach(func() {
stopper = &fake_lrp_stopper.FakeLRPStopper{}
client = new(fake_client.FakeClient)
bbs = &fake_bbs.FakeRepBBS{}
delegate = New("some-executor-id", stopper, bbs, client, lagertest.NewTestLogger("test"))
azNumber = 0
delegate = New(azNumber, "some-executor-id", stopper, bbs, client, lagertest.NewTestLogger("test"))
clientFetchError = errors.New("Failed to fetch")
})

Expand Down
3 changes: 3 additions & 0 deletions integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var executorID string
var azNumber int
var representativePath string
var etcdRunner *etcdstorerunner.ETCDClusterRunner
var natsRunner *natsrunner.NATSRunner
Expand All @@ -32,6 +33,8 @@ var _ = BeforeSuite(func() {
natsRunner = natsrunner.NewNATSRunner(4001)
etcdRunner = etcdstorerunner.NewETCDClusterRunner(etcdPort, 1)

azNumber = 0

representativePath, err = gexec.Build("github.com/cloudfoundry-incubator/rep", "-race")
Ω(err).ShouldNot(HaveOccurred())
})
Expand Down
1 change: 1 addition & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var _ = Describe("The Rep", func() {

runner = reprunner.New(
representativePath,
azNumber,
executorID,
"the-stack",
"the-lrp-host",
Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,19 @@ var executorID = flag.String(
"the ID used by the rep to identify itself to external systems - must be specified",
)

var azNumber = flag.Int(
"azNumber",
-1,
"the number of the Availability Zone or Cluster that this rep is running on",
)

func main() {
flag.Parse()

if *azNumber < 0 {
log.Fatalf("-azNumber must be specified, and non-negative")
}

if *executorID == "" {
log.Fatalf("-executorID must be specified")
}
Expand All @@ -123,7 +133,7 @@ func main() {
"task-rep": initializeTaskRep(*executorID, bbs, logger, executorClient),
"stop-lrp-listener": initializeStopLRPListener(lrpStopper, bbs, logger),
"api-server": initializeAPIServer(*executorID, bbs, logger, executorClient),
"auction-server": initializeAuctionNatsServer(*executorID, lrpStopper, bbs, executorClient, logger),
"auction-server": initializeAuctionNatsServer(*azNumber, *executorID, lrpStopper, bbs, executorClient, logger),
})
monitor := ifrit.Envoke(sigmon.New(group))

Expand Down Expand Up @@ -239,8 +249,8 @@ func initializeNatsClient(logger lager.Logger) yagnats.NATSClient {
return natsClient
}

func initializeAuctionNatsServer(executorID string, stopper lrp_stopper.LRPStopper, bbs Bbs.RepBBS, executorClient executorapi.Client, logger lager.Logger) *auction_nats_server.AuctionNATSServer {
auctionDelegate := auction_delegate.New(executorID, stopper, bbs, executorClient, logger)
func initializeAuctionNatsServer(azNumber int, executorID string, stopper lrp_stopper.LRPStopper, bbs Bbs.RepBBS, executorClient executorapi.Client, logger lager.Logger) *auction_nats_server.AuctionNATSServer {
auctionDelegate := auction_delegate.New(azNumber, executorID, stopper, bbs, executorClient, logger)
auctionRep := auctionrep.New(executorID, auctionDelegate)
natsClient := initializeNatsClient(logger)
return auction_nats_server.New(natsClient, auctionRep, logger)
Expand Down
6 changes: 5 additions & 1 deletion reprunner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reprunner

import (
"os/exec"
"strconv"
"time"

"github.com/onsi/ginkgo"
Expand All @@ -17,6 +18,7 @@ type Runner struct {
}

type Config struct {
azNumber int
stack string
executorID string
lrpHost string
Expand All @@ -28,10 +30,11 @@ type Config struct {
heartbeatInterval time.Duration
}

func New(binPath, executorID, stack, lrpHost, listenAddr, executorURL, etcdCluster, natsAddr, logLevel string, heartbeatInterval time.Duration) *Runner {
func New(binPath string, azNumber int, executorID, stack, lrpHost, listenAddr, executorURL, etcdCluster, natsAddr, logLevel string, heartbeatInterval time.Duration) *Runner {
return &Runner{
binPath: binPath,
config: Config{
azNumber: azNumber,
executorID: executorID,
stack: stack,
lrpHost: lrpHost,
Expand All @@ -53,6 +56,7 @@ func (r *Runner) Start() {
repSession, err := gexec.Start(
exec.Command(
r.binPath,
"-azNumber", strconv.Itoa(r.config.azNumber),
"-executorID", r.config.executorID,
"-stack", r.config.stack,
"-lrpHost", r.config.lrpHost,
Expand Down

0 comments on commit 07d0d79

Please sign in to comment.