Skip to content

Commit

Permalink
set status waiting for lock
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Mar 20, 2018
1 parent 7756fd6 commit 963f330
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 25 deletions.
56 changes: 56 additions & 0 deletions api/scheduler_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,9 @@ autoscaling:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -842,6 +845,9 @@ autoscaling:
SetNX(lockKeyNs, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

scheduler1 := models.NewScheduler(configYaml1.Name, configYaml1.Game, yamlString)
// Update new config on schedulers table
MockUpdateSchedulersTable(mockDb, nil)
Expand Down Expand Up @@ -880,6 +886,10 @@ autoscaling:
mockRedisClient.EXPECT().
SetNX(lockKeyNs, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

mockDb.EXPECT().
Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml1.Name)
mockRedisClient.EXPECT().
Expand Down Expand Up @@ -940,6 +950,9 @@ autoscaling:
SetNX(gomock.Any(), gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

mockRedisClient.EXPECT().
Eval(gomock.Any(), gomock.Any(), gomock.Any()).
Return(redis.NewCmdResult(nil, nil))
Expand Down Expand Up @@ -1014,6 +1027,9 @@ autoscaling:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -1100,6 +1116,9 @@ autoscaling:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -1149,6 +1168,10 @@ autoscaling:
mockRedisClient.EXPECT().
SetNX(gomock.Any(), gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

mockDb.EXPECT().Query(
gomock.Any(),
"SELECT * FROM schedulers WHERE name = ?",
Expand Down Expand Up @@ -1312,6 +1335,9 @@ forwarders:
SetNX(lockKeyNs, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

scheduler1 := models.NewScheduler(configYaml1.Name, configYaml1.Game, yamlString)
// Update new config on schedulers table
MockUpdateSchedulersTable(mockDb, nil)
Expand Down Expand Up @@ -2167,6 +2193,9 @@ ports:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -2220,6 +2249,9 @@ ports:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -2551,6 +2583,9 @@ ports:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -2634,6 +2669,9 @@ ports:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml1)

Expand Down Expand Up @@ -2711,6 +2749,9 @@ ports:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand Down Expand Up @@ -2880,6 +2921,9 @@ ports:
SetNX(schedulerLockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

mockDb.EXPECT().
Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml1.Name).
Do(func(scheduler *models.Scheduler, query string, modifier string) {
Expand Down Expand Up @@ -3019,6 +3063,9 @@ ports:
SetNX(schedulerLockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Update new config on schedulers table
MockUpdateSchedulersTable(mockDb, nil)
// Add new version into versions table
Expand Down Expand Up @@ -3110,6 +3157,9 @@ ports:
SetNX(schedulerLockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Update scheduler
body := map[string]interface{}{"min": configYaml1.AutoScaling.Min + 1}
bts, _ := json.Marshal(body)
Expand Down Expand Up @@ -3188,6 +3238,9 @@ ports:
SetNX(schedulerLockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

mockDb.EXPECT().
Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml1.Name).
Do(func(scheduler *models.Scheduler, query string, modifier string) {
Expand Down Expand Up @@ -3262,6 +3315,9 @@ ports:
SetNX(schedulerLockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(redis.NewBoolResult(true, nil))

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

mockDb.EXPECT().
Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml1.Name).
Do(func(scheduler *models.Scheduler, query string, modifier string) {
Expand Down
6 changes: 6 additions & 0 deletions api/scheduler_rollback_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ autoscaling:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Update new config on schedulers table
MockUpdateSchedulersTable(mockDb, nil)

Expand Down Expand Up @@ -203,6 +206,9 @@ autoscaling:
// Get redis lock
MockRedisLock(mockRedisClient, lockKeyNs, lockTimeoutMs, true, nil)

// Set new operation manager description
MockAnySetDescription(opManager, mockRedisClient, "running", nil)

// Update new config on schedulers table
MockUpdateSchedulersTable(mockDb, nil)

Expand Down
2 changes: 2 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ waitForLock:
}
}()

operationManager.SetDescription("running")

var scheduler *models.Scheduler
var oldConfig models.ConfigYAML
if schedulerOrNil != nil {
Expand Down
50 changes: 45 additions & 5 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ var _ = Describe("Controller", func() {

_, err = clientset.CoreV1().Nodes().Create(node)
Expect(err).NotTo(HaveOccurred())

opManager = models.NewOperationManager(configYaml1.Name, mockRedisClient, logger)
})

Describe("CreateScheduler", func() {
Expand Down Expand Up @@ -2680,7 +2682,6 @@ containers:
Expect(err).NotTo(HaveOccurred())

scheduler1 = models.NewScheduler(configYaml1.Name, configYaml1.Game, yaml1)
opManager = models.NewOperationManager(configYaml1.Name, mockRedisClient, logger)

mt.MockCreateScheduler(clientset, mockRedisClient, mockPipeline, mockDb,
logger, mr, yaml1, timeoutSec)
Expand Down Expand Up @@ -2744,6 +2745,9 @@ cmd:
// Get redis lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml2)

Expand Down Expand Up @@ -2815,6 +2819,9 @@ cmd:
// Get redis lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Select empty scheduler yaml
mockDb.EXPECT().
Query(gomock.Any(), "SELECT * FROM schedulers WHERE name = ?", configYaml2.Name)
Expand Down Expand Up @@ -2888,6 +2895,9 @@ cmd:
// Get redis lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Update new config on schedulers table
mt.MockUpdateSchedulersTable(mockDb, nil)

Expand Down Expand Up @@ -2942,6 +2952,10 @@ cmd:
mockRedisClient.EXPECT().
SetNX(lockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(goredis.NewBoolResult(true, nil))

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

mockRedisClient.EXPECT().
Eval(gomock.Any(), []string{lockKey}, gomock.Any()).
Return(goredis.NewCmdResult(nil, nil))
Expand Down Expand Up @@ -2997,6 +3011,7 @@ cmd:
mockRedisClient.EXPECT().
SetNX(lockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(goredis.NewBoolResult(false, nil))

mockRedisClient.EXPECT().
Eval(gomock.Any(), []string{lockKey}, gomock.Any()).
Return(goredis.NewCmdResult(nil, nil))
Expand Down Expand Up @@ -3062,6 +3077,10 @@ cmd:
calls.Append(
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil))

// Set new operation manager description
calls.Append(
mt.MockSetDescription(opManager, mockRedisClient, "running", nil))

// Get scheduler from DB
calls.Append(
mt.MockSelectScheduler(yaml1, mockDb, nil))
Expand Down Expand Up @@ -3120,6 +3139,9 @@ cmd:
SetNX(lockKey, gomock.Any(), time.Duration(lockTimeoutMs)*time.Millisecond).
Return(goredis.NewBoolResult(true, nil)))

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Get scheduler from DB
calls.Add(
mockDb.EXPECT().
Expand Down Expand Up @@ -3292,6 +3314,10 @@ cmd:
calls.Append(
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil))

// Set new operation manager description
calls.Append(
mt.MockSetDescription(opManager, mockRedisClient, "running", nil))

// Get scheduler from DB
calls.Append(mt.MockSelectScheduler(yaml1, mockDb, nil))

Expand Down Expand Up @@ -3421,6 +3447,9 @@ cmd:
// Get redis lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml2)

Expand Down Expand Up @@ -3576,6 +3605,9 @@ containers:
lockKey := "maestro-lock-key-scheduler-name-cancel"
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Remove old room
for i, pod := range pods.Items {
room := models.NewRoom(pod.GetName(), pod.GetNamespace())
Expand Down Expand Up @@ -3681,6 +3713,9 @@ containers:
lockKey := "maestro-lock-key-scheduler-name-cancel"
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Delete keys from OperationManager (to cancel it)
mt.MockDeleteRedisKey(opManager, mockRedisClient, mockPipeline, nil)

Expand Down Expand Up @@ -3906,6 +3941,9 @@ containers:
// Get redis lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml1)

Expand All @@ -3926,8 +3964,6 @@ containers:
// Retrieve redis lock
mt.MockReturnRedisLock(mockRedisClient, lockKey, nil)

opManager = models.NewOperationManager(scheduler1.Name, mockRedisClient, logger)

err = controller.UpdateSchedulerImage(
logger,
mr,
Expand Down Expand Up @@ -4121,6 +4157,9 @@ containers:
// Get lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Remove old rooms
mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml)

Expand All @@ -4140,8 +4179,6 @@ containers:
// return lock
mt.MockReturnRedisLock(mockRedisClient, lockKey, nil)

opManager = models.NewOperationManager(scheduler1.Name, mockRedisClient, logger)

imageParams.Container = "container1"
err = controller.UpdateSchedulerImage(
logger,
Expand Down Expand Up @@ -4380,6 +4417,9 @@ containers:
// Get redis lock
mt.MockRedisLock(mockRedisClient, lockKey, lockTimeoutMs, true, nil)

// Set new operation manager description
mt.MockSetDescription(opManager, mockRedisClient, "running", nil)

// Update new config on schedulers table
mt.MockUpdateSchedulersTable(mockDb, nil)

Expand Down
Loading

0 comments on commit 963f330

Please sign in to comment.