Add RescheduleTracker to allocations API struct

This commit is contained in:
Preetha Appan
2018-01-18 18:05:20 -06:00
parent 9a21db844d
commit ccc434ee6a
2 changed files with 26 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ type Allocation struct {
AllocModifyIndex uint64
CreateTime int64
ModifyTime int64
RescheduleTracker *RescheduleTracker
}
// AllocationMetric is used to deserialize allocation metrics.
@@ -135,6 +136,7 @@ type AllocationListStub struct {
ModifyIndex uint64
CreateTime int64
ModifyTime int64
RescheduleTracker *RescheduleTracker
}
// AllocDeploymentStatus captures the status of the allocation as part of the
@@ -159,3 +161,20 @@ func (a AllocIndexSort) Less(i, j int) bool {
func (a AllocIndexSort) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
// RescheduleTracker encapsulates previous reschedule events
type RescheduleTracker struct {
Events []*RescheduleEvent
}
// RescheduleEvent is used to keep track of previous attempts at rescheduling an allocation
type RescheduleEvent struct {
// RescheduleTime is the timestamp of a reschedule attempt
RescheduleTime int64
// PrevAllocID is the ID of the previous allocation being restarted
PrevAllocID string
// PrevNodeID is the node ID of the previous allocation
PrevNodeID string
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
@@ -218,7 +219,13 @@ func TestAllocEndpoint_GetAlloc(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
// Create the register request
prevAllocID := uuid.Generate()
alloc := mock.Alloc()
alloc.RescheduleTracker = &structs.RescheduleTracker{
Events: []*structs.RescheduleEvent{
{RescheduleTime: time.Now().UTC().UnixNano(), PrevNodeID: "boom", PrevAllocID: prevAllocID},
},
}
state := s1.fsm.State()
state.UpsertJobSummary(999, mock.JobSummary(alloc.JobID))
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc})