Skip to content

Commit

Permalink
Merge pull request #5870 from hashicorp/b-nmd-1529-alloc-stop-missing…
Browse files Browse the repository at this point in the history
…-header

api: return X-Nomad-Index header on allocation stop
  • Loading branch information
Chris Baker committed Jul 17, 2019
2 parents bcfb39d + 06e30c4 commit 0965379
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 4 additions & 6 deletions api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion command/agent/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions command/agent/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http/httptest"
"os"
"reflect"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0965379

Please sign in to comment.