diff --git a/.changelog/14833.txt b/.changelog/14833.txt new file mode 100644 index 000000000000..4cb7b34b4840 --- /dev/null +++ b/.changelog/14833.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Adds a "Pack" tag and logo on the jobs list index when appropriate +``` diff --git a/api/jobs.go b/api/jobs.go index de77db1a5075..a9011189731d 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -155,10 +155,31 @@ func (j *Jobs) RegisterOpts(job *Job, opts *RegisterOptions, q *WriteOptions) (* return &resp, wm, nil } +type JobListFields struct { + Meta bool +} +type JobListOptions struct { + Fields *JobListFields +} + // List is used to list all of the existing jobs. func (j *Jobs) List(q *QueryOptions) ([]*JobListStub, *QueryMeta, error) { + return j.ListOptions(nil, q) +} + +// List is used to list all of the existing jobs. +func (j *Jobs) ListOptions(opts *JobListOptions, q *QueryOptions) ([]*JobListStub, *QueryMeta, error) { var resp []*JobListStub - qm, err := j.client.query("/v1/jobs", &resp, q) + + destinationURL := "/v1/jobs" + + if opts != nil && opts.Fields != nil { + qp := url.Values{} + qp.Add("meta", fmt.Sprint(opts.Fields.Meta)) + destinationURL = destinationURL + "?" + qp.Encode() + } + + qm, err := j.client.query(destinationURL, &resp, q) if err != nil { return nil, qm, err } @@ -1063,6 +1084,7 @@ type JobListStub struct { ModifyIndex uint64 JobModifyIndex uint64 SubmitTime int64 + Meta map[string]string `json:",omitempty"` } // JobIDSort is used to sort jobs by their job ID's. diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index dc31ea6d5f73..7a4977da8d5d 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -37,6 +37,16 @@ func (s *HTTPServer) jobListRequest(resp http.ResponseWriter, req *http.Request) return nil, nil } + args.Fields = &structs.JobStubFields{} + // Parse meta query param + jobMeta, err := parseBool(req, "meta") + if err != nil { + return nil, err + } + if jobMeta != nil { + args.Fields.Meta = *jobMeta + } + var out structs.JobListResponse if err := s.agent.RPC("Job.List", &args, &out); err != nil { return nil, err diff --git a/command/job_status.go b/command/job_status.go index f129fc922883..ea464974caab 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -128,7 +128,7 @@ func (c *JobStatusCommand) Run(args []string) int { // Invoke list mode if no job ID. if len(args) == 0 { - jobs, _, err := client.Jobs().List(nil) + jobs, _, err := client.Jobs().ListOptions(nil, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error querying jobs: %s", err)) diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 80ef7afb5110..155ff12228e8 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -1377,7 +1377,7 @@ func (j *Job) List(args *structs.JobListRequest, reply *structs.JobListResponse) if err != nil || summary == nil { return fmt.Errorf("unable to look up summary for job: %v", job.ID) } - jobs = append(jobs, job.Stub(summary)) + jobs = append(jobs, job.Stub(summary, args.Fields)) return nil }) if err != nil { diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index 94242c22ed80..655baf9c6a10 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -5113,6 +5113,7 @@ func TestJobEndpoint_ListJobs(t *testing.T) { require.Len(t, resp2.Jobs, 1) require.Equal(t, job.ID, resp2.Jobs[0].ID) require.Equal(t, job.Namespace, resp2.Jobs[0].Namespace) + require.Nil(t, resp2.Jobs[0].Meta) // Lookup the jobs by prefix get = &structs.JobListRequest{ @@ -5129,6 +5130,22 @@ func TestJobEndpoint_ListJobs(t *testing.T) { require.Len(t, resp3.Jobs, 1) require.Equal(t, job.ID, resp3.Jobs[0].ID) require.Equal(t, job.Namespace, resp3.Jobs[0].Namespace) + + // Lookup jobs with a meta parameter + get = &structs.JobListRequest{ + QueryOptions: structs.QueryOptions{ + Region: "global", + Namespace: job.Namespace, + Prefix: resp2.Jobs[0].ID[:4], + }, + Fields: &structs.JobStubFields{ + Meta: true, + }, + } + var resp4 structs.JobListResponse + err = msgpackrpc.CallWithCodec(codec, "Job.List", get, &resp4) + require.NoError(t, err) + require.Equal(t, job.Meta["owner"], resp4.Jobs[0].Meta["owner"]) } // TestJobEndpoint_ListJobs_AllNamespaces_OSS asserts that server diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index cf08db0be1fd..c05f7e1bc622 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -689,6 +689,12 @@ type JobSpecificRequest struct { // JobListRequest is used to parameterize a list request type JobListRequest struct { QueryOptions + Fields *JobStubFields +} + +// Stub returns a summarized version of the job +type JobStubFields struct { + Meta bool } // JobPlanRequest is used for the Job.Plan endpoint to trigger a dry-run @@ -4517,8 +4523,8 @@ func (j *Job) HasUpdateStrategy() bool { } // Stub is used to return a summary of the job -func (j *Job) Stub(summary *JobSummary) *JobListStub { - return &JobListStub{ +func (j *Job) Stub(summary *JobSummary, fields *JobStubFields) *JobListStub { + jobStub := &JobListStub{ ID: j.ID, Namespace: j.Namespace, ParentID: j.ParentID, @@ -4538,6 +4544,14 @@ func (j *Job) Stub(summary *JobSummary) *JobListStub { SubmitTime: j.SubmitTime, JobSummary: summary, } + + if fields != nil { + if fields.Meta { + jobStub.Meta = j.Meta + } + } + + return jobStub } // IsPeriodic returns whether a job is periodic. @@ -4721,6 +4735,7 @@ type JobListStub struct { ModifyIndex uint64 JobModifyIndex uint64 SubmitTime int64 + Meta map[string]string `json:",omitempty"` } // JobSummary summarizes the state of the allocations of a job diff --git a/ui/app/routes/jobs/index.js b/ui/app/routes/jobs/index.js index 93bc9d39e355..f894ba9d2a5a 100644 --- a/ui/app/routes/jobs/index.js +++ b/ui/app/routes/jobs/index.js @@ -22,7 +22,7 @@ export default class IndexRoute extends Route.extend( model(params) { return RSVP.hash({ jobs: this.store - .query('job', { namespace: params.qpNamespace }) + .query('job', { namespace: params.qpNamespace, meta: true }) .catch(notifyForbidden(this)), namespaces: this.store.findAll('namespace'), }); @@ -32,7 +32,7 @@ export default class IndexRoute extends Route.extend( controller.set('namespacesWatch', this.watchNamespaces.perform()); controller.set( 'modelWatch', - this.watchJobs.perform({ namespace: controller.qpNamesapce }) + this.watchJobs.perform({ namespace: controller.qpNamespace, meta: true }) ); } diff --git a/ui/app/routes/jobs/job.js b/ui/app/routes/jobs/job.js index dba817d7bc06..c8f94ae33ed0 100644 --- a/ui/app/routes/jobs/job.js +++ b/ui/app/routes/jobs/job.js @@ -35,7 +35,7 @@ export default class JobRoute extends Route { const relatedModelsQueries = [ job.get('allocations'), job.get('evaluations'), - this.store.query('job', { namespace }), + this.store.query('job', { namespace, meta: true }), this.store.findAll('namespace'), ]; diff --git a/ui/app/routes/jobs/job/index.js b/ui/app/routes/jobs/job/index.js index 2c527ef9f0bb..68ff254dd7d5 100644 --- a/ui/app/routes/jobs/job/index.js +++ b/ui/app/routes/jobs/job/index.js @@ -31,7 +31,10 @@ export default class IndexRoute extends Route.extend(WithWatchers) { this.watchLatestDeployment.perform(model), list: model.get('hasChildren') && - this.watchAllJobs.perform({ namespace: model.namespace.get('name') }), + this.watchAllJobs.perform({ + namespace: model.namespace.get('name'), + meta: true, + }), nodes: model.get('hasClientStatus') && this.can.can('read client') && diff --git a/ui/app/styles/core/tag.scss b/ui/app/styles/core/tag.scss index 4682b8bdba1d..aa1b627d5cd6 100644 --- a/ui/app/styles/core/tag.scss +++ b/ui/app/styles/core/tag.scss @@ -68,6 +68,11 @@ vertical-align: 2px; } + &.is-pack { + position: relative; + top: 3px; + } + .icon { height: 1rem; width: 1rem; diff --git a/ui/app/templates/components/job-row.hbs b/ui/app/templates/components/job-row.hbs index f2212ebdf7eb..7031db97cb51 100644 --- a/ui/app/templates/components/job-row.hbs +++ b/ui/app/templates/components/job-row.hbs @@ -10,6 +10,14 @@ class="is-primary" > {{this.job.name}} + + {{#if this.job.meta.structured.pack}} + + {{x-icon "box" class= "test"}} + Pack + + {{/if}} + {{#if this.system.shouldShowNamespaces}} diff --git a/website/content/api-docs/jobs.mdx b/website/content/api-docs/jobs.mdx index e8339a85901a..aefb12651eb4 100644 --- a/website/content/api-docs/jobs.mdx +++ b/website/content/api-docs/jobs.mdx @@ -46,6 +46,8 @@ The table below shows this endpoint's support for - `namespace` `(string: "default")` - Specifies the target namespace. Specifying `*` would return all jobs across all the authorized namespaces. +- `meta` `(bool: false)` - If set, jobs returned will include a [meta](/docs/job-specification/meta) field containing all + ### Sample Request ```shell-session