From 77619b6b63749e8df8a2974b8db441110d12a991 Mon Sep 17 00:00:00 2001 From: Chris Baker Date: Fri, 21 Jun 2019 16:20:06 +0000 Subject: [PATCH 1/2] api: return X-Nomad-Index header on allocation stop --- command/agent/alloc_endpoint.go | 4 +++- command/agent/alloc_endpoint_test.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index 9c78c8749..3305f1850 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -125,9 +125,11 @@ func (s *HTTPServer) allocStop(allocID string, resp http.ResponseWriter, req *ht if structs.IsErrUnknownAllocation(rpcErr) { rpcErr = CodedError(404, allocNotFoundErr) } + return nil, rpcErr } - return &out, rpcErr + setIndex(resp, out.Index) + return &out, nil } func (s *HTTPServer) ClientAllocRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { diff --git a/command/agent/alloc_endpoint_test.go b/command/agent/alloc_endpoint_test.go index 85de625f9..6d9f3fa64 100644 --- a/command/agent/alloc_endpoint_test.go +++ b/command/agent/alloc_endpoint_test.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "os" "reflect" + "strconv" "strings" "testing" @@ -419,6 +420,8 @@ func TestHTTP_AllocStop(t *testing.T) { a := obj.(*structs.AllocStopResponse) require.NotEmpty(a.EvalID, "missing eval") require.NotEmpty(a.Index, "missing index") + headerIndex, _ := strconv.ParseUint(respW.Header().Get("X-Nomad-Index"), 10, 64) + require.Equal(a.Index, headerIndex) } // Test that we 404 when the allocid is invalid From 06e30c458929d398bfef47cdc678bd85888548ff Mon Sep 17 00:00:00 2001 From: Chris Baker Date: Fri, 21 Jun 2019 21:44:38 +0000 Subject: [PATCH 2/2] api: removed unused AllocID from AllocSignalRequest --- api/allocations.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/api/allocations.go b/api/allocations.go index fde558e11..3089f775e 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -335,9 +335,8 @@ func (a *Allocations) Signal(alloc *Allocation, q *QueryOptions, task, signal st } req := AllocSignalRequest{ - AllocID: alloc.ID, - Signal: signal, - Task: task, + Signal: signal, + Task: task, } var resp GenericResponse @@ -519,9 +518,8 @@ type AllocationRestartRequest struct { } type AllocSignalRequest struct { - AllocID string - Task string - Signal string + Task string + Signal string } // GenericResponse is used to respond to a request where no