Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/bbs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type BBSConfig struct {
ConvergenceWorkers int `json:"convergence_workers,omitempty"`
DatabaseConnectionString string `json:"database_connection_string"`
DatabaseDriver string `json:"database_driver,omitempty"`
DebugLRPStartHeartbeats bool `json:"debug_lrp_start_heartbeats,omitempty"`
DesiredLRPCreationTimeout durationjson.Duration `json:"desired_lrp_creation_timeout,omitempty"`
ExpireCompletedTaskDuration durationjson.Duration `json:"expire_completed_task_duration,omitempty"`
ExpirePendingTaskDuration durationjson.Duration `json:"expire_pending_task_duration,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions cmd/bbs/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var _ = Describe("BBSConfig", func() {
"database_connection_string": "",
"database_driver": "postgres",
"debug_address": "127.0.0.1:17017",
"debug_lrp_start_heartbeats":true,
"desired_lrp_creation_timeout": "1m0s",
"encryption_keys": {"label": "key"},
"expire_completed_task_duration": "2m0s",
Expand Down Expand Up @@ -137,6 +138,7 @@ var _ = Describe("BBSConfig", func() {
DebugServerConfig: debugserver.DebugServerConfig{
DebugAddress: "127.0.0.1:17017",
},
DebugLRPStartHeartbeats: true,
DesiredLRPCreationTimeout: durationjson.Duration(1 * time.Minute),
EncryptionConfig: encryption.EncryptionConfig{
ActiveKeyLabel: "label",
Expand Down
2 changes: 2 additions & 0 deletions cmd/bbs/lrp_convergence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var _ = Describe("Convergence API", func() {
clock.NewClock(),
sqlRunner.DriverName(),
metronClient,
false,
)

Eventually(func() models.ActualLRP_Presence {
Expand Down Expand Up @@ -176,6 +177,7 @@ var _ = Describe("Convergence API", func() {
map[string]string{},
false,
"",
false,
)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
1 change: 1 addition & 0 deletions cmd/bbs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func main() {
clock,
bbsConfig.DatabaseDriver,
metronClient,
bbsConfig.DebugLRPStartHeartbeats,
)
err = sqlDB.CreateConfigurationsTable(context.Background(), logger)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion controllers/actual_lrp_lifecycle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ func (h *ActualLRPLifecycleController) StartActualLRP(ctx context.Context,
return nil
}

isCurrentlyRunning := lrp != nil && lrp.State == models.ActualLRPStateRunning

// creates ordinary running actual LRP if it doesn't exist, otherwise updates
// the existing ordinary actual LRP to running state
before, after, err := h.db.StartActualLRP(ctx, logger, actualLRPKey, actualLRPInstanceKey, actualLRPNetInfo, actualLRPInternalRoutes, actualLRPMetricTags, routable, availabilityZone)
before, after, err := h.db.StartActualLRP(ctx, logger, actualLRPKey, actualLRPInstanceKey, actualLRPNetInfo, actualLRPInternalRoutes, actualLRPMetricTags, routable, availabilityZone, isCurrentlyRunning)
if err != nil {
return err
}
Expand Down
24 changes: 22 additions & 2 deletions controllers/actual_lrp_lifecycle_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() {
Expect(fakeActualLRPDB.StartActualLRPCallCount()).To(Equal(1))
Expect(fakeActualLRPDB.ActualLRPsCallCount()).To(Equal(1))

_, _, _, _, _, internalRoutesArgument, metricTagsArgument, routableArgument, availabilityZoneArgument := fakeActualLRPDB.StartActualLRPArgsForCall(0)
_, _, _, _, _, internalRoutesArgument, metricTagsArgument, routableArgument, availabilityZoneArgument, _ := fakeActualLRPDB.StartActualLRPArgsForCall(0)

Expect(err).NotTo(HaveOccurred())
Expect(internalRoutesArgument).To(Equal(internalRoutes))
Expand Down Expand Up @@ -532,11 +532,23 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() {
createdEvent := event.(*models.ActualLRPInstanceCreatedEvent)
Expect(createdEvent.ActualLrp).To(Equal(afterActualLRP))
})
It("tells the db that a previous instance didn't exist", func() {
err = controller.StartActualLRP(ctx, logger, &actualLRPKey, &afterInstanceKey, &netInfo, internalRoutes, metricTags, routable, availabilityZone)
Expect(err).NotTo(HaveOccurred())

Expect(fakeActualLRPDB.StartActualLRPCallCount()).To(Equal(1))
_, _, _, _, _, _, _, _, _, isRunning := fakeActualLRPDB.StartActualLRPArgsForCall(0)
Expect(isRunning).To(BeFalse())
})
})

Context("when the actual lrp was updated", func() {
JustBeforeEach(func() {
actualLRP.State = models.ActualLRPStateRunning
fakeActualLRPDB.ActualLRPsReturns([]*models.ActualLRP{actualLRP}, nil)
})
It("emits a change event to the hub", func() {
err = controller.StartActualLRP(ctx, logger, &actualLRPKey, &afterInstanceKey, &netInfo, internalRoutes, metricTags, routable, availabilityZone)
err = controller.StartActualLRP(ctx, logger, &actualLRPKey, &beforeInstanceKey, &netInfo, internalRoutes, metricTags, routable, availabilityZone)
Eventually(actualHub.EmitCallCount).Should(Equal(1))
event := actualHub.EmitArgsForCall(0)
//lint:ignore SA1019 - calling deprecated model while unit testing deprecated method
Expand All @@ -547,6 +559,14 @@ var _ = Describe("ActualLRP Lifecycle Controller", func() {
//lint:ignore SA1019 - still need to emit these events until the ActaulLRPGroup api is deleted
Expect(changedEvent.After).To(Equal(afterActualLRP.ToActualLRPGroup()))
})
It("tells the db that a previous instance exists", func() {
err = controller.StartActualLRP(ctx, logger, &actualLRPKey, &afterInstanceKey, &netInfo, internalRoutes, metricTags, routable, availabilityZone)
Expect(err).NotTo(HaveOccurred())

Expect(fakeActualLRPDB.StartActualLRPCallCount()).To(Equal(1))
_, _, _, _, _, _, _, _, _, isRunning := fakeActualLRPDB.StartActualLRPArgsForCall(0)
Expect(isRunning).To(BeTrue())
})
})

Context("when Routable was updated", func() {
Expand Down
1 change: 1 addition & 0 deletions db/actual_lrp_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ActualLRPDB interface {
metricTags map[string]string,
routable bool,
availabilityZone string,
isCurrentlyRunning bool,
) (before *models.ActualLRP, after *models.ActualLRP, err error)
CrashActualLRP(ctx context.Context, logger lager.Logger, key *models.ActualLRPKey, instanceKey *models.ActualLRPInstanceKey, crashReason string) (before *models.ActualLRP, after *models.ActualLRP, shouldRestart bool, err error)
FailActualLRP(ctx context.Context, logger lager.Logger, key *models.ActualLRPKey, placementError string) (before *models.ActualLRP, after *models.ActualLRP, err error)
Expand Down
54 changes: 28 additions & 26 deletions db/dbfakes/fake_actual_lrpdb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 28 additions & 26 deletions db/dbfakes/fake_db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading