From 63d8e92e901b8b59c314bdfba9ef6938ed33bebf Mon Sep 17 00:00:00 2001 From: Alex Munda Date: Wed, 30 Jun 2021 14:23:37 -0500 Subject: [PATCH] Move idempotency token to write options. Remove DispatchIdempotent --- api/api.go | 3 +++ api/jobs.go | 23 +++---------------- nomad/structs/structs.go | 10 ++++---- vendor/github.com/hashicorp/nomad/api/api.go | 3 +++ vendor/github.com/hashicorp/nomad/api/jobs.go | 23 +++---------------- 5 files changed, 18 insertions(+), 44 deletions(-) diff --git a/api/api.go b/api/api.go index 7ce7d9a13..7693bde43 100644 --- a/api/api.go +++ b/api/api.go @@ -93,6 +93,9 @@ type WriteOptions struct { // ctx is an optional context pass through to the underlying HTTP // request layer. Use Context() and WithContext() to manage this. ctx context.Context + + // IdempotencyToken can be used to ensure the write is idempotent. + IdempotencyToken string } // QueryMeta is used to return meta data about a query diff --git a/api/jobs.go b/api/jobs.go index 536234c3d..1fed52c7c 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -397,22 +397,6 @@ func (j *Jobs) Dispatch(jobID string, meta map[string]string, return &resp, wm, nil } -func (j *Jobs) DispatchIdempotent(jobID string, meta map[string]string, - payload []byte, idempotencyToken string, q *WriteOptions) (*JobDispatchResponse, *WriteMeta, error) { - var resp JobDispatchResponse - req := &JobDispatchRequest{ - JobID: jobID, - Meta: meta, - Payload: payload, - IdempotencyToken: idempotencyToken, - } - wm, err := j.client.write("/v1/job/"+url.PathEscape(jobID)+"/dispatch", req, &resp, q) - if err != nil { - return nil, nil, err - } - return &resp, wm, nil -} - // Revert is used to revert the given job to the passed version. If // enforceVersion is set, the job is only reverted if the current version is at // the passed version. @@ -1278,10 +1262,9 @@ type DesiredUpdates struct { } type JobDispatchRequest struct { - JobID string - Payload []byte - Meta map[string]string - IdempotencyToken string + JobID string + Payload []byte + Meta map[string]string } type JobDispatchResponse struct { diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 9d1677bc5..bf7358580 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -385,6 +385,9 @@ type WriteRequest struct { // AuthToken is secret portion of the ACL token used for the request AuthToken string + // IdempotencyToken can be used to ensure the write is idempotent. + IdempotencyToken string + InternalRpcInfo } @@ -728,10 +731,9 @@ type JobScaleStatusRequest struct { // JobDispatchRequest is used to dispatch a job based on a parameterized job type JobDispatchRequest struct { - JobID string - Payload []byte - Meta map[string]string - IdempotencyToken string + JobID string + Payload []byte + Meta map[string]string WriteRequest } diff --git a/vendor/github.com/hashicorp/nomad/api/api.go b/vendor/github.com/hashicorp/nomad/api/api.go index 7ce7d9a13..7693bde43 100644 --- a/vendor/github.com/hashicorp/nomad/api/api.go +++ b/vendor/github.com/hashicorp/nomad/api/api.go @@ -93,6 +93,9 @@ type WriteOptions struct { // ctx is an optional context pass through to the underlying HTTP // request layer. Use Context() and WithContext() to manage this. ctx context.Context + + // IdempotencyToken can be used to ensure the write is idempotent. + IdempotencyToken string } // QueryMeta is used to return meta data about a query diff --git a/vendor/github.com/hashicorp/nomad/api/jobs.go b/vendor/github.com/hashicorp/nomad/api/jobs.go index 536234c3d..1fed52c7c 100644 --- a/vendor/github.com/hashicorp/nomad/api/jobs.go +++ b/vendor/github.com/hashicorp/nomad/api/jobs.go @@ -397,22 +397,6 @@ func (j *Jobs) Dispatch(jobID string, meta map[string]string, return &resp, wm, nil } -func (j *Jobs) DispatchIdempotent(jobID string, meta map[string]string, - payload []byte, idempotencyToken string, q *WriteOptions) (*JobDispatchResponse, *WriteMeta, error) { - var resp JobDispatchResponse - req := &JobDispatchRequest{ - JobID: jobID, - Meta: meta, - Payload: payload, - IdempotencyToken: idempotencyToken, - } - wm, err := j.client.write("/v1/job/"+url.PathEscape(jobID)+"/dispatch", req, &resp, q) - if err != nil { - return nil, nil, err - } - return &resp, wm, nil -} - // Revert is used to revert the given job to the passed version. If // enforceVersion is set, the job is only reverted if the current version is at // the passed version. @@ -1278,10 +1262,9 @@ type DesiredUpdates struct { } type JobDispatchRequest struct { - JobID string - Payload []byte - Meta map[string]string - IdempotencyToken string + JobID string + Payload []byte + Meta map[string]string } type JobDispatchResponse struct {