fix broken link to `task-group` in `Recent Allocation` table in `jobs.job.index` (#12765)

* chore:  run prettier on hbs files

* ui:  ensure to pass a real job object to task-group link

* chore:  add changelog entry

* chore: prettify template

* ui:  template helper for formatting jobId in LinkTo component

* ui:  handle async relationship

* ui:  pass in job id to model arg instead of job model

* update test for serialized namespace

* ui:  defend against null  in tests

* ui:  prettified template added whitespace

* ui:  rollback ember-data to 3.24 because watcher return undefined on abort

* ui: use format-job-helper instead of job model via alloc

* ui: fix whitespace in template caused by prettier using template helper

* ui: update test for new namespace

* ui: revert prettier change

Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
This commit is contained in:
Jai 2022-04-28 14:02:15 -04:00 committed by GitHub
parent 97cf204c00
commit 316daf581e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1214 additions and 327 deletions

3
.changelog/12765.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
ui: fix broken link to task-groups in the Recent Allocations table in the Job Detail overview page.
```

View File

@ -0,0 +1,8 @@
import Helper from '@ember/component/helper';
export function formatJobId([jobId]) {
if (!jobId) return;
return JSON.parse(jobId).join('@');
}
export default Helper.helper(formatJobId);

View File

@ -17,12 +17,13 @@ export default class AllocationRoute extends Route.extend(WithWatchers) {
// Preload the job for the allocation since it's required for the breadcrumb trail
return super
.model(...arguments)
.then((allocation) =>
allocation
.get('job')
.then((allocation) => {
const jobId = allocation.belongsTo('job').id();
return this.store
.findRecord('job', jobId)
.then(() => this.store.findAll('namespace')) // namespaces belong to a job and are an asynchronous relationship so we can peak them later on
.then(() => allocation)
)
.then(() => allocation);
})
.catch(notifyError(this));
}

View File

@ -5,11 +5,12 @@
<div data-test-inline-error class="notification is-danger">
<div class="columns">
<div class="column">
<h3
data-test-inline-error-title
class="title is-4"
>{{this.error.title}}</h3>
<p data-test-inline-error-body>{{this.error.description}}</p>
<h3 data-test-inline-error-title class="title is-4">
{{this.error.title}}
</h3>
<p data-test-inline-error-body>
{{this.error.description}}
</p>
</div>
<div class="column is-centered is-minimum">
<button
@ -17,19 +18,20 @@
class="button is-danger"
onclick={{action this.onDismiss}}
type="button"
>Okay</button>
>
Okay
</button>
</div>
</div>
</div>
{{/if}}
<h1 data-test-title class="title with-headroom with-flex">
<div>
Allocation
{{this.model.name}}
<span
class="bumper-left tag {{this.model.statusClass}}"
>{{this.model.clientStatus}}</span>
<span class="bumper-left tag {{this.model.statusClass}}">
{{this.model.clientStatus}}
</span>
</div>
<div>
{{#if this.model.isRunning}}
@ -70,35 +72,44 @@
{{/if}}
</div>
</h1>
<span class="tag is-hollow is-small is-alone no-text-transform">
{{this.model.id}}
<CopyButton @clipboardText={{this.model.id}} />
</span>
<div class="boxed-section is-small">
<div
data-test-allocation-details
class="boxed-section-body inline-definitions"
>
<span class="label">Allocation Details</span>
<span class="pair job-link"><span class="term">Job</span>
<span class="label">
Allocation Details
</span>
<span class="pair job-link">
<span class="term">
Job
</span>
<LinkTo
@route="jobs.job"
@model={{this.model.job}}
@model={{format-job-id this.model.job.id}}
data-test-job-link
>{{this.model.job.name}}</LinkTo>
>
{{this.model.job.name}}
</LinkTo>
</span>
<span class="pair node-link"><span class="term">Client</span>
<span class="pair node-link">
<span class="term">
Client
</span>
<LinkTo
@route="clients.client"
@model={{this.model.node}}
data-test-client-link
>{{this.model.node.shortId}}</LinkTo>
>
{{this.model.node.shortId}}
</LinkTo>
</span>
</div>
</div>
<div class="boxed-section">
<div class="boxed-section-head is-hollow">
Resource Utilization
@ -121,43 +132,55 @@
</div>
{{else}}
<div data-test-resource-error class="empty-message">
<h3
data-test-resource-error-headline
class="empty-message-headline"
>Allocation isn't running</h3>
<p class="empty-message-body">Only running allocations utilize
resources.</p>
<h3 data-test-resource-error-headline class="empty-message-headline">
Allocation isn't running
</h3>
<p class="empty-message-body">
Only running allocations utilize
resources.
</p>
</div>
{{/if}}
</div>
</div>
<LifecycleChart @taskStates={{this.model.states}} />
<div class="boxed-section">
<div class="boxed-section-head">
Tasks
</div>
<div
class="boxed-section-body {{if this.sortedStates.length 'is-full-bleed'}}"
class="boxed-section-body {{if this.sortedStates.length "is-full-bleed"}}"
>
{{#if this.sortedStates.length}}
<ListTable
@source={{this.sortedStates}}
@sortProperty={{this.sortProperty}}
@sortDescending={{this.sortDescending}}
@class="is-striped"
as |t|
@class="is-striped" as |t|
>
<t.head>
<th class="is-narrow"></th>
<t.sort-by @prop="name">Name</t.sort-by>
<t.sort-by @prop="state">State</t.sort-by>
<th>Last Event</th>
<t.sort-by @prop="events.lastObject.time">Time</t.sort-by>
<th>Volumes</th>
<th>CPU</th>
<th>Memory</th>
<t.sort-by @prop="name">
Name
</t.sort-by>
<t.sort-by @prop="state">
State
</t.sort-by>
<th>
Last Event
</th>
<t.sort-by @prop="events.lastObject.time">
Time
</t.sort-by>
<th>
Volumes
</th>
<th>
CPU
</th>
<th>
Memory
</th>
</t.head>
<t.body as |row|>
<TaskRow
@ -172,16 +195,16 @@
<h3
data-test-empty-tasks-list-headline
class="empty-message-headline"
>No Tasks</h3>
<p
data-test-empty-tasks-list-body
class="empty-message-body"
>Allocations will not have tasks until they are in a running state.</p>
>
No Tasks
</h3>
<p data-test-empty-tasks-list-body class="empty-message-body">
Allocations will not have tasks until they are in a running state.
</p>
</div>
{{/if}}
</div>
</div>
{{#if this.ports.length}}
<div class="boxed-section" data-test-allocation-ports>
<div class="boxed-section-head">
@ -190,28 +213,39 @@
<div class="boxed-section-body is-full-bleed">
<ListTable @source={{this.ports}} as |t|>
<t.head>
<th>Name</th>
<th>Host Address</th>
<th>Mapped Port</th>
<th>
Name
</th>
<th>
Host Address
</th>
<th>
Mapped Port
</th>
</t.head>
<t.body as |row|>
<tr data-test-allocation-port>
<td data-test-allocation-port-name>{{row.model.label}}</td>
<td data-test-allocation-port-name>
{{row.model.label}}
</td>
<td data-test-allocation-port-address>
<a
href="http://{{row.model.hostIp}}:{{row.model.value}}"
target="_blank"
rel="noopener noreferrer"
>{{row.model.hostIp}}:{{row.model.value}}</a>
>
{{row.model.hostIp}}:{{row.model.value}}
</a>
</td>
<td data-test-allocation-port-to>
{{row.model.to}}
</td>
<td data-test-allocation-port-to>{{row.model.to}}</td>
</tr>
</t.body>
</ListTable>
</div>
</div>
{{/if}}
{{#if this.services.length}}
<div class="boxed-section">
<div class="boxed-section-head">
@ -220,31 +254,45 @@
<div class="boxed-section-body is-full-bleed">
<ListTable @source={{this.services}} as |t|>
<t.head>
<th class="is-2">Name</th>
<th class="is-1">Port</th>
<td>Tags</td>
<td>On Update</td>
<td>Connect?</td>
<td>Upstreams</td>
<th class="is-2">
Name
</th>
<th class="is-1">
Port
</th>
<td>
Tags
</td>
<td>
On Update
</td>
<td>
Connect?
</td>
<td>
Upstreams
</td>
</t.head>
<t.body as |row|>
<tr data-test-service>
<td data-test-service-name>{{row.model.name}}</td>
<td data-test-service-port>{{row.model.portLabel}}</td>
<td data-test-service-tags class="is-long-text">{{join
", "
row.model.tags
}}</td>
<td data-test-service-onupdate>{{row.model.onUpdate}}</td>
<td data-test-service-connect>{{if
row.model.connect
"Yes"
"No"
}}</td>
<td data-test-service-name>
{{row.model.name}}
</td>
<td data-test-service-port>
{{row.model.portLabel}}
</td>
<td data-test-service-tags class="is-long-text">
{{join ", " row.model.tags}}
</td>
<td data-test-service-onupdate>
{{row.model.onUpdate}}
</td>
<td data-test-service-connect>
{{if row.model.connect "Yes" "No"}}
</td>
<td data-test-service-upstreams>
{{#each
row.model.connect.sidecarService.proxy.upstreams
as |upstream|
row.model.connect.sidecarService.proxy.upstreams as |upstream|
}}
{{upstream.destinationName}}:{{upstream.localBindPort}}
{{/each}}
@ -255,7 +303,6 @@
</div>
</div>
{{/if}}
{{#if this.model.hasRescheduleEvents}}
<div class="boxed-section" data-test-reschedule-events>
<div class="boxed-section-head is-hollow">
@ -266,10 +313,11 @@
</div>
</div>
{{/if}}
{{#if this.model.wasPreempted}}
<div class="boxed-section is-warning" data-test-was-preempted>
<div class="boxed-section-head">Preempted By</div>
<div class="boxed-section-head">
Preempted By
</div>
<div class="boxed-section-body">
{{#if this.preempter}}
<div class="boxed-section is-small">
@ -283,59 +331,84 @@
</span>
</span>
<span class="pair">
<span
class="term"
data-test-allocation-name
>{{this.preempter.name}}</span>
<span class="term" data-test-allocation-name>
{{this.preempter.name}}
</span>
<LinkTo
@route="allocations.allocation"
@model={{this.preempter}}
data-test-allocation-id
>{{this.preempter.shortId}}</LinkTo>
>
{{this.preempter.shortId}}
</LinkTo>
</span>
<span class="pair job-link"><span class="term">Job</span>
<span class="pair job-link">
<span class="term">
Job
</span>
<LinkTo
@route="jobs.job"
@model={{this.preempter.job}}
data-test-job-link
>{{this.preempter.job.name}}</LinkTo>
>
{{this.preempter.job.name}}
</LinkTo>
</span>
<span class="pair job-priority"><span class="term">Priority</span>
<span
data-test-job-priority
>{{this.preempter.job.priority}}</span>
<span class="pair job-priority">
<span class="term">
Priority
</span>
<span data-test-job-priority>
{{this.preempter.job.priority}}
</span>
</span>
<span class="pair node-link"><span class="term">Client</span>
<span class="pair node-link">
<span class="term">
Client
</span>
<LinkTo
@route="clients.client"
@model={{this.preempter.node}}
data-test-client-link
>{{this.preempter.node.shortId}}</LinkTo>
>
{{this.preempter.node.shortId}}
</LinkTo>
</span>
<span class="pair"><span class="term">Reserved CPU</span>
<span data-test-allocation-cpu>{{format-scheduled-hertz
this.preempter.resources.cpu
}}</span>
<span class="pair">
<span class="term">
Reserved CPU
</span>
<span data-test-allocation-cpu>
{{format-scheduled-hertz this.preempter.resources.cpu}}
</span>
</span>
<span class="pair"><span class="term">Reserved Memory</span>
<span data-test-allocation-memory>{{format-scheduled-bytes
<span class="pair">
<span class="term">
Reserved Memory
</span>
<span data-test-allocation-memory>
{{format-scheduled-bytes
this.preempter.resources.memory
start="MiB"
}}</span>
}}
</span>
</span>
</div>
</div>
{{else}}
<div class="empty-message">
<h3 class="empty-message-headline">Allocation is gone</h3>
<p class="empty-message-body">This allocation has been stopped and
garbage collected.</p>
<h3 class="empty-message-headline">
Allocation is gone
</h3>
<p class="empty-message-body">
This allocation has been stopped and
garbage collected.
</p>
</div>
{{/if}}
</div>
</div>
{{/if}}
{{#if
(and
this.model.preemptedAllocations.isFulfilled
@ -343,24 +416,43 @@
)
}}
<div class="boxed-section" data-test-preemptions>
<div class="boxed-section-head">Preempted Allocations</div>
<div class="boxed-section-head">
Preempted Allocations
</div>
<div class="boxed-section-body">
<ListTable
@source={{this.model.preemptedAllocations}}
@class="allocations is-isolated"
as |t|
@class="allocations is-isolated" as |t|
>
<t.head>
<th class="is-narrow"></th>
<th>ID</th>
<th>Task Group</th>
<th>Created</th>
<th>Modified</th>
<th>Status</th>
<th>Version</th>
<th>Node</th>
<th>CPU</th>
<th>Memory</th>
<th>
ID
</th>
<th>
Task Group
</th>
<th>
Created
</th>
<th>
Modified
</th>
<th>
Status
</th>
<th>
Version
</th>
<th>
Node
</th>
<th>
CPU
</th>
<th>
Memory
</th>
</t.head>
<t.body as |row|>
<AllocationRow

View File

@ -1,40 +1,71 @@
<td data-test-indicators class="is-narrow">
{{#if this.allocation.unhealthyDrivers.length}}
<span data-test-icon="unhealthy-driver" class="tooltip text-center" role="tooltip" aria-label="Allocation depends on unhealthy drivers">
<span
data-test-icon="unhealthy-driver"
class="tooltip text-center"
role="tooltip"
aria-label="Allocation depends on unhealthy drivers"
>
{{x-icon "alert-triangle" class="is-warning"}}
</span>
{{/if}}
{{#if this.allocation.nextAllocation}}
<span data-test-icon="reschedule" class="tooltip text-center" role="tooltip" aria-label="Allocation was rescheduled">
<span
data-test-icon="reschedule"
class="tooltip text-center"
role="tooltip"
aria-label="Allocation was rescheduled"
>
{{x-icon "history" class="is-faded"}}
</span>
{{/if}}
{{#if this.allocation.wasPreempted}}
<span data-test-icon="preemption" class="tooltip text-center" role="tooltip" aria-label="Allocation was preempted">
<span
data-test-icon="preemption"
class="tooltip text-center"
role="tooltip"
aria-label="Allocation was preempted"
>
{{x-icon "boot" class="is-faded"}}
</span>
{{/if}}
</td>
<td data-test-short-id>
<LinkTo @route="allocations.allocation" @model={{this.allocation}} class="is-primary">
<LinkTo
@route="allocations.allocation"
@model={{this.allocation}}
class="is-primary"
>
{{this.allocation.shortId}}
</LinkTo>
</td>
{{#if (eq this.context "job")}}
<td data-test-task-group>
<LinkTo @route="jobs.job.task-group" @models={{array this.allocation.job this.allocation.taskGroupName}} @query={{hash jobNamespace=this.allocation.job.namespace.id}}>
<LinkTo
@route="jobs.job.task-group"
@models={{array
(format-job-id this.allocation.job.id)
this.allocation.taskGroupName
}}
>
{{this.allocation.taskGroupName}}
</LinkTo>
</td>
{{/if}}
<td data-test-create-time>{{format-month-ts this.allocation.createTime}}</td>
<td data-test-create-time>
{{format-month-ts this.allocation.createTime}}
</td>
<td data-test-modify-time>
<span class="tooltip" aria-label="{{format-month-ts this.allocation.modifyTime}}">
<span
class="tooltip"
aria-label="{{format-month-ts this.allocation.modifyTime}}"
>
{{moment-from-now this.allocation.modifyTime}}
</span>
</td>
<td data-test-client-status class="is-one-line">
<span class="color-swatch {{this.allocation.clientStatus}}" /> {{this.allocation.clientStatus}}
<span class="color-swatch {{this.allocation.clientStatus}}"></span>
{{this.allocation.clientStatus}}
</td>
{{#if (eq this.context "volume")}}
<td data-test-client>
@ -46,7 +77,9 @@
</td>
{{/if}}
{{#if (or (eq this.context "taskGroup") (eq this.context "job"))}}
<td data-test-job-version>{{this.allocation.jobVersion}}</td>
<td data-test-job-version>
{{this.allocation.jobVersion}}
</td>
<td data-test-client>
<Tooltip @text={{this.allocation.node.name}}>
<LinkTo @route="clients.client" @model={{this.allocation.node}}>
@ -59,14 +92,27 @@
{{#if (or this.allocation.job.isPending this.allocation.job.isReloading)}}
...
{{else}}
<LinkTo @route="jobs.job" @model={{this.allocation.job}} @query={{hash jobNamespace=this.allocation.job.namespace.id}} data-test-job>{{this.allocation.job.name}}</LinkTo>
<span class="is-faded" data-test-task-group>/ {{this.allocation.taskGroup.name}}</span>
<LinkTo
@route="jobs.job"
@model={{format-job-id this.allocation.job.id}}
data-test-job
>
{{this.allocation.job.name}}
</LinkTo>
<span class="is-faded" data-test-task-group>
/
{{this.allocation.taskGroup.name}}
</span>
{{/if}}
</td>
<td data-test-job-version class="is-1">{{this.allocation.jobVersion}}</td>
<td data-test-job-version class="is-1">
{{this.allocation.jobVersion}}
</td>
{{/if}}
{{#if (not (eq this.context "volume"))}}
<td data-test-volume>{{if this.allocation.taskGroup.volumes.length "Yes"}}</td>
<td data-test-volume>
{{if this.allocation.taskGroup.volumes.length "Yes"}}
</td>
{{/if}}
<td data-test-cpu class="is-1 has-text-centered">
<AllocationStat
@ -74,7 +120,8 @@
@allocation={{this.allocation}}
@statsTracker={{this.stats}}
@isLoading={{this.fetchStats.isRunning}}
@error={{this.statsError}} />
@error={{this.statsError}}
/>
</td>
<td data-test-mem class="is-1 has-text-centered">
<AllocationStat
@ -82,5 +129,6 @@
@allocation={{this.allocation}}
@statsTracker={{this.stats}}
@isLoading={{this.fetchStats.isRunning}}
@error={{this.statsError}} />
@error={{this.statsError}}
/>
</td>

View File

@ -2,46 +2,85 @@
<div class="boxed-section-head">
Recent Allocations
</div>
<div class="boxed-section-body {{if this.job.allocations.length "is-full-bleed"}}">
<div
class="boxed-section-body
{{if this.job.allocations.length "is-full-bleed"}}"
>
{{#if this.job.allocations.length}}
<ListTable
@source={{this.sortedAllocations}}
@sortProperty={{this.sortProperty}}
@sortDescending={{this.sortDescending}}
@class="with-foot" as |t|>
@class="with-foot" as |t|
>
<t.head>
<th class="is-narrow"></th>
<th>ID</th>
<th>Task Group</th>
<th>Created</th>
<th>Modified</th>
<th>Status</th>
<th>Version</th>
<th>Client</th>
<th>Volume</th>
<th>CPU</th>
<th>Memory</th>
<th>
ID
</th>
<th>
Task Group
</th>
<th>
Created
</th>
<th>
Modified
</th>
<th>
Status
</th>
<th>
Version
</th>
<th>
Client
</th>
<th>
Volume
</th>
<th>
CPU
</th>
<th>
Memory
</th>
</t.head>
<t.body as |row|>
<AllocationRow
@data-test-allocation={{row.model.id}}
@allocation={{row.model}}
@context="job"
@onClick={{action "gotoAllocation" row.model}} />
@onClick={{action "gotoAllocation" row.model}}
/>
</t.body>
</ListTable>
{{else}}
<div class="empty-message" data-test-empty-recent-allocations>
<h3 class="empty-message-headline" data-test-empty-recent-allocations-headline>No Allocations</h3>
<p class="empty-message-body" data-test-empty-recent-allocations-message>No allocations have been placed.</p>
<h3
class="empty-message-headline"
data-test-empty-recent-allocations-headline
>
No Allocations
</h3>
<p
class="empty-message-body"
data-test-empty-recent-allocations-message
>
No allocations have been placed.
</p>
</div>
{{/if}}
</div>
{{#if this.job.allocations.length}}
<div class="boxed-section-foot">
<p class="pull-right" data-test-view-all-allocations><LinkTo @route="jobs.job.allocations" @model={{this.job}}>
View all {{this.job.allocations.length}} {{pluralize "allocation" this.job.allocations.length}}
</LinkTo></p>
<p class="pull-right" data-test-view-all-allocations>
<LinkTo @route="jobs.job.allocations" @model={{this.job}}>
View all
{{this.job.allocations.length}}
{{pluralize "allocation" this.job.allocations.length}}
</LinkTo>
</p>
</div>
{{/if}}
</div>

View File

@ -42,7 +42,7 @@
<li data-test-tab="allocations">
<LinkTo
@route="jobs.job.allocations"
@model={{@job}}
@model={{format-job-id @job.id}}
@activeClass="is-active"
>
Allocations

View File

@ -84,7 +84,7 @@
"ember-composable-helpers": "^5.0.0",
"ember-concurrency": "^2.2.1",
"ember-copy": "^2.0.1",
"ember-data": "~3.28.6",
"ember-data": "~3.24",
"ember-data-model-fragments": "5.0.0-beta.3",
"ember-decorators": "^6.1.1",
"ember-exam": "6.1.0",

View File

@ -76,7 +76,7 @@ module('Acceptance | allocation detail', function (hooks) {
await Allocation.details.visitJob();
assert.equal(
currentURL(),
`/jobs/${job.id}`,
`/jobs/${job.id}@default`,
'Job link navigates to the job'
);

View File

@ -305,7 +305,7 @@ module('Acceptance | client detail', function (hooks) {
assert.equal(
currentURL(),
`/jobs/${job.id}`,
`/jobs/${job.id}@default`,
'Allocation rows link to the job detail page for the allocation'
);
});

File diff suppressed because it is too large Load Diff