From ccc434ee6a63dddae646bf26fb2cc537a20d8e68 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Thu, 18 Jan 2018 18:05:20 -0600 Subject: [PATCH] Add RescheduleTracker to allocations API struct --- api/allocations.go | 19 +++++++++++++++++++ nomad/alloc_endpoint_test.go | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/api/allocations.go b/api/allocations.go index 0b2823bd2..68e2e8f6f 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -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 +} diff --git a/nomad/alloc_endpoint_test.go b/nomad/alloc_endpoint_test.go index d10a852d0..ec5c372ec 100644 --- a/nomad/alloc_endpoint_test.go +++ b/nomad/alloc_endpoint_test.go @@ -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})