From a2115d457b39bbcacbc8aba3e4d5a72d4152fa34 Mon Sep 17 00:00:00 2001 From: i583051 Date: Mon, 8 Jan 2024 19:27:27 +0200 Subject: [PATCH 1/5] Fetch Scheduling info instead --- .../actual_lrp_lifecycle_controller.go | 14 +++++----- .../actual_lrp_lifecycle_controller_test.go | 23 +++++++++++----- controllers/evacuation_controller.go | 9 +++---- controllers/evacuation_controller_test.go | 27 ++++++++++++------- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/controllers/actual_lrp_lifecycle_controller.go b/controllers/actual_lrp_lifecycle_controller.go index 95644e1a..ac430021 100644 --- a/controllers/actual_lrp_lifecycle_controller.go +++ b/controllers/actual_lrp_lifecycle_controller.go @@ -204,17 +204,17 @@ func (h *ActualLRPLifecycleController) CrashActualLRP(ctx context.Context, logge return nil } - desiredLRP, err := h.desiredLRPDB.DesiredLRPByProcessGuid(ctx, logger, actualLRPKey.ProcessGuid) - if err != nil { - logger.Error("failed-fetching-desired-lrp", err) + schedInfos, err := h.desiredLRPDB.DesiredLRPSchedulingInfos(ctx, logger, models.DesiredLRPFilter{ProcessGuids: []string{actualLRPKey.ProcessGuid}}) + if err != nil || len(schedInfos) == 0 { + logger.Error("failed-fetching-desired-lrp-scheduling-info", err) return err } + lrpSchedInfo := schedInfos[0] - schedInfo := desiredLRP.DesiredLRPSchedulingInfo() - startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(&schedInfo, int(actualLRPKey.Index)) - logger.Info("start-lrp-auction-request", lager.Data{"app_guid": schedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) + startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(lrpSchedInfo, int(actualLRPKey.Index)) + logger.Info("start-lrp-auction-request", lager.Data{"app_guid": lrpSchedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) err = h.auctioneerClient.RequestLRPAuctions(logger, trace.RequestIdFromContext(ctx), []*auctioneer.LRPStartRequest{&startRequest}) - logger.Info("finished-lrp-auction-request", lager.Data{"app_guid": schedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) + logger.Info("finished-lrp-auction-request", lager.Data{"app_guid": lrpSchedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) if err != nil { logger.Error("failed-requesting-auction", err) } diff --git a/controllers/actual_lrp_lifecycle_controller_test.go b/controllers/actual_lrp_lifecycle_controller_test.go index b111168f..829860e2 100644 --- a/controllers/actual_lrp_lifecycle_controller_test.go +++ b/controllers/actual_lrp_lifecycle_controller_test.go @@ -619,7 +619,11 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { MaxPids: 100, } - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil) + schedInfo := desiredLRP.DesiredLRPSchedulingInfo() + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( + []*models.DesiredLRPSchedulingInfo{&schedInfo}, + nil, + ) }) It("responds with no error", func() { @@ -666,9 +670,10 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { err = controller.CrashActualLRP(context.WithValue(ctx, trace.RequestIdHeader, traceId), logger, &actualLRPKey, &beforeInstanceKey, errorMessage) Expect(err).NotTo(HaveOccurred()) - Expect(fakeDesiredLRPDB.DesiredLRPByProcessGuidCallCount()).To(Equal(1)) - _, _, processGuid := fakeDesiredLRPDB.DesiredLRPByProcessGuidArgsForCall(0) - Expect(processGuid).To(Equal("process-guid")) + Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfosCallCount()).To(Equal(1)) + _, _, filter := fakeDesiredLRPDB.DesiredLRPSchedulingInfosArgsForCall(0) + processGuid := filter.ProcessGuids + Expect(processGuid).To(Equal([]string{"process-guid"})) Expect(fakeAuctioneerClient.RequestLRPAuctionsCallCount()).To(Equal(1)) _, actualTraceId, startRequests := fakeAuctioneerClient.RequestLRPAuctionsArgsForCall(0) @@ -733,9 +738,9 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { }) }) - Context("when fetching the desired lrp fails", func() { + Context("when fetching the desired lrp scheduling info fails", func() { JustBeforeEach(func() { - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(nil, errors.New("error occured")) + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(nil, errors.New("error occured")) }) It("fails and does not request an auction", func() { @@ -876,7 +881,11 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { Routes: routes, } - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil) + schedInfo := desiredLRP.DesiredLRPSchedulingInfo() + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( + []*models.DesiredLRPSchedulingInfo{&schedInfo}, + nil, + ) }) It("returns the error to the caller", func() { diff --git a/controllers/evacuation_controller.go b/controllers/evacuation_controller.go index 01705017..5e55fb95 100644 --- a/controllers/evacuation_controller.go +++ b/controllers/evacuation_controller.go @@ -384,14 +384,13 @@ func (h *EvacuationController) EvacuateStoppedActualLRP(ctx context.Context, log } func (h *EvacuationController) requestAuction(ctx context.Context, logger lager.Logger, lrpKey *models.ActualLRPKey) { - desiredLRP, err := h.desiredLRPDB.DesiredLRPByProcessGuid(ctx, logger, lrpKey.ProcessGuid) - if err != nil { - logger.Error("failed-fetching-desired-lrp", err) + schedInfos, err := h.desiredLRPDB.DesiredLRPSchedulingInfos(ctx, logger, models.DesiredLRPFilter{ProcessGuids: []string{lrpKey.ProcessGuid}}) + if err != nil || len(schedInfos) == 0 { + logger.Error("failed-fetching-desired-lrp-scheduling-info", err) return } - schedInfo := desiredLRP.DesiredLRPSchedulingInfo() - startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(&schedInfo, int(lrpKey.Index)) + startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(schedInfos[0], int(lrpKey.Index)) err = h.auctioneerClient.RequestLRPAuctions(logger, trace.RequestIdFromContext(ctx), []*auctioneer.LRPStartRequest{&startRequest}) if err != nil { logger.Error("failed-requesting-auction", err) diff --git a/controllers/evacuation_controller_test.go b/controllers/evacuation_controller_test.go index 712d85ad..cf94ac02 100644 --- a/controllers/evacuation_controller_test.go +++ b/controllers/evacuation_controller_test.go @@ -231,7 +231,11 @@ var _ = Describe("Evacuation Controller", func() { BeforeEach(func() { desiredLRP = model_helpers.NewValidDesiredLRP("the-guid") - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil) + schedInfo := desiredLRP.DesiredLRPSchedulingInfo() + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( + []*models.DesiredLRPSchedulingInfo{&schedInfo}, + nil, + ) actualLRP = model_helpers.NewValidActualLRP("process-guid", 1) actualLRP.State = models.ActualLRPStateClaimed @@ -260,9 +264,10 @@ var _ = Describe("Evacuation Controller", func() { _, _, key := fakeActualLRPDB.UnclaimActualLRPArgsForCall(0) Expect(key).To(Equal(lrpKey)) - Expect(fakeDesiredLRPDB.DesiredLRPByProcessGuidCallCount()).To(Equal(1)) - _, _, guid := fakeDesiredLRPDB.DesiredLRPByProcessGuidArgsForCall(0) - Expect(guid).To(Equal("process-guid")) + Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfosCallCount()).To(Equal(1)) + _, _, filter := fakeDesiredLRPDB.DesiredLRPSchedulingInfosArgsForCall(0) + guid := filter.ProcessGuids + Expect(guid).To(Equal([]string{"process-guid"})) expectedStartRequest := auctioneer.NewLRPStartRequestFromModel(desiredLRP, int(actualLRP.Index)) Expect(fakeAuctioneerClient.RequestLRPAuctionsCallCount()).To(Equal(1)) @@ -357,9 +362,9 @@ var _ = Describe("Evacuation Controller", func() { }) }) - Context("when looking up the desired lrp to auction fails", func() { + Context("when looking up the desired lrp scheduling info to auction fails", func() { BeforeEach(func() { - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(nil, errors.New("error fetching desired lrp")) + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(nil, errors.New("error fetching desired lrp")) }) It("does not error and tells the caller to not keep the lrp container", func() { @@ -749,7 +754,11 @@ var _ = Describe("Evacuation Controller", func() { fakeActualLRPDB.UnclaimActualLRPReturns(actual, unclaimedActualLRP, nil) desiredLRP = model_helpers.NewValidDesiredLRP("the-guid") - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(desiredLRP, nil) + schedInfo := desiredLRP.DesiredLRPSchedulingInfo() + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( + []*models.DesiredLRPSchedulingInfo{&schedInfo}, + nil, + ) }) JustBeforeEach(func() { @@ -1288,9 +1297,9 @@ var _ = Describe("Evacuation Controller", func() { }) }) - Context("when fetching the desired lrp fails", func() { + Context("when fetching the desired lrp scheduling info fails", func() { BeforeEach(func() { - fakeDesiredLRPDB.DesiredLRPByProcessGuidReturns(nil, errors.New("jolly rancher beer :/")) + fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(nil, errors.New("jolly rancher beer :/")) }) It("does not return an error and keeps the container", func() { From c5a1fd1919483e72b4f9123b133d22882dfa5549 Mon Sep 17 00:00:00 2001 From: i583051 Date: Tue, 16 Jan 2024 07:25:50 +0200 Subject: [PATCH 2/5] Add DesiredLRPSchedulingInfoByProcessGuid endpoint --- client.go | 16 + cmd/bbs/desired_lrp_test.go | 81 +++- .../actual_lrp_lifecycle_controller.go | 13 +- .../actual_lrp_lifecycle_controller_test.go | 21 +- controllers/evacuation_controller.go | 6 +- controllers/evacuation_controller_test.go | 24 +- db/dbfakes/fake_db.go | 83 ++++ db/dbfakes/fake_desired_lrpdb.go | 83 ++++ db/dbfakes/fake_lrpdb.go | 83 ++++ db/desired_lrp_db.go | 2 + db/sqldb/desired_lrp_db.go | 20 + db/sqldb/desired_lrp_db_test.go | 52 +++ db/sqldb/fakesqldriver/deadlocks_test.go | 16 + fake_bbs/fake_client.go | 83 ++++ fake_bbs/fake_internal_client.go | 83 ++++ handlers/desired_lrp_handlers.go | 19 + handlers/desired_lrp_handlers_test.go | 94 +++++ handlers/handlers.go | 19 +- models/desired_lrp_requests.pb.go | 364 ++++++++++++++++-- models/desired_lrp_requests.proto | 5 + routes.go | 14 +- 21 files changed, 1087 insertions(+), 94 deletions(-) diff --git a/client.go b/client.go index a8b191ce..1d38620d 100644 --- a/client.go +++ b/client.go @@ -169,6 +169,9 @@ type ExternalDesiredLRPClient interface { // Returns all DesiredLRPSchedulingInfos that match the given DesiredLRPFilter DesiredLRPSchedulingInfos(lager.Logger, string, models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) + //Returns the DesiredLRPSchedulingInfo that matches the given process guid + DesiredLRPSchedulingInfoByProcessGuid(logger lager.Logger, traceID string, processGuid string) (*models.DesiredLRPSchedulingInfo, error) + // Returns all DesiredLRPRoutingInfos that match the given DesiredLRPFilter DesiredLRPRoutingInfos(lager.Logger, string, models.DesiredLRPFilter) ([]*models.DesiredLRP, error) @@ -627,6 +630,19 @@ func (c *client) DesiredLRPSchedulingInfos(logger lager.Logger, traceID string, return response.DesiredLrpSchedulingInfos, response.Error.ToError() } +func (c *client) DesiredLRPSchedulingInfoByProcessGuid(logger lager.Logger, traceID string, processGuid string) (*models.DesiredLRPSchedulingInfo, error) { + request := models.DesiredLRPByProcessGuidRequest{ + ProcessGuid: processGuid, + } + response := models.DesiredLRPSchedulingInfoByProcessGuidResponse{} + err := c.doRequest(logger, traceID, DesiredLRPSchedulingInfoByProcessGuid_r0, nil, nil, &request, &response) + if err != nil { + return nil, err + } + + return response.DesiredLrpSchedulingInfo, response.Error.ToError() +} + func (c *client) DesiredLRPRoutingInfos(logger lager.Logger, traceID string, filter models.DesiredLRPFilter) ([]*models.DesiredLRP, error) { request := models.DesiredLRPsRequest{ ProcessGuids: filter.ProcessGuids, diff --git a/cmd/bbs/desired_lrp_test.go b/cmd/bbs/desired_lrp_test.go index 6baa4895..774aef5a 100644 --- a/cmd/bbs/desired_lrp_test.go +++ b/cmd/bbs/desired_lrp_test.go @@ -15,10 +15,12 @@ import ( var _ = Describe("DesiredLRP API", func() { var ( - desiredLRPs map[string][]*models.DesiredLRP - schedulingInfos []*models.DesiredLRPSchedulingInfo - expectedDesiredLRPs []*models.DesiredLRP - actualDesiredLRPs []*models.DesiredLRP + desiredLRPs map[string][]*models.DesiredLRP + schedulingInfos []*models.DesiredLRPSchedulingInfo + routingInfos []*models.DesiredLRP + expectedSchedulingInfo models.DesiredLRPSchedulingInfo + expectedDesiredLRPs []*models.DesiredLRP + actualDesiredLRPs []*models.DesiredLRP filter models.DesiredLRPFilter @@ -199,6 +201,77 @@ var _ = Describe("DesiredLRP API", func() { }) }) + Describe("DesiredLRPSchedulingInfoByProcessGuid", func() { + var schedulingInfoByProcessGuid *models.DesiredLRPSchedulingInfo + + JustBeforeEach(func() { + expectedSchedulingInfo = desiredLRPs["domain-1"][0].DesiredLRPSchedulingInfo() + schedulingInfoByProcessGuid, getErr = client.DesiredLRPSchedulingInfoByProcessGuid(logger, "some-trace-id", expectedSchedulingInfo.GetProcessGuid()) + schedulingInfoByProcessGuid.ModificationTag.Epoch = "epoch" + }) + + It("responds without error", func() { + Expect(getErr).ToNot(HaveOccurred()) + }) + + It("returns the correct desired lrp scheduling info", func() { + Expect(*schedulingInfoByProcessGuid).To(Equal(expectedSchedulingInfo)) + }) + }) + + Describe("DesiredLRPRoutingInfos", func() { + JustBeforeEach(func() { + routingInfos, getErr = client.DesiredLRPRoutingInfos(logger, "some-trace-id", filter) + for _, routingInfo := range routingInfos { + routingInfo.ModificationTag.Epoch = "epoch" + } + }) + + It("responds without error", func() { + Expect(getErr).NotTo(HaveOccurred()) + }) + + It("has the correct number of responses", func() { + Expect(routingInfos).To(HaveLen(5)) + }) + + Context("when not filtering", func() { + It("returns all routing infos from the bbs", func() { + expectedRoutingInfos := []*models.DesiredLRP{} + for _, domainLRPs := range desiredLRPs { + for _, lrp := range domainLRPs { + routingInfo := lrp.DesiredLRPRoutingInfo() + expectedRoutingInfos = append(expectedRoutingInfos, &routingInfo) + } + } + Expect(routingInfos).To(ConsistOf(expectedRoutingInfos)) + }) + }) + + Context("when filtering by process guids", func() { + BeforeEach(func() { + guids := []string{ + "guid-1-for-domain-1", + "guid-2-for-domain-2", + } + + filter = models.DesiredLRPFilter{ProcessGuids: guids} + }) + + It("returns only the routing infos in the requested process guids", func() { + Expect(routingInfos).To(HaveLen(2)) + + routingInfo1 := desiredLRPs["domain-1"][1].DesiredLRPRoutingInfo() + routingInfo2 := desiredLRPs["domain-2"][2].DesiredLRPRoutingInfo() + expectedRoutingInfos := []*models.DesiredLRP{ + &routingInfo1, + &routingInfo2, + } + Expect(routingInfos).To(ConsistOf(expectedRoutingInfos)) + }) + }) + }) + Describe("DesireLRP", func() { var ( desiredLRP *models.DesiredLRP diff --git a/controllers/actual_lrp_lifecycle_controller.go b/controllers/actual_lrp_lifecycle_controller.go index ac430021..eb9ddd89 100644 --- a/controllers/actual_lrp_lifecycle_controller.go +++ b/controllers/actual_lrp_lifecycle_controller.go @@ -204,17 +204,16 @@ func (h *ActualLRPLifecycleController) CrashActualLRP(ctx context.Context, logge return nil } - schedInfos, err := h.desiredLRPDB.DesiredLRPSchedulingInfos(ctx, logger, models.DesiredLRPFilter{ProcessGuids: []string{actualLRPKey.ProcessGuid}}) - if err != nil || len(schedInfos) == 0 { - logger.Error("failed-fetching-desired-lrp-scheduling-info", err) + schedInfo, err := h.desiredLRPDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, actualLRPKey.ProcessGuid) + if err != nil { + logger.Error("failed-fetching-desired-lrp", err) return err } - lrpSchedInfo := schedInfos[0] - startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(lrpSchedInfo, int(actualLRPKey.Index)) - logger.Info("start-lrp-auction-request", lager.Data{"app_guid": lrpSchedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) + startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(schedInfo, int(actualLRPKey.Index)) + logger.Info("start-lrp-auction-request", lager.Data{"app_guid": schedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) err = h.auctioneerClient.RequestLRPAuctions(logger, trace.RequestIdFromContext(ctx), []*auctioneer.LRPStartRequest{&startRequest}) - logger.Info("finished-lrp-auction-request", lager.Data{"app_guid": lrpSchedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) + logger.Info("finished-lrp-auction-request", lager.Data{"app_guid": schedInfo.ProcessGuid, "index": int(actualLRPKey.Index)}) if err != nil { logger.Error("failed-requesting-auction", err) } diff --git a/controllers/actual_lrp_lifecycle_controller_test.go b/controllers/actual_lrp_lifecycle_controller_test.go index 829860e2..8f8c163e 100644 --- a/controllers/actual_lrp_lifecycle_controller_test.go +++ b/controllers/actual_lrp_lifecycle_controller_test.go @@ -620,10 +620,7 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { } schedInfo := desiredLRP.DesiredLRPSchedulingInfo() - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( - []*models.DesiredLRPSchedulingInfo{&schedInfo}, - nil, - ) + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(&schedInfo, nil) }) It("responds with no error", func() { @@ -670,10 +667,9 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { err = controller.CrashActualLRP(context.WithValue(ctx, trace.RequestIdHeader, traceId), logger, &actualLRPKey, &beforeInstanceKey, errorMessage) Expect(err).NotTo(HaveOccurred()) - Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfosCallCount()).To(Equal(1)) - _, _, filter := fakeDesiredLRPDB.DesiredLRPSchedulingInfosArgsForCall(0) - processGuid := filter.ProcessGuids - Expect(processGuid).To(Equal([]string{"process-guid"})) + Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidCallCount()).To(Equal(1)) + _, _, processGuid := fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidArgsForCall(0) + Expect(processGuid).To(Equal("process-guid")) Expect(fakeAuctioneerClient.RequestLRPAuctionsCallCount()).To(Equal(1)) _, actualTraceId, startRequests := fakeAuctioneerClient.RequestLRPAuctionsArgsForCall(0) @@ -738,9 +734,9 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { }) }) - Context("when fetching the desired lrp scheduling info fails", func() { + Context("when fetching the desired lrp fails", func() { JustBeforeEach(func() { - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(nil, errors.New("error occured")) + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, errors.New("error occured")) }) It("fails and does not request an auction", func() { @@ -882,10 +878,7 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() { } schedInfo := desiredLRP.DesiredLRPSchedulingInfo() - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( - []*models.DesiredLRPSchedulingInfo{&schedInfo}, - nil, - ) + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(&schedInfo, nil) }) It("returns the error to the caller", func() { diff --git a/controllers/evacuation_controller.go b/controllers/evacuation_controller.go index 5e55fb95..81f43e0b 100644 --- a/controllers/evacuation_controller.go +++ b/controllers/evacuation_controller.go @@ -384,13 +384,13 @@ func (h *EvacuationController) EvacuateStoppedActualLRP(ctx context.Context, log } func (h *EvacuationController) requestAuction(ctx context.Context, logger lager.Logger, lrpKey *models.ActualLRPKey) { - schedInfos, err := h.desiredLRPDB.DesiredLRPSchedulingInfos(ctx, logger, models.DesiredLRPFilter{ProcessGuids: []string{lrpKey.ProcessGuid}}) - if err != nil || len(schedInfos) == 0 { + schedInfo, err := h.desiredLRPDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, lrpKey.ProcessGuid) + if err != nil { logger.Error("failed-fetching-desired-lrp-scheduling-info", err) return } - startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(schedInfos[0], int(lrpKey.Index)) + startRequest := auctioneer.NewLRPStartRequestFromSchedulingInfo(schedInfo, int(lrpKey.Index)) err = h.auctioneerClient.RequestLRPAuctions(logger, trace.RequestIdFromContext(ctx), []*auctioneer.LRPStartRequest{&startRequest}) if err != nil { logger.Error("failed-requesting-auction", err) diff --git a/controllers/evacuation_controller_test.go b/controllers/evacuation_controller_test.go index cf94ac02..e5c60688 100644 --- a/controllers/evacuation_controller_test.go +++ b/controllers/evacuation_controller_test.go @@ -232,11 +232,7 @@ var _ = Describe("Evacuation Controller", func() { BeforeEach(func() { desiredLRP = model_helpers.NewValidDesiredLRP("the-guid") schedInfo := desiredLRP.DesiredLRPSchedulingInfo() - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( - []*models.DesiredLRPSchedulingInfo{&schedInfo}, - nil, - ) - + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(&schedInfo, nil) actualLRP = model_helpers.NewValidActualLRP("process-guid", 1) actualLRP.State = models.ActualLRPStateClaimed fakeActualLRPDB.ActualLRPsReturns([]*models.ActualLRP{actualLRP}, nil) @@ -264,10 +260,9 @@ var _ = Describe("Evacuation Controller", func() { _, _, key := fakeActualLRPDB.UnclaimActualLRPArgsForCall(0) Expect(key).To(Equal(lrpKey)) - Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfosCallCount()).To(Equal(1)) - _, _, filter := fakeDesiredLRPDB.DesiredLRPSchedulingInfosArgsForCall(0) - guid := filter.ProcessGuids - Expect(guid).To(Equal([]string{"process-guid"})) + Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidCallCount()).To(Equal(1)) + _, _, guid := fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidArgsForCall(0) + Expect(guid).To(Equal("process-guid")) expectedStartRequest := auctioneer.NewLRPStartRequestFromModel(desiredLRP, int(actualLRP.Index)) Expect(fakeAuctioneerClient.RequestLRPAuctionsCallCount()).To(Equal(1)) @@ -362,9 +357,9 @@ var _ = Describe("Evacuation Controller", func() { }) }) - Context("when looking up the desired lrp scheduling info to auction fails", func() { + Context("when looking up the desired lrp to auction fails", func() { BeforeEach(func() { - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(nil, errors.New("error fetching desired lrp")) + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, errors.New("error fetching desired lrp")) }) It("does not error and tells the caller to not keep the lrp container", func() { @@ -755,10 +750,7 @@ var _ = Describe("Evacuation Controller", func() { desiredLRP = model_helpers.NewValidDesiredLRP("the-guid") schedInfo := desiredLRP.DesiredLRPSchedulingInfo() - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns( - []*models.DesiredLRPSchedulingInfo{&schedInfo}, - nil, - ) + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(&schedInfo, nil) }) JustBeforeEach(func() { @@ -1299,7 +1291,7 @@ var _ = Describe("Evacuation Controller", func() { Context("when fetching the desired lrp scheduling info fails", func() { BeforeEach(func() { - fakeDesiredLRPDB.DesiredLRPSchedulingInfosReturns(nil, errors.New("jolly rancher beer :/")) + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, errors.New("jolly rancher beer :/")) }) It("does not return an error and keeps the container", func() { diff --git a/db/dbfakes/fake_db.go b/db/dbfakes/fake_db.go index dc5f9c16..f4febc8b 100644 --- a/db/dbfakes/fake_db.go +++ b/db/dbfakes/fake_db.go @@ -278,6 +278,21 @@ type FakeDB struct { result1 []*models.DesiredLRP result2 error } + DesiredLRPSchedulingInfoByProcessGuidStub func(context.Context, lager.Logger, string) (*models.DesiredLRPSchedulingInfo, error) + desiredLRPSchedulingInfoByProcessGuidMutex sync.RWMutex + desiredLRPSchedulingInfoByProcessGuidArgsForCall []struct { + arg1 context.Context + arg2 lager.Logger + arg3 string + } + desiredLRPSchedulingInfoByProcessGuidReturns struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } + desiredLRPSchedulingInfoByProcessGuidReturnsOnCall map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } DesiredLRPSchedulingInfosStub func(context.Context, lager.Logger, models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) desiredLRPSchedulingInfosMutex sync.RWMutex desiredLRPSchedulingInfosArgsForCall []struct { @@ -1770,6 +1785,72 @@ func (fake *FakeDB) DesiredLRPRoutingInfosReturnsOnCall(i int, result1 []*models }{result1, result2} } +func (fake *FakeDB) DesiredLRPSchedulingInfoByProcessGuid(arg1 context.Context, arg2 lager.Logger, arg3 string) (*models.DesiredLRPSchedulingInfo, error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + ret, specificReturn := fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall)] + fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall = append(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall, struct { + arg1 context.Context + arg2 lager.Logger + arg3 string + }{arg1, arg2, arg3}) + stub := fake.DesiredLRPSchedulingInfoByProcessGuidStub + fakeReturns := fake.desiredLRPSchedulingInfoByProcessGuidReturns + fake.recordInvocation("DesiredLRPSchedulingInfoByProcessGuid", []interface{}{arg1, arg2, arg3}) + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeDB) DesiredLRPSchedulingInfoByProcessGuidCallCount() int { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + return len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall) +} + +func (fake *FakeDB) DesiredLRPSchedulingInfoByProcessGuidCalls(stub func(context.Context, lager.Logger, string) (*models.DesiredLRPSchedulingInfo, error)) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = stub +} + +func (fake *FakeDB) DesiredLRPSchedulingInfoByProcessGuidArgsForCall(i int) (context.Context, lager.Logger, string) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + argsForCall := fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *FakeDB) DesiredLRPSchedulingInfoByProcessGuidReturns(result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + fake.desiredLRPSchedulingInfoByProcessGuidReturns = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + +func (fake *FakeDB) DesiredLRPSchedulingInfoByProcessGuidReturnsOnCall(i int, result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + if fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall == nil { + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall = make(map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }) + } + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[i] = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + func (fake *FakeDB) DesiredLRPSchedulingInfos(arg1 context.Context, arg2 lager.Logger, arg3 models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) { fake.desiredLRPSchedulingInfosMutex.Lock() ret, specificReturn := fake.desiredLRPSchedulingInfosReturnsOnCall[len(fake.desiredLRPSchedulingInfosArgsForCall)] @@ -3494,6 +3575,8 @@ func (fake *FakeDB) Invocations() map[string][][]interface{} { defer fake.desiredLRPByProcessGuidMutex.RUnlock() fake.desiredLRPRoutingInfosMutex.RLock() defer fake.desiredLRPRoutingInfosMutex.RUnlock() + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() fake.desiredLRPSchedulingInfosMutex.RLock() defer fake.desiredLRPSchedulingInfosMutex.RUnlock() fake.desiredLRPsMutex.RLock() diff --git a/db/dbfakes/fake_desired_lrpdb.go b/db/dbfakes/fake_desired_lrpdb.go index fc20c4f0..a6b9d5c5 100644 --- a/db/dbfakes/fake_desired_lrpdb.go +++ b/db/dbfakes/fake_desired_lrpdb.go @@ -54,6 +54,21 @@ type FakeDesiredLRPDB struct { result1 []*models.DesiredLRP result2 error } + DesiredLRPSchedulingInfoByProcessGuidStub func(context.Context, lager.Logger, string) (*models.DesiredLRPSchedulingInfo, error) + desiredLRPSchedulingInfoByProcessGuidMutex sync.RWMutex + desiredLRPSchedulingInfoByProcessGuidArgsForCall []struct { + arg1 context.Context + arg2 lager.Logger + arg3 string + } + desiredLRPSchedulingInfoByProcessGuidReturns struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } + desiredLRPSchedulingInfoByProcessGuidReturnsOnCall map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } DesiredLRPSchedulingInfosStub func(context.Context, lager.Logger, models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) desiredLRPSchedulingInfosMutex sync.RWMutex desiredLRPSchedulingInfosArgsForCall []struct { @@ -312,6 +327,72 @@ func (fake *FakeDesiredLRPDB) DesiredLRPRoutingInfosReturnsOnCall(i int, result1 }{result1, result2} } +func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfoByProcessGuid(arg1 context.Context, arg2 lager.Logger, arg3 string) (*models.DesiredLRPSchedulingInfo, error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + ret, specificReturn := fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall)] + fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall = append(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall, struct { + arg1 context.Context + arg2 lager.Logger + arg3 string + }{arg1, arg2, arg3}) + stub := fake.DesiredLRPSchedulingInfoByProcessGuidStub + fakeReturns := fake.desiredLRPSchedulingInfoByProcessGuidReturns + fake.recordInvocation("DesiredLRPSchedulingInfoByProcessGuid", []interface{}{arg1, arg2, arg3}) + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfoByProcessGuidCallCount() int { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + return len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall) +} + +func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfoByProcessGuidCalls(stub func(context.Context, lager.Logger, string) (*models.DesiredLRPSchedulingInfo, error)) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = stub +} + +func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfoByProcessGuidArgsForCall(i int) (context.Context, lager.Logger, string) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + argsForCall := fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfoByProcessGuidReturns(result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + fake.desiredLRPSchedulingInfoByProcessGuidReturns = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + +func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfoByProcessGuidReturnsOnCall(i int, result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + if fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall == nil { + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall = make(map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }) + } + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[i] = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + func (fake *FakeDesiredLRPDB) DesiredLRPSchedulingInfos(arg1 context.Context, arg2 lager.Logger, arg3 models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) { fake.desiredLRPSchedulingInfosMutex.Lock() ret, specificReturn := fake.desiredLRPSchedulingInfosReturnsOnCall[len(fake.desiredLRPSchedulingInfosArgsForCall)] @@ -583,6 +664,8 @@ func (fake *FakeDesiredLRPDB) Invocations() map[string][][]interface{} { defer fake.desiredLRPByProcessGuidMutex.RUnlock() fake.desiredLRPRoutingInfosMutex.RLock() defer fake.desiredLRPRoutingInfosMutex.RUnlock() + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() fake.desiredLRPSchedulingInfosMutex.RLock() defer fake.desiredLRPSchedulingInfosMutex.RUnlock() fake.desiredLRPsMutex.RLock() diff --git a/db/dbfakes/fake_lrpdb.go b/db/dbfakes/fake_lrpdb.go index b9a1c5a6..ff85cdbd 100644 --- a/db/dbfakes/fake_lrpdb.go +++ b/db/dbfakes/fake_lrpdb.go @@ -188,6 +188,21 @@ type FakeLRPDB struct { result1 []*models.DesiredLRP result2 error } + DesiredLRPSchedulingInfoByProcessGuidStub func(context.Context, lager.Logger, string) (*models.DesiredLRPSchedulingInfo, error) + desiredLRPSchedulingInfoByProcessGuidMutex sync.RWMutex + desiredLRPSchedulingInfoByProcessGuidArgsForCall []struct { + arg1 context.Context + arg2 lager.Logger + arg3 string + } + desiredLRPSchedulingInfoByProcessGuidReturns struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } + desiredLRPSchedulingInfoByProcessGuidReturnsOnCall map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } DesiredLRPSchedulingInfosStub func(context.Context, lager.Logger, models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) desiredLRPSchedulingInfosMutex sync.RWMutex desiredLRPSchedulingInfosArgsForCall []struct { @@ -1066,6 +1081,72 @@ func (fake *FakeLRPDB) DesiredLRPRoutingInfosReturnsOnCall(i int, result1 []*mod }{result1, result2} } +func (fake *FakeLRPDB) DesiredLRPSchedulingInfoByProcessGuid(arg1 context.Context, arg2 lager.Logger, arg3 string) (*models.DesiredLRPSchedulingInfo, error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + ret, specificReturn := fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall)] + fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall = append(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall, struct { + arg1 context.Context + arg2 lager.Logger + arg3 string + }{arg1, arg2, arg3}) + stub := fake.DesiredLRPSchedulingInfoByProcessGuidStub + fakeReturns := fake.desiredLRPSchedulingInfoByProcessGuidReturns + fake.recordInvocation("DesiredLRPSchedulingInfoByProcessGuid", []interface{}{arg1, arg2, arg3}) + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeLRPDB) DesiredLRPSchedulingInfoByProcessGuidCallCount() int { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + return len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall) +} + +func (fake *FakeLRPDB) DesiredLRPSchedulingInfoByProcessGuidCalls(stub func(context.Context, lager.Logger, string) (*models.DesiredLRPSchedulingInfo, error)) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = stub +} + +func (fake *FakeLRPDB) DesiredLRPSchedulingInfoByProcessGuidArgsForCall(i int) (context.Context, lager.Logger, string) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + argsForCall := fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *FakeLRPDB) DesiredLRPSchedulingInfoByProcessGuidReturns(result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + fake.desiredLRPSchedulingInfoByProcessGuidReturns = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + +func (fake *FakeLRPDB) DesiredLRPSchedulingInfoByProcessGuidReturnsOnCall(i int, result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + if fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall == nil { + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall = make(map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }) + } + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[i] = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + func (fake *FakeLRPDB) DesiredLRPSchedulingInfos(arg1 context.Context, arg2 lager.Logger, arg3 models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) { fake.desiredLRPSchedulingInfosMutex.Lock() ret, specificReturn := fake.desiredLRPSchedulingInfosReturnsOnCall[len(fake.desiredLRPSchedulingInfosArgsForCall)] @@ -1637,6 +1718,8 @@ func (fake *FakeLRPDB) Invocations() map[string][][]interface{} { defer fake.desiredLRPByProcessGuidMutex.RUnlock() fake.desiredLRPRoutingInfosMutex.RLock() defer fake.desiredLRPRoutingInfosMutex.RUnlock() + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() fake.desiredLRPSchedulingInfosMutex.RLock() defer fake.desiredLRPSchedulingInfosMutex.RUnlock() fake.desiredLRPsMutex.RLock() diff --git a/db/desired_lrp_db.go b/db/desired_lrp_db.go index 2260b389..878a44de 100644 --- a/db/desired_lrp_db.go +++ b/db/desired_lrp_db.go @@ -14,6 +14,8 @@ type DesiredLRPDB interface { DesiredLRPByProcessGuid(ctx context.Context, logger lager.Logger, processGuid string) (*models.DesiredLRP, error) DesiredLRPSchedulingInfos(ctx context.Context, logger lager.Logger, filter models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) + DesiredLRPSchedulingInfoByProcessGuid(ctx context.Context, logger lager.Logger, processGuid string) (*models.DesiredLRPSchedulingInfo, error) + DesiredLRPRoutingInfos(ctx context.Context, logger lager.Logger, filter models.DesiredLRPFilter) ([]*models.DesiredLRP, error) DesireLRP(ctx context.Context, logger lager.Logger, desiredLRP *models.DesiredLRP) error diff --git a/db/sqldb/desired_lrp_db.go b/db/sqldb/desired_lrp_db.go index c06d3513..c9d2388d 100644 --- a/db/sqldb/desired_lrp_db.go +++ b/db/sqldb/desired_lrp_db.go @@ -205,6 +205,26 @@ func (db *SQLDB) DesiredLRPSchedulingInfos(ctx context.Context, logger lager.Log return results, err } +func (db *SQLDB) DesiredLRPSchedulingInfoByProcessGuid(ctx context.Context, logger lager.Logger, processGuid string) (*models.DesiredLRPSchedulingInfo, error) { + logger = logger.Session("db-desired-lrp-scheduling-info-by-process-guid", lager.Data{"process_guid": processGuid}) + logger.Debug("starting") + defer logger.Debug("complete") + + var desiredLRPSchedulingInfo *models.DesiredLRPSchedulingInfo + err := db.transact(ctx, logger, func(logger lager.Logger, tx helpers.Tx) error { + var err error + row := db.one(ctx, logger, tx, desiredLRPsTable, + schedulingInfoColumns, helpers.NoLockRow, + "process_guid = ?", processGuid, + ) + + desiredLRPSchedulingInfo, err = db.fetchDesiredLRPSchedulingInfo(logger, row) + return err + }) + + return desiredLRPSchedulingInfo, err +} + func (db *SQLDB) DesiredLRPRoutingInfos(ctx context.Context, logger lager.Logger, filter models.DesiredLRPFilter) ([]*models.DesiredLRP, error) { logger = logger.Session("db-desired-lrps-routing-infos", lager.Data{"filter": filter}) logger.Debug("starting") diff --git a/db/sqldb/desired_lrp_db_test.go b/db/sqldb/desired_lrp_db_test.go index 5a1b3fcd..5f5a975d 100644 --- a/db/sqldb/desired_lrp_db_test.go +++ b/db/sqldb/desired_lrp_db_test.go @@ -329,6 +329,58 @@ var _ = Describe("DesiredLRPDB", func() { }) }) + Describe("DesiredLRPSchedulingInfoByProcessGuid", func() { + var expectedDesiredLRPSchedulingInfo models.DesiredLRPSchedulingInfo + + BeforeEach(func() { + desiredLRPGuid := "desired-lrp-guid" + desiredLRP := model_helpers.NewValidDesiredLRP(desiredLRPGuid) + Expect(sqlDB.DesireLRP(ctx, logger, desiredLRP)).To(Succeed()) + expectedDesiredLRPSchedulingInfo = desiredLRP.DesiredLRPSchedulingInfo() + }) + + It("Returns the desired-lrp", func() { + schedInfo, err := sqlDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, expectedDesiredLRPSchedulingInfo.ProcessGuid) + + Expect(err).NotTo(HaveOccurred()) + Expect(*schedInfo).To(BeEquivalentTo(expectedDesiredLRPSchedulingInfo)) + }) + + Context("when the desired lrp does not exist", func() { + It("does not log an error", func() { + sqlDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, "I am Batman") + Expect(logger.Errors).To(BeEmpty()) + }) + + It("returns a ResourceNotFound error", func() { + schedInfo, err := sqlDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, "I am Batman") + Expect(err).To(Equal(models.ErrResourceNotFound)) + Expect(schedInfo).To(BeNil()) + }) + }) + + Context("when the routes are invalid", func() { + BeforeEach(func() { + queryStr := "UPDATE desired_lrps SET routes = ? WHERE process_guid = ?" + if test_helpers.UsePostgres() { + queryStr = test_helpers.ReplaceQuestionMarks(queryStr) + } + + result, err := db.ExecContext(ctx, queryStr, "{{", expectedDesiredLRPSchedulingInfo.ProcessGuid) + Expect(err).NotTo(HaveOccurred()) + rowsAffected, err := result.RowsAffected() + Expect(err).NotTo(HaveOccurred()) + Expect(rowsAffected).To(BeEquivalentTo(1)) + }) + + It("returns an invalid record error", func() { + schedInfo, err := sqlDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, expectedDesiredLRPSchedulingInfo.ProcessGuid) + Expect(err).To(HaveOccurred()) + Expect(schedInfo).To(BeNil()) + }) + }) + }) + Describe("DesiredLRPRoutingInfos", func() { var expectedDesiredLRPRoutingInfos []*models.DesiredLRP var expectedDesiredLRPs []*models.DesiredLRP diff --git a/db/sqldb/fakesqldriver/deadlocks_test.go b/db/sqldb/fakesqldriver/deadlocks_test.go index dfb1f04b..6c905f1d 100644 --- a/db/sqldb/fakesqldriver/deadlocks_test.go +++ b/db/sqldb/fakesqldriver/deadlocks_test.go @@ -159,6 +159,22 @@ var _ = Describe("Deadlocks", func() { }) }) + Context("DesiredLRPSchedulingInfoByProcessGuid", func() { + It("retries on deadlocks", func() { + _, err := sqlDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, "") + Expect(err).To(HaveOccurred()) + Expect(fakeConn.BeginCallCount()).To(Equal(3)) + }) + }) + + Context("DesiredLRPRoutingInfo", func() { + It("retries on deadlocks", func() { + _, err := sqlDB.DesiredLRPRoutingInfos(ctx, logger, models.DesiredLRPFilter{}) + Expect(err).To(HaveOccurred()) + Expect(fakeConn.BeginCallCount()).To(Equal(3)) + }) + }) + Context("DesiredLRPs", func() { It("retries on deadlocks", func() { _, err := sqlDB.DesiredLRPs(ctx, logger, models.DesiredLRPFilter{}) diff --git a/fake_bbs/fake_client.go b/fake_bbs/fake_client.go index 2bb85946..cd43ebaf 100644 --- a/fake_bbs/fake_client.go +++ b/fake_bbs/fake_client.go @@ -171,6 +171,21 @@ type FakeClient struct { result1 []*models.DesiredLRP result2 error } + DesiredLRPSchedulingInfoByProcessGuidStub func(lager.Logger, string, string) (*models.DesiredLRPSchedulingInfo, error) + desiredLRPSchedulingInfoByProcessGuidMutex sync.RWMutex + desiredLRPSchedulingInfoByProcessGuidArgsForCall []struct { + arg1 lager.Logger + arg2 string + arg3 string + } + desiredLRPSchedulingInfoByProcessGuidReturns struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } + desiredLRPSchedulingInfoByProcessGuidReturnsOnCall map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } DesiredLRPSchedulingInfosStub func(lager.Logger, string, models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) desiredLRPSchedulingInfosMutex sync.RWMutex desiredLRPSchedulingInfosArgsForCall []struct { @@ -1155,6 +1170,72 @@ func (fake *FakeClient) DesiredLRPRoutingInfosReturnsOnCall(i int, result1 []*mo }{result1, result2} } +func (fake *FakeClient) DesiredLRPSchedulingInfoByProcessGuid(arg1 lager.Logger, arg2 string, arg3 string) (*models.DesiredLRPSchedulingInfo, error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + ret, specificReturn := fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall)] + fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall = append(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall, struct { + arg1 lager.Logger + arg2 string + arg3 string + }{arg1, arg2, arg3}) + stub := fake.DesiredLRPSchedulingInfoByProcessGuidStub + fakeReturns := fake.desiredLRPSchedulingInfoByProcessGuidReturns + fake.recordInvocation("DesiredLRPSchedulingInfoByProcessGuid", []interface{}{arg1, arg2, arg3}) + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeClient) DesiredLRPSchedulingInfoByProcessGuidCallCount() int { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + return len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall) +} + +func (fake *FakeClient) DesiredLRPSchedulingInfoByProcessGuidCalls(stub func(lager.Logger, string, string) (*models.DesiredLRPSchedulingInfo, error)) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = stub +} + +func (fake *FakeClient) DesiredLRPSchedulingInfoByProcessGuidArgsForCall(i int) (lager.Logger, string, string) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + argsForCall := fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *FakeClient) DesiredLRPSchedulingInfoByProcessGuidReturns(result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + fake.desiredLRPSchedulingInfoByProcessGuidReturns = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + +func (fake *FakeClient) DesiredLRPSchedulingInfoByProcessGuidReturnsOnCall(i int, result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + if fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall == nil { + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall = make(map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }) + } + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[i] = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + func (fake *FakeClient) DesiredLRPSchedulingInfos(arg1 lager.Logger, arg2 string, arg3 models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) { fake.desiredLRPSchedulingInfosMutex.Lock() ret, specificReturn := fake.desiredLRPSchedulingInfosReturnsOnCall[len(fake.desiredLRPSchedulingInfosArgsForCall)] @@ -2407,6 +2488,8 @@ func (fake *FakeClient) Invocations() map[string][][]interface{} { defer fake.desiredLRPByProcessGuidMutex.RUnlock() fake.desiredLRPRoutingInfosMutex.RLock() defer fake.desiredLRPRoutingInfosMutex.RUnlock() + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() fake.desiredLRPSchedulingInfosMutex.RLock() defer fake.desiredLRPSchedulingInfosMutex.RUnlock() fake.desiredLRPsMutex.RLock() diff --git a/fake_bbs/fake_internal_client.go b/fake_bbs/fake_internal_client.go index 1c27f324..0e84d75f 100644 --- a/fake_bbs/fake_internal_client.go +++ b/fake_bbs/fake_internal_client.go @@ -217,6 +217,21 @@ type FakeInternalClient struct { result1 []*models.DesiredLRP result2 error } + DesiredLRPSchedulingInfoByProcessGuidStub func(lager.Logger, string, string) (*models.DesiredLRPSchedulingInfo, error) + desiredLRPSchedulingInfoByProcessGuidMutex sync.RWMutex + desiredLRPSchedulingInfoByProcessGuidArgsForCall []struct { + arg1 lager.Logger + arg2 string + arg3 string + } + desiredLRPSchedulingInfoByProcessGuidReturns struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } + desiredLRPSchedulingInfoByProcessGuidReturnsOnCall map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + } DesiredLRPSchedulingInfosStub func(lager.Logger, string, models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) desiredLRPSchedulingInfosMutex sync.RWMutex desiredLRPSchedulingInfosArgsForCall []struct { @@ -1572,6 +1587,72 @@ func (fake *FakeInternalClient) DesiredLRPRoutingInfosReturnsOnCall(i int, resul }{result1, result2} } +func (fake *FakeInternalClient) DesiredLRPSchedulingInfoByProcessGuid(arg1 lager.Logger, arg2 string, arg3 string) (*models.DesiredLRPSchedulingInfo, error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + ret, specificReturn := fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall)] + fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall = append(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall, struct { + arg1 lager.Logger + arg2 string + arg3 string + }{arg1, arg2, arg3}) + stub := fake.DesiredLRPSchedulingInfoByProcessGuidStub + fakeReturns := fake.desiredLRPSchedulingInfoByProcessGuidReturns + fake.recordInvocation("DesiredLRPSchedulingInfoByProcessGuid", []interface{}{arg1, arg2, arg3}) + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeInternalClient) DesiredLRPSchedulingInfoByProcessGuidCallCount() int { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + return len(fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall) +} + +func (fake *FakeInternalClient) DesiredLRPSchedulingInfoByProcessGuidCalls(stub func(lager.Logger, string, string) (*models.DesiredLRPSchedulingInfo, error)) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = stub +} + +func (fake *FakeInternalClient) DesiredLRPSchedulingInfoByProcessGuidArgsForCall(i int) (lager.Logger, string, string) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() + argsForCall := fake.desiredLRPSchedulingInfoByProcessGuidArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *FakeInternalClient) DesiredLRPSchedulingInfoByProcessGuidReturns(result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + fake.desiredLRPSchedulingInfoByProcessGuidReturns = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + +func (fake *FakeInternalClient) DesiredLRPSchedulingInfoByProcessGuidReturnsOnCall(i int, result1 *models.DesiredLRPSchedulingInfo, result2 error) { + fake.desiredLRPSchedulingInfoByProcessGuidMutex.Lock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.Unlock() + fake.DesiredLRPSchedulingInfoByProcessGuidStub = nil + if fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall == nil { + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall = make(map[int]struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }) + } + fake.desiredLRPSchedulingInfoByProcessGuidReturnsOnCall[i] = struct { + result1 *models.DesiredLRPSchedulingInfo + result2 error + }{result1, result2} +} + func (fake *FakeInternalClient) DesiredLRPSchedulingInfos(arg1 lager.Logger, arg2 string, arg3 models.DesiredLRPFilter) ([]*models.DesiredLRPSchedulingInfo, error) { fake.desiredLRPSchedulingInfosMutex.Lock() ret, specificReturn := fake.desiredLRPSchedulingInfosReturnsOnCall[len(fake.desiredLRPSchedulingInfosArgsForCall)] @@ -3570,6 +3651,8 @@ func (fake *FakeInternalClient) Invocations() map[string][][]interface{} { defer fake.desiredLRPByProcessGuidMutex.RUnlock() fake.desiredLRPRoutingInfosMutex.RLock() defer fake.desiredLRPRoutingInfosMutex.RUnlock() + fake.desiredLRPSchedulingInfoByProcessGuidMutex.RLock() + defer fake.desiredLRPSchedulingInfoByProcessGuidMutex.RUnlock() fake.desiredLRPSchedulingInfosMutex.RLock() defer fake.desiredLRPSchedulingInfosMutex.RUnlock() fake.desiredLRPsMutex.RLock() diff --git a/handlers/desired_lrp_handlers.go b/handlers/desired_lrp_handlers.go index e42ca792..214cb5c9 100644 --- a/handlers/desired_lrp_handlers.go +++ b/handlers/desired_lrp_handlers.go @@ -148,6 +148,25 @@ func (h *DesiredLRPHandler) DesiredLRPSchedulingInfos(logger lager.Logger, w htt exitIfUnrecoverable(logger, h.exitChan, response.Error) } +func (h *DesiredLRPHandler) DesiredLRPSchedulingInfoByProcessGuid(logger lager.Logger, w http.ResponseWriter, req *http.Request) { + var err error + logger = logger.Session("desired-lrp-scheduling-info-by-process-guid").WithTraceInfo(req) + logger.Debug("starting") + defer logger.Debug("complete") + + request := &models.DesiredLRPByProcessGuidRequest{} + response := &models.DesiredLRPSchedulingInfoByProcessGuidResponse{} + + err = parseRequest(logger, req, request) + if err == nil { + response.DesiredLrpSchedulingInfo, err = h.desiredLRPDB.DesiredLRPSchedulingInfoByProcessGuid(req.Context(), logger, request.ProcessGuid) + } + + response.Error = models.ConvertError(err) + writeResponse(w, response) + exitIfUnrecoverable(logger, h.exitChan, response.Error) +} + func (h *DesiredLRPHandler) DesiredLRPRoutingInfos(logger lager.Logger, w http.ResponseWriter, req *http.Request) { var err error logger = logger.Session("desired-lrp-routing-infos") diff --git a/handlers/desired_lrp_handlers_test.go b/handlers/desired_lrp_handlers_test.go index 56ad4cd1..4cf79d58 100644 --- a/handlers/desired_lrp_handlers_test.go +++ b/handlers/desired_lrp_handlers_test.go @@ -742,6 +742,100 @@ var _ = Describe("DesiredLRP Handlers", func() { }) }) + Describe("DesiredLRPSchedulingInfoByProcessGuid", func() { + var ( + processGuid = "process-guid" + + requestBody interface{} + ) + + BeforeEach(func() { + requestBody = &models.DesiredLRPByProcessGuidRequest{ + ProcessGuid: processGuid, + } + }) + + JustBeforeEach(func() { + request := newTestRequest(requestBody) + request.Header.Set(lager.RequestIdHeader, requestIdHeader) + handler.DesiredLRPSchedulingInfoByProcessGuid(logger, responseRecorder, request) + }) + + Context("when reading the desired lrp scheduling info from the DB succeeds", func() { + var schedInfo models.DesiredLRPSchedulingInfo + BeforeEach(func() { + desiredLRP := &models.DesiredLRP{ + ProcessGuid: "some-guid", + VolumeMounts: []*models.VolumeMount{ + &models.VolumeMount{ + Driver: "some=driver", + }, + }, + } + + schedInfo = desiredLRP.DesiredLRPSchedulingInfo() + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(&schedInfo, nil) + }) + + It("fetches the desired lrp scheduling info by process guid", func() { + Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidCallCount()).To(Equal(1)) + _, _, process_guid := fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidArgsForCall(0) + Expect(process_guid).To(Equal(processGuid)) + + Expect(responseRecorder.Code).To(Equal(http.StatusOK)) + response := models.DesiredLRPSchedulingInfoByProcessGuidResponse{} + err := response.Unmarshal(responseRecorder.Body.Bytes()) + Expect(err).ToNot(HaveOccurred()) + + Expect(response.Error).To(BeNil()) + responseSchedInfo := response.DesiredLrpSchedulingInfo + Expect(*responseSchedInfo).To(DeepEqual(schedInfo)) + }) + }) + + Context("when the DB returns no desired lrp scheduling info", func() { + BeforeEach(func() { + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, models.ErrResourceNotFound) + }) + + It("returns a resource not found error", func() { + Expect(responseRecorder.Code).To(Equal(http.StatusOK)) + response := models.DesiredLRPSchedulingInfoByProcessGuidResponse{} + err := response.Unmarshal(responseRecorder.Body.Bytes()) + Expect(err).ToNot(HaveOccurred()) + + Expect(response.Error).To(Equal(models.ErrResourceNotFound)) + }) + }) + + Context("when the DB returns an unrecoverable error", func() { + BeforeEach(func() { + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, models.NewUnrecoverableError(nil)) + }) + + It("logs and writes to exit channels", func() { + Eventually(logger).Should(gbytes.Say("unrecoverable-error")) + Eventually(logger).Should(gbytes.Say(b3RequestIdHeader)) + Eventually(exitCh).Should(Receive()) + }) + }) + + Context("when the DB errros out", func() { + BeforeEach(func() { + fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, models.ErrUnknownError) + }) + + It("provides relevant error information", func() { + Expect(responseRecorder.Code).To(Equal(http.StatusOK)) + response := models.DesiredLRPSchedulingInfoByProcessGuidResponse{} + err := response.Unmarshal(responseRecorder.Body.Bytes()) + Expect(err).NotTo(HaveOccurred()) + + Expect(response.Error).To(Equal(models.ErrUnknownError)) + }) + }) + }) + Describe("DesiredLRPRoutingInfos", func() { var ( requestBody interface{} diff --git a/handlers/handlers.go b/handlers/handlers.go index ea3ecd22..8442585e 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -97,15 +97,16 @@ func New( bbs.EvacuateRunningActualLRPRoute_r1: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, evacuationHandler.EvacuateRunningActualLRP), emitter)), // Desired LRPs - bbs.DesiredLRPsRoute_r3: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs), emitter)), - bbs.DesiredLRPByProcessGuidRoute_r3: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid), emitter)), - bbs.DesiredLRPsRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs_r2), emitter)), // DEPRECATED - bbs.DesiredLRPByProcessGuidRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid_r2), emitter)), // DEPRECATED - bbs.DesiredLRPSchedulingInfosRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPSchedulingInfos), emitter)), - bbs.DesiredLRPRoutingInfosRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPRoutingInfos), emitter)), - bbs.DesireDesiredLRPRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesireDesiredLRP), emitter)), - bbs.UpdateDesiredLRPRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.UpdateDesiredLRP), emitter)), - bbs.RemoveDesiredLRPRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.RemoveDesiredLRP), emitter)), + bbs.DesiredLRPsRoute_r3: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs), emitter)), + bbs.DesiredLRPByProcessGuidRoute_r3: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid), emitter)), + bbs.DesiredLRPsRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs_r2), emitter)), // DEPRECATED + bbs.DesiredLRPByProcessGuidRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid_r2), emitter)), // DEPRECATED + bbs.DesiredLRPSchedulingInfosRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPSchedulingInfos), emitter)), + bbs.DesiredLRPSchedulingInfoByProcessGuid_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPSchedulingInfoByProcessGuid), emitter)), + bbs.DesiredLRPRoutingInfosRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPRoutingInfos), emitter)), + bbs.DesireDesiredLRPRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesireDesiredLRP), emitter)), + bbs.UpdateDesiredLRPRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.UpdateDesiredLRP), emitter)), + bbs.RemoveDesiredLRPRoute_r0: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.RemoveDesiredLRP), emitter)), // Tasks bbs.TasksRoute_r2: route(middleware.RecordLatency(middleware.LogWrap(logger, accessLogger, taskHandler.Tasks_r2), emitter)), // DEPRECATED diff --git a/models/desired_lrp_requests.pb.go b/models/desired_lrp_requests.pb.go index 56e34cdd..703679ff 100644 --- a/models/desired_lrp_requests.pb.go +++ b/models/desired_lrp_requests.pb.go @@ -272,6 +272,59 @@ func (m *DesiredLRPSchedulingInfosResponse) GetDesiredLrpSchedulingInfos() []*De return nil } +type DesiredLRPSchedulingInfoByProcessGuidResponse struct { + Error *Error `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` + DesiredLrpSchedulingInfo *DesiredLRPSchedulingInfo `protobuf:"bytes,2,opt,name=desired_lrp_scheduling_info,json=desiredLrpSchedulingInfo,proto3" json:"desired_lrp_scheduling_info,omitempty"` +} + +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) Reset() { + *m = DesiredLRPSchedulingInfoByProcessGuidResponse{} +} +func (*DesiredLRPSchedulingInfoByProcessGuidResponse) ProtoMessage() {} +func (*DesiredLRPSchedulingInfoByProcessGuidResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7235cc1a84e38c85, []int{5} +} +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DesiredLRPSchedulingInfoByProcessGuidResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DesiredLRPSchedulingInfoByProcessGuidResponse.Merge(m, src) +} +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) XXX_Size() int { + return m.Size() +} +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DesiredLRPSchedulingInfoByProcessGuidResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DesiredLRPSchedulingInfoByProcessGuidResponse proto.InternalMessageInfo + +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) GetError() *Error { + if m != nil { + return m.Error + } + return nil +} + +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) GetDesiredLrpSchedulingInfo() *DesiredLRPSchedulingInfo { + if m != nil { + return m.DesiredLrpSchedulingInfo + } + return nil +} + type DesiredLRPByProcessGuidRequest struct { ProcessGuid string `protobuf:"bytes,1,opt,name=process_guid,json=processGuid,proto3" json:"process_guid"` } @@ -279,7 +332,7 @@ type DesiredLRPByProcessGuidRequest struct { func (m *DesiredLRPByProcessGuidRequest) Reset() { *m = DesiredLRPByProcessGuidRequest{} } func (*DesiredLRPByProcessGuidRequest) ProtoMessage() {} func (*DesiredLRPByProcessGuidRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7235cc1a84e38c85, []int{5} + return fileDescriptor_7235cc1a84e38c85, []int{6} } func (m *DesiredLRPByProcessGuidRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -322,7 +375,7 @@ type DesireLRPRequest struct { func (m *DesireLRPRequest) Reset() { *m = DesireLRPRequest{} } func (*DesireLRPRequest) ProtoMessage() {} func (*DesireLRPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7235cc1a84e38c85, []int{6} + return fileDescriptor_7235cc1a84e38c85, []int{7} } func (m *DesireLRPRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -366,7 +419,7 @@ type UpdateDesiredLRPRequest struct { func (m *UpdateDesiredLRPRequest) Reset() { *m = UpdateDesiredLRPRequest{} } func (*UpdateDesiredLRPRequest) ProtoMessage() {} func (*UpdateDesiredLRPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7235cc1a84e38c85, []int{7} + return fileDescriptor_7235cc1a84e38c85, []int{8} } func (m *UpdateDesiredLRPRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -416,7 +469,7 @@ type RemoveDesiredLRPRequest struct { func (m *RemoveDesiredLRPRequest) Reset() { *m = RemoveDesiredLRPRequest{} } func (*RemoveDesiredLRPRequest) ProtoMessage() {} func (*RemoveDesiredLRPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7235cc1a84e38c85, []int{8} + return fileDescriptor_7235cc1a84e38c85, []int{9} } func (m *RemoveDesiredLRPRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -458,6 +511,7 @@ func init() { proto.RegisterType((*DesiredLRPsRequest)(nil), "models.DesiredLRPsRequest") proto.RegisterType((*DesiredLRPResponse)(nil), "models.DesiredLRPResponse") proto.RegisterType((*DesiredLRPSchedulingInfosResponse)(nil), "models.DesiredLRPSchedulingInfosResponse") + proto.RegisterType((*DesiredLRPSchedulingInfoByProcessGuidResponse)(nil), "models.DesiredLRPSchedulingInfoByProcessGuidResponse") proto.RegisterType((*DesiredLRPByProcessGuidRequest)(nil), "models.DesiredLRPByProcessGuidRequest") proto.RegisterType((*DesireLRPRequest)(nil), "models.DesireLRPRequest") proto.RegisterType((*UpdateDesiredLRPRequest)(nil), "models.UpdateDesiredLRPRequest") @@ -467,37 +521,38 @@ func init() { func init() { proto.RegisterFile("desired_lrp_requests.proto", fileDescriptor_7235cc1a84e38c85) } var fileDescriptor_7235cc1a84e38c85 = []byte{ - // 467 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0xc1, 0x6e, 0xd3, 0x30, - 0x18, 0x8e, 0x87, 0xa8, 0xb4, 0x3f, 0x9d, 0x34, 0xcc, 0x61, 0xa5, 0x20, 0xaf, 0x78, 0x97, 0x5d, - 0xe8, 0xd0, 0x0a, 0x2f, 0x50, 0x81, 0x26, 0xa4, 0x0a, 0x4d, 0x46, 0x3b, 0xa2, 0xaa, 0x4d, 0xdc, - 0x2c, 0x52, 0x12, 0x67, 0x76, 0x82, 0xb4, 0xdb, 0x1e, 0x81, 0xc7, 0x40, 0xe2, 0x45, 0x38, 0xf6, - 0xb8, 0xd3, 0x44, 0xd3, 0x0b, 0xda, 0x69, 0x8f, 0x80, 0x6a, 0xbb, 0xc4, 0x61, 0x1c, 0x28, 0xe2, - 0x94, 0xf8, 0xf3, 0xf7, 0x7f, 0xff, 0xf7, 0x7f, 0x7f, 0x02, 0xdd, 0x90, 0xab, 0x58, 0xf2, 0x70, - 0x9c, 0xc8, 0x7c, 0x2c, 0xf9, 0x45, 0xc9, 0x55, 0xa1, 0xfa, 0xb9, 0x14, 0x85, 0xc0, 0xad, 0x54, - 0x84, 0x3c, 0x51, 0xdd, 0x17, 0x51, 0x5c, 0x9c, 0x97, 0xd3, 0x7e, 0x20, 0xd2, 0xa3, 0x48, 0x44, - 0xe2, 0x48, 0x5f, 0x4f, 0xcb, 0x99, 0x3e, 0xe9, 0x83, 0x7e, 0x33, 0x65, 0xdd, 0x47, 0x8e, 0xa4, - 0x85, 0x7c, 0x2e, 0xa5, 0x90, 0xe6, 0x40, 0x87, 0xf0, 0xf4, 0x8d, 0x61, 0x8c, 0xd8, 0xe9, 0x28, - 0x9e, 0xf1, 0xe0, 0x32, 0x48, 0x38, 0xe3, 0x2a, 0x17, 0x99, 0xe2, 0xf8, 0x00, 0x1e, 0x6a, 0x76, - 0x07, 0xf5, 0xd0, 0xa1, 0x7f, 0xbc, 0xd3, 0x37, 0x2e, 0xfa, 0x6f, 0x57, 0x20, 0x33, 0x77, 0xf4, - 0x02, 0x1e, 0xd7, 0x1a, 0x6a, 0xa3, 0x5a, 0xfc, 0x1a, 0xda, 0x8e, 0x43, 0xd5, 0xd9, 0xea, 0x3d, - 0x38, 0xf4, 0x8f, 0xf1, 0x9a, 0x5b, 0xeb, 0x32, 0xdf, 0xf2, 0x46, 0x32, 0x57, 0xf4, 0x23, 0xe0, - 0x46, 0x4b, 0x1d, 0x15, 0xa6, 0xd0, 0x0a, 0x45, 0x3a, 0x89, 0x33, 0xdd, 0x72, 0x7b, 0x08, 0xb7, - 0x37, 0xfb, 0x16, 0x61, 0xf6, 0x89, 0x0f, 0x60, 0x27, 0x97, 0x22, 0xe0, 0x4a, 0x8d, 0xa3, 0x32, - 0x0e, 0x4d, 0xc7, 0x6d, 0xd6, 0xb6, 0xe0, 0xc9, 0x0a, 0xa3, 0x99, 0x2b, 0xbf, 0xd9, 0x40, 0x03, - 0xf0, 0x9d, 0x81, 0x3a, 0x5b, 0x9a, 0xfa, 0xa7, 0x79, 0xa0, 0x9e, 0x87, 0x7e, 0x45, 0xf0, 0xbc, - 0xbe, 0xfa, 0x10, 0x9c, 0xf3, 0xb0, 0x4c, 0xe2, 0x2c, 0x7a, 0x97, 0xcd, 0xc4, 0x86, 0x81, 0x4e, - 0xe0, 0x99, 0xfb, 0x15, 0xa9, 0x5f, 0x5a, 0xe3, 0x78, 0x25, 0x66, 0x03, 0xee, 0xdd, 0x37, 0xd4, - 0xec, 0xca, 0x9e, 0xd4, 0xf6, 0x7e, 0xf3, 0x43, 0xcf, 0x80, 0xd4, 0x65, 0xc3, 0xcb, 0xd3, 0x3a, - 0xb9, 0xf5, 0x22, 0x06, 0xd0, 0x76, 0x43, 0xb6, 0xeb, 0xd8, 0xbd, 0xbd, 0xd9, 0x6f, 0xe0, 0xcc, - 0x77, 0x52, 0xa7, 0x27, 0xb0, 0x6b, 0x64, 0x75, 0xe6, 0x6b, 0xa1, 0x46, 0x9a, 0xe8, 0xaf, 0xd2, - 0xbc, 0x42, 0xb0, 0x77, 0x96, 0x87, 0x93, 0x82, 0xbb, 0x4b, 0xfc, 0x77, 0x67, 0xf8, 0x25, 0xb4, - 0x4a, 0xad, 0x67, 0xd7, 0xd9, 0xb9, 0x6f, 0xc0, 0xf4, 0x63, 0x96, 0x47, 0xdf, 0xc3, 0x1e, 0xe3, - 0xa9, 0xf8, 0xf4, 0x9f, 0x1c, 0x0c, 0x5f, 0xcd, 0x17, 0xc4, 0xbb, 0x5e, 0x10, 0xef, 0x6e, 0x41, - 0xd0, 0x55, 0x45, 0xd0, 0x97, 0x8a, 0xa0, 0x6f, 0x15, 0x41, 0xf3, 0x8a, 0xa0, 0xef, 0x15, 0x41, - 0x3f, 0x2a, 0xe2, 0xdd, 0x55, 0x04, 0x7d, 0x5e, 0x12, 0x6f, 0xbe, 0x24, 0xde, 0xf5, 0x92, 0x78, - 0xd3, 0x96, 0xfe, 0xc7, 0x07, 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x9b, 0xf1, 0x73, 0xee, 0x58, - 0x04, 0x00, 0x00, + // 493 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x6b, 0x13, 0x41, + 0x18, 0xc6, 0x77, 0x2a, 0x06, 0xfa, 0x6e, 0x0a, 0x75, 0x3c, 0x74, 0x4d, 0x65, 0x1a, 0xa7, 0x97, + 0x5e, 0x9a, 0x4a, 0xa3, 0x5f, 0x20, 0x28, 0x45, 0x08, 0x52, 0x46, 0x7a, 0x94, 0x25, 0xd9, 0x9d, + 0x6c, 0x17, 0x92, 0x9d, 0xed, 0x4c, 0x56, 0xe8, 0xad, 0x1f, 0xc1, 0x8f, 0x21, 0x78, 0xf6, 0x3b, + 0x78, 0xcc, 0xb1, 0xa7, 0x62, 0x36, 0x17, 0xe9, 0xa9, 0x1f, 0x41, 0x32, 0x33, 0x75, 0x27, 0xad, + 0x51, 0x23, 0x9e, 0x92, 0x79, 0xff, 0x3c, 0xef, 0xef, 0x7d, 0x79, 0x58, 0x68, 0xc4, 0x5c, 0xa5, + 0x92, 0xc7, 0xe1, 0x50, 0xe6, 0xa1, 0xe4, 0x67, 0x05, 0x57, 0x63, 0xd5, 0xca, 0xa5, 0x18, 0x0b, + 0x5c, 0x1b, 0x89, 0x98, 0x0f, 0x55, 0x63, 0x3f, 0x49, 0xc7, 0xa7, 0x45, 0xbf, 0x15, 0x89, 0xd1, + 0x41, 0x22, 0x12, 0x71, 0xa0, 0xd3, 0xfd, 0x62, 0xa0, 0x5f, 0xfa, 0xa1, 0xff, 0x99, 0xb6, 0xc6, + 0x23, 0x47, 0xd2, 0x86, 0x7c, 0x2e, 0xa5, 0x90, 0xe6, 0x41, 0x3b, 0xb0, 0xfd, 0xca, 0x54, 0x74, + 0xd9, 0x71, 0x37, 0x1d, 0xf0, 0xe8, 0x3c, 0x1a, 0x72, 0xc6, 0x55, 0x2e, 0x32, 0xc5, 0xf1, 0x2e, + 0x3c, 0xd4, 0xd5, 0x01, 0x6a, 0xa2, 0x3d, 0xff, 0x70, 0xa3, 0x65, 0x28, 0x5a, 0xaf, 0xe7, 0x41, + 0x66, 0x72, 0xf4, 0x0c, 0x1e, 0x57, 0x1a, 0x6a, 0xa5, 0x5e, 0xfc, 0x12, 0xea, 0x0e, 0xa1, 0x0a, + 0xd6, 0x9a, 0x0f, 0xf6, 0xfc, 0x43, 0x7c, 0x5b, 0x5b, 0xe9, 0x32, 0xdf, 0xd6, 0x75, 0x65, 0xae, + 0xe8, 0x7b, 0xc0, 0x0b, 0x23, 0xf5, 0xa9, 0x30, 0x85, 0x5a, 0x2c, 0x46, 0xbd, 0x34, 0xd3, 0x23, + 0xd7, 0x3b, 0x70, 0x7d, 0xb5, 0x63, 0x23, 0xcc, 0xfe, 0xe2, 0x5d, 0xd8, 0xc8, 0xa5, 0x88, 0xb8, + 0x52, 0x61, 0x52, 0xa4, 0xb1, 0x99, 0xb8, 0xce, 0xea, 0x36, 0x78, 0x34, 0x8f, 0xd1, 0xcc, 0x95, + 0x5f, 0x6d, 0xa1, 0x36, 0xf8, 0xce, 0x42, 0xc1, 0x9a, 0x2e, 0xfd, 0xd5, 0x3e, 0x50, 0xed, 0x43, + 0x3f, 0x23, 0x78, 0x56, 0xa5, 0xde, 0x45, 0xa7, 0x3c, 0x2e, 0x86, 0x69, 0x96, 0xbc, 0xc9, 0x06, + 0x62, 0xc5, 0x83, 0xf6, 0xe0, 0xa9, 0xeb, 0x22, 0xf5, 0x53, 0x2b, 0x4c, 0xe7, 0x62, 0xf6, 0xc0, + 0xcd, 0xfb, 0x40, 0x8b, 0x53, 0xd9, 0x93, 0x0a, 0xef, 0x0e, 0x0f, 0xfd, 0x82, 0x60, 0x7f, 0x59, + 0x5f, 0xe7, 0xfc, 0xb8, 0x3a, 0xe4, 0x6a, 0xe4, 0x21, 0x6c, 0xff, 0x86, 0xdc, 0x5e, 0xf2, 0xcf, + 0xe0, 0xc1, 0x32, 0x70, 0x7a, 0x02, 0xa4, 0xea, 0xba, 0x03, 0x6a, 0x0c, 0xd4, 0x86, 0xba, 0x6b, + 0x0e, 0x6b, 0xa3, 0xcd, 0xeb, 0xab, 0x9d, 0x85, 0x38, 0xf3, 0x1d, 0xb7, 0xd0, 0x23, 0xd8, 0x34, + 0xb2, 0xda, 0x2b, 0xb7, 0x42, 0x0b, 0x2e, 0x40, 0x7f, 0xe5, 0x82, 0x0b, 0x04, 0x5b, 0x27, 0x79, + 0xdc, 0x1b, 0x73, 0xd7, 0x7c, 0xff, 0x4e, 0x86, 0x9f, 0x43, 0xad, 0xd0, 0x7a, 0xf6, 0x78, 0xc1, + 0x7d, 0x00, 0x33, 0x8f, 0xd9, 0x3a, 0xfa, 0x16, 0xb6, 0x18, 0x1f, 0x89, 0x0f, 0xff, 0x89, 0xa0, + 0xf3, 0x62, 0x32, 0x25, 0xde, 0xe5, 0x94, 0x78, 0x37, 0x53, 0x82, 0x2e, 0x4a, 0x82, 0x3e, 0x95, + 0x04, 0x7d, 0x2d, 0x09, 0x9a, 0x94, 0x04, 0x7d, 0x2b, 0x09, 0xfa, 0x5e, 0x12, 0xef, 0xa6, 0x24, + 0xe8, 0xe3, 0x8c, 0x78, 0x93, 0x19, 0xf1, 0x2e, 0x67, 0xc4, 0xeb, 0xd7, 0xf4, 0xb7, 0xa9, 0xfd, + 0x23, 0x00, 0x00, 0xff, 0xff, 0xca, 0x08, 0x89, 0xe8, 0x10, 0x05, 0x00, 0x00, } func (this *DesiredLRPLifecycleResponse) Equal(that interface{}) bool { @@ -647,6 +702,33 @@ func (this *DesiredLRPSchedulingInfosResponse) Equal(that interface{}) bool { } return true } +func (this *DesiredLRPSchedulingInfoByProcessGuidResponse) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DesiredLRPSchedulingInfoByProcessGuidResponse) + if !ok { + that2, ok := that.(DesiredLRPSchedulingInfoByProcessGuidResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Error.Equal(that1.Error) { + return false + } + if !this.DesiredLrpSchedulingInfo.Equal(that1.DesiredLrpSchedulingInfo) { + return false + } + return true +} func (this *DesiredLRPByProcessGuidRequest) Equal(that interface{}) bool { if that == nil { return this == nil @@ -814,6 +896,21 @@ func (this *DesiredLRPSchedulingInfosResponse) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *DesiredLRPSchedulingInfoByProcessGuidResponse) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&models.DesiredLRPSchedulingInfoByProcessGuidResponse{") + if this.Error != nil { + s = append(s, "Error: "+fmt.Sprintf("%#v", this.Error)+",\n") + } + if this.DesiredLrpSchedulingInfo != nil { + s = append(s, "DesiredLrpSchedulingInfo: "+fmt.Sprintf("%#v", this.DesiredLrpSchedulingInfo)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} func (this *DesiredLRPByProcessGuidRequest) GoString() string { if this == nil { return "nil" @@ -1086,6 +1183,53 @@ func (m *DesiredLRPSchedulingInfosResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DesiredLrpSchedulingInfo != nil { + { + size, err := m.DesiredLrpSchedulingInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDesiredLrpRequests(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Error != nil { + { + size, err := m.Error.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDesiredLrpRequests(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *DesiredLRPByProcessGuidRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1321,6 +1465,23 @@ func (m *DesiredLRPSchedulingInfosResponse) Size() (n int) { return n } +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Error != nil { + l = m.Error.Size() + n += 1 + l + sovDesiredLrpRequests(uint64(l)) + } + if m.DesiredLrpSchedulingInfo != nil { + l = m.DesiredLrpSchedulingInfo.Size() + n += 1 + l + sovDesiredLrpRequests(uint64(l)) + } + return n +} + func (m *DesiredLRPByProcessGuidRequest) Size() (n int) { if m == nil { return 0 @@ -1447,6 +1608,17 @@ func (this *DesiredLRPSchedulingInfosResponse) String() string { }, "") return s } +func (this *DesiredLRPSchedulingInfoByProcessGuidResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&DesiredLRPSchedulingInfoByProcessGuidResponse{`, + `Error:` + strings.Replace(fmt.Sprintf("%v", this.Error), "Error", "Error", 1) + `,`, + `DesiredLrpSchedulingInfo:` + strings.Replace(fmt.Sprintf("%v", this.DesiredLrpSchedulingInfo), "DesiredLRPSchedulingInfo", "DesiredLRPSchedulingInfo", 1) + `,`, + `}`, + }, "") + return s +} func (this *DesiredLRPByProcessGuidRequest) String() string { if this == nil { return "nil" @@ -2058,6 +2230,128 @@ func (m *DesiredLRPSchedulingInfosResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *DesiredLRPSchedulingInfoByProcessGuidResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDesiredLrpRequests + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DesiredLRPSchedulingInfoByProcessGuidResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DesiredLRPSchedulingInfoByProcessGuidResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDesiredLrpRequests + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDesiredLrpRequests + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDesiredLrpRequests + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Error == nil { + m.Error = &Error{} + } + if err := m.Error.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DesiredLrpSchedulingInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDesiredLrpRequests + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDesiredLrpRequests + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDesiredLrpRequests + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.DesiredLrpSchedulingInfo == nil { + m.DesiredLrpSchedulingInfo = &DesiredLRPSchedulingInfo{} + } + if err := m.DesiredLrpSchedulingInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDesiredLrpRequests(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDesiredLrpRequests + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *DesiredLRPByProcessGuidRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/models/desired_lrp_requests.proto b/models/desired_lrp_requests.proto index 46476293..be746255 100644 --- a/models/desired_lrp_requests.proto +++ b/models/desired_lrp_requests.proto @@ -30,6 +30,11 @@ message DesiredLRPSchedulingInfosResponse { repeated DesiredLRPSchedulingInfo desired_lrp_scheduling_infos = 2; } +message DesiredLRPSchedulingInfoByProcessGuidResponse { + Error error = 1; + DesiredLRPSchedulingInfo desired_lrp_scheduling_info = 2; +} + message DesiredLRPByProcessGuidRequest { string process_guid = 1 [(gogoproto.jsontag) = "process_guid"]; } diff --git a/routes.go b/routes.go index 66ccc7b0..a00095c7 100644 --- a/routes.go +++ b/routes.go @@ -34,12 +34,13 @@ const ( EvacuateRunningActualLRPRoute_r0 = "EvacuateRunningActualLRP_r0" // DEPRECATED // Desired LRPs - DesiredLRPsRoute_r3 = "DesiredLRPs" - DesiredLRPSchedulingInfosRoute_r0 = "DesiredLRPSchedulingInfos" - DesiredLRPRoutingInfosRoute_r0 = "DesiredLRPRoutingInfos" - DesiredLRPByProcessGuidRoute_r3 = "DesiredLRPByProcessGuid" - DesiredLRPsRoute_r2 = "DesiredLRPs_r2" // DEPRECATED - DesiredLRPByProcessGuidRoute_r2 = "DesiredLRPByProcessGuid_r2" // DEPRECATED + DesiredLRPsRoute_r3 = "DesiredLRPs" + DesiredLRPSchedulingInfosRoute_r0 = "DesiredLRPSchedulingInfos" + DesiredLRPSchedulingInfoByProcessGuid_r0 = "DesiredLRPSchedulingInfoByProcessGuid" + DesiredLRPRoutingInfosRoute_r0 = "DesiredLRPRoutingInfos" + DesiredLRPByProcessGuidRoute_r3 = "DesiredLRPByProcessGuid" + DesiredLRPsRoute_r2 = "DesiredLRPs_r2" // DEPRECATED + DesiredLRPByProcessGuidRoute_r2 = "DesiredLRPByProcessGuid_r2" // DEPRECATED // Desire LRP Lifecycle DesireDesiredLRPRoute_r2 = "DesireDesiredLRP" @@ -105,6 +106,7 @@ var Routes = rata.Routes{ // Desired LRPs {Path: "/v1/desired_lrp_scheduling_infos/list", Method: "POST", Name: DesiredLRPSchedulingInfosRoute_r0}, + {Path: "/v1/desired_lrp_scheduling_infos/get_by_process_guid", Method: "POST", Name: DesiredLRPSchedulingInfoByProcessGuid_r0}, {Path: "/v1/desired_lrp_routing_infos/list", Method: "POST", Name: DesiredLRPRoutingInfosRoute_r0}, {Path: "/v1/desired_lrps/list.r3", Method: "POST", Name: DesiredLRPsRoute_r3}, From bae78a83cbae8ffd7fc9535a687b62c0c842b46e Mon Sep 17 00:00:00 2001 From: i583051 Date: Tue, 16 Jan 2024 08:37:07 +0200 Subject: [PATCH 3/5] Update docs --- doc/api-lrps.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/doc/api-lrps.md b/doc/api-lrps.md index 08c81107..ec8080eb 100644 --- a/doc/api-lrps.md +++ b/doc/api-lrps.md @@ -341,6 +341,89 @@ if err != nil { } ``` +## DesiredLRPSchedulingInfoByProcessGuid + +Returns the DesiredLRPSchedulingInfo with the given process guid. + +### BBS API Endpoint + +POST a [DesiredLRPByProcessGuidRequest](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPByProcessGuidRequest) to `/v1/desired_lrp_scheduling_infos/get_by_process_guid` and receive a [DesiredLRPSchedulingInfoByProcessGuidResponse](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPSchedulingInfoByProcessGuidResponse) with a [DesiredLRPSchedulingInfo](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPSchedulingInfo). + +### Golang Client API + +```go +DesiredLRPSchedulingInfoByProcessGuid(ctx context.Context, logger lager.Logger, processGuid string) (*models.DesiredLRPSchedulingInfo, error) +``` + +#### Inputs + +* `processGuid string`: The GUID for the DesiredLRPSchedulingInfo. + +#### Output + +* `*models.DesiredLRPSchedulingInfo`: The requested [DesiredLRPSchedulingInfo](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPSchedulingInfo). +* `error`: Non-nil if an error occurred. + + +#### Example + +```go +client := bbs.NewClient(url) +schedInfo, err := client.DesiredLRPBySchedulingInfoProcessGuid(logger, "some-processs-guid") +if err != nil { + log.Printf("failed to retrieve desired lrp scheduling info: " + err.Error()) +} +``` + +## DesiredLRPRoutingInfos + +Returns all DesiredLRPs with only the routing info, that matches the given DesiredLRPFilter. + +### BBS API Endpoint + +POST a [DesiredLRPsRequest](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPsRequest) +to `/v1/desired_lrp_routing_infos/list` +and receive a [DesiredLRPsResponse](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPsResponse). + +### Golang Client API +```go +DesiredLRPRoutingInfos(ctx context.Context, logger lager.Logger, filter models.DesiredLRPFilter) ([]*models.DesiredLRP, error) +``` + +#### Inputs + +* `filter models.DesiredLRPFilter`: [DesiredLRPFilter](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRPFilter) to restrict the DesiredLRPs returned. + * `Domain string`: If non-empty, filter to only DesiredLRPs in this domain. + * `ProcessGuids []string`: If non-empty, filter to only DesiredLRPs with ProcessGuid in the given slice. + +#### Output + +* `[]*models.DesiredLRP`: List of [DesiredLRPS](https://godoc.org/code.cloudfoundry.org/bbs/models#DesiredLRP) records. +* Returned fields: +```go +".process_guid", +".domain", +".log_guid", +".instances", +".routes", +".modification_tag_epoch", +".modification_tag_index", +".run_info", +``` +* `error`: Non-nil if an error occurred. + +#### Example + +```go +client := bbs.NewClient(url) +routingInfos, err := client.DesiredLRPRoutingInfos(logger, &models.DesiredLRPFilter{ + Domain: "cf-apps", +}) +if err != nil { + log.Printf("failed to retrieve desired lrp routing info: " + err.Error()) +} +``` + ## DesireLRP Create a DesiredLRP and its corresponding associated ActualLRPs. From d432bc7b2eb5b861d5d85963fe1489ad6caf796f Mon Sep 17 00:00:00 2001 From: Brandon Roberson Date: Thu, 29 Feb 2024 10:44:34 -0700 Subject: [PATCH 4/5] Update desired_lrp_db_test.go Casing / more specific description --- db/sqldb/desired_lrp_db_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/sqldb/desired_lrp_db_test.go b/db/sqldb/desired_lrp_db_test.go index 5f5a975d..951d5e5f 100644 --- a/db/sqldb/desired_lrp_db_test.go +++ b/db/sqldb/desired_lrp_db_test.go @@ -339,7 +339,7 @@ var _ = Describe("DesiredLRPDB", func() { expectedDesiredLRPSchedulingInfo = desiredLRP.DesiredLRPSchedulingInfo() }) - It("Returns the desired-lrp", func() { + It("returns the desired lrp scheduling info", func() { schedInfo, err := sqlDB.DesiredLRPSchedulingInfoByProcessGuid(ctx, logger, expectedDesiredLRPSchedulingInfo.ProcessGuid) Expect(err).NotTo(HaveOccurred()) From 8a2d5e1e550302ecca5932651b4bfe78e97eb11f Mon Sep 17 00:00:00 2001 From: Brandon Roberson Date: Thu, 29 Feb 2024 10:47:17 -0700 Subject: [PATCH 5/5] Update desired_lrp_handlers_test.go No need to specify VolumeMount type process_guid -> receivedProcessGuid for clarity Typo on `errros` --- handlers/desired_lrp_handlers_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/handlers/desired_lrp_handlers_test.go b/handlers/desired_lrp_handlers_test.go index 4cf79d58..347a6d6b 100644 --- a/handlers/desired_lrp_handlers_test.go +++ b/handlers/desired_lrp_handlers_test.go @@ -767,7 +767,7 @@ var _ = Describe("DesiredLRP Handlers", func() { desiredLRP := &models.DesiredLRP{ ProcessGuid: "some-guid", VolumeMounts: []*models.VolumeMount{ - &models.VolumeMount{ + { Driver: "some=driver", }, }, @@ -779,8 +779,8 @@ var _ = Describe("DesiredLRP Handlers", func() { It("fetches the desired lrp scheduling info by process guid", func() { Expect(fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidCallCount()).To(Equal(1)) - _, _, process_guid := fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidArgsForCall(0) - Expect(process_guid).To(Equal(processGuid)) + _, _, receivedProcessGuid := fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidArgsForCall(0) + Expect(receivedProcessGuid).To(Equal(processGuid)) Expect(responseRecorder.Code).To(Equal(http.StatusOK)) response := models.DesiredLRPSchedulingInfoByProcessGuidResponse{} @@ -820,7 +820,7 @@ var _ = Describe("DesiredLRP Handlers", func() { }) }) - Context("when the DB errros out", func() { + Context("when the DB errors out", func() { BeforeEach(func() { fakeDesiredLRPDB.DesiredLRPSchedulingInfoByProcessGuidReturns(nil, models.ErrUnknownError) })