From 532402aa2d263a9db4b090964405bd4c90538fc5 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Thu, 23 Nov 2023 07:42:37 +0000 Subject: [PATCH] actions: use specific RPC request object and tighten naming. (#19149) --- command/agent/job_endpoint.go | 6 +++--- nomad/job_endpoint.go | 7 ++++--- nomad/structs/actions.go | 20 +++++++++++++++++++- nomad/structs/actions_test.go | 7 +++++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index cb8519cd1..db7d24279 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -346,15 +346,15 @@ func (s *HTTPServer) jobActions(resp http.ResponseWriter, req *http.Request, job return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod) } - args := structs.JobSpecificRequest{ + args := structs.JobActionListRequest{ JobID: jobID, } if s.parse(resp, req, &args.Region, &args.QueryOptions) { return nil, nil } - var out structs.ActionListResponse - if err := s.agent.RPC("Job.GetActions", &args, &out); err != nil { + var out structs.JobActionListResponse + if err := s.agent.RPC(structs.JobGetActionsRPCMethod, &args, &out); err != nil { return nil, err } diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 06712eba3..66070f175 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -1720,11 +1720,12 @@ func (j *Job) LatestDeployment(args *structs.JobSpecificRequest, return j.srv.blockingRPC(&opts) } -// jobActions is used to parse through a job's taskgroups' tasks and aggregate their actions, flattened -func (j *Job) GetActions(args *structs.JobSpecificRequest, reply *structs.ActionListResponse) error { +// GetActions is used to iterate through a job's taskgroups' tasks and +// aggregate their actions, flattened. +func (j *Job) GetActions(args *structs.JobActionListRequest, reply *structs.JobActionListResponse) error { // authenticate, measure, and forward authErr := j.srv.Authenticate(j.ctx, args) - if done, err := j.srv.forward("Job.GetActions", args, args, reply); done { + if done, err := j.srv.forward(structs.JobGetActionsRPCMethod, args, args, reply); done { return err } j.srv.MeasureRPCRate("job", structs.RateMetricRead, args) diff --git a/nomad/structs/actions.go b/nomad/structs/actions.go index 78a2f9810..2791d825e 100644 --- a/nomad/structs/actions.go +++ b/nomad/structs/actions.go @@ -31,7 +31,25 @@ type JobAction struct { TaskGroupName string } -type ActionListResponse struct { +const ( + // JobGetActionsRPCMethod is the RPC method for listing all configured + // actions within a job. + // + // Args: JobActionListRequest + // Reply: JobActionListResponse + JobGetActionsRPCMethod = "Job.GetActions" +) + +// JobActionListRequest is the request object when listing the actions +// configured within a job. +type JobActionListRequest struct { + JobID string + QueryOptions +} + +// JobActionListResponse is the response object when performing a listing of +// actions configured within a job. +type JobActionListResponse struct { Actions []*JobAction QueryMeta } diff --git a/nomad/structs/actions_test.go b/nomad/structs/actions_test.go index 463fd1929..3c7e20714 100644 --- a/nomad/structs/actions_test.go +++ b/nomad/structs/actions_test.go @@ -12,6 +12,13 @@ import ( "github.com/shoenig/test/must" ) +func TestJobActionListRequest(t *testing.T) { + ci.Parallel(t) + + req := JobActionListRequest{} + must.True(t, req.IsRead()) +} + func TestAction_Copy(t *testing.T) { ci.Parallel(t)