Accounting lost state of allocations

This commit is contained in:
Diptanu Choudhury 2016-07-12 14:27:45 -06:00
parent e8d1aee3f4
commit 00b9b4c6e8
3 changed files with 7 additions and 15 deletions

View File

@ -1299,6 +1299,8 @@ func (s *StateStore) updateSummaryWithAlloc(newAlloc *structs.Allocation,
tgSummary.Starting += 1
case structs.AllocClientStatusComplete:
tgSummary.Complete += 1
case structs.AllocClientStatusLost:
tgSummary.Lost += 1
}
// Decrementing the count of the bin of the last state
@ -1311,21 +1313,8 @@ func (s *StateStore) updateSummaryWithAlloc(newAlloc *structs.Allocation,
tgSummary.Starting -= 1
case structs.AllocClientStatusComplete:
tgSummary.Complete -= 1
}
} else if existingAlloc.DesiredStatus != newAlloc.DesiredStatus {
shouldDecrementStarting := false
switch newAlloc.DesiredStatus {
case structs.AllocDesiredStatusFailed:
tgSummary.Failed += 1
shouldDecrementStarting = true
case structs.AllocDesiredStatusStop:
tgSummary.Complete += 1
shouldDecrementStarting = true
}
if shouldDecrementStarting {
if newAlloc.ClientStatus == structs.AllocClientStatusPending {
tgSummary.Starting -= 1
}
case structs.AllocClientStatusLost:
tgSummary.Lost -= 1
}
}

View File

@ -2369,12 +2369,14 @@ func TestStateJobSummary_UpdateJobCount(t *testing.T) {
alloc4.Job = alloc2.Job
alloc4.JobID = alloc2.JobID
alloc4.DesiredStatus = structs.AllocDesiredStatusStop
alloc4.ClientStatus = structs.AllocClientStatusComplete
alloc5 := mock.Alloc()
alloc5.ID = alloc3.ID
alloc5.Job = alloc3.Job
alloc5.JobID = alloc3.JobID
alloc5.DesiredStatus = structs.AllocDesiredStatusStop
alloc5.ClientStatus = structs.AllocClientStatusComplete
if err := state.UpsertAllocs(1004, []*structs.Allocation{alloc4, alloc5}); err != nil {
t.Fatalf("err: %v", err)

View File

@ -955,6 +955,7 @@ type TaskGroupSummary struct {
Failed int
Running int
Starting int
Lost int
}
// Total returns the total number of allocations for the task group.