Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Recent allocs + job allocs view #4529

Merged
merged 17 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},
rules: {
indent: ['error', 2, { SwitchCase: 1 }],
Expand Down
24 changes: 24 additions & 0 deletions ui/app/components/job-page/parts/recent-allocations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import PromiseArray from 'nomad-ui/utils/classes/promise-array';

export default Component.extend({
sortProperty: 'modifyIndex',
sortDescending: true,
sortedAllocations: computed('job.allocations.@each.modifyIndex', function() {
return new PromiseArray({
promise: this.get('job.allocations').then(allocations =>
allocations
.sortBy('modifyIndex')
.reverse()
.slice(0, 5)
),
});
}),
Copy link
Contributor

@johncowen johncowen Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just about of interest, what's the reason for the PromiseArray? I'm guessing the allocations might not be loaded yet when you ask to sort them or something? If you have a sec would be good to get an understanding, no prob if not.

I had a quick look at some other sorting you are doing and none of them use this, are allocations different or is this something you are going to be moving to across the board?

P.S.(edit) Sorry funny the way GH does this, the preview from GH doesn't help here 😄 probably need to view a few lines up also for this to make sense!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually just noticed also, looks like job is an attribute on the component (job="job") and then you are reaching up into the job to get the allocations. Just an offshoot, would an alternative be allocations={{job.allocations}} so you are sending the data down? Not sure if that is workable for you or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it isn't clear, the PromiseArray object makes it so the returned value always has an array-like interface before and after the promise resolves.

This isn't important elsewhere because RecordArray (either from store.findAll or model.get('asyncHasMany') are used in templates.

Here, additional transformations need to happen (sortBy, reverse, slice).

If the promise isn't resolved yet, this breaks because it's not an array yet. Simply doing this.get('job.allocations').then(allocations => allocations.transformations) also doesn't work because the computed property now returns a promise. The template can't do anything with the promise and the computed property doesn't update when the promise resolves.

By using a PromiseArray, I can do the promise control flow while also ensuring an Array interface as well as a template re-render when the promise resolves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use allocations=job.allocations, and that may be better. Specifically because of the principle of least authority. I chose to use job=job to make all the various job-page/parts components feel similar.

I don't think this violates data-down actions-up because it isn't reaching up into a higher viewer (e.g., allocations: alias('parentView.job.allocations')). Instead, a larger than necessary piece of data is being provided to the component and the component is reaching down in that data.

I'm willing to talk about this more if you wish. I know it's pretty nuanced.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the further detail.

I'm willing to talk about this more if you wish. I know it's pretty nuanced.

It's fine I'm not fussed, just thought I'd highlight a alternative approach if it helps. If you decide to go that route at some point and you want to chat then quite happy to, no prob if not.

Back to the PR - Ping me when you tweak the search thing so you can undo your search when there are no results, and I can give it another once over.

Thanks,


actions: {
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
},
},
});
39 changes: 39 additions & 0 deletions ui/app/controllers/jobs/job/allocations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';

export default Controller.extend(Sortable, Searchable, WithNamespaceResetting, {
queryParams: {
currentPage: 'page',
searchTerm: 'search',
sortProperty: 'sort',
sortDescending: 'desc',
},

currentPage: 1,
pageSize: 25,

sortProperty: 'modifyIndex',
sortDescending: true,

job: alias('model'),

searchProps: computed(() => ['shortId', 'name', 'taskGroupName']),

allocations: computed('model.allocations.[]', function() {
return this.get('model.allocations') || [];
}),

listToSort: alias('allocations'),
listToSearch: alias('listSorted'),
sortedAllocations: alias('listSearched'),

actions: {
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
},
},
});
6 changes: 5 additions & 1 deletion ui/app/models/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ export default Model.extend({
name: attr('string'),
taskGroupName: attr('string'),
resources: fragment('resources'),
jobVersion: attr('number'),

modifyIndex: attr('number'),
modifyTime: attr('date'),
jobVersion: attr('number'),

createIndex: attr('number'),
createTime: attr('date'),

clientStatus: attr('string'),
desiredStatus: attr('string'),
Expand Down
1 change: 1 addition & 0 deletions ui/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Router.map(function() {
this.route('versions');
this.route('deployments');
this.route('evaluations');
this.route('allocations');
});
});

Expand Down
19 changes: 19 additions & 0 deletions ui/app/routes/jobs/job/allocations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend(WithWatchers, {
model() {
const job = this.modelFor('jobs.job');
return job.get('allocations').then(() => job);
},

startWatchers(controller, model) {
controller.set('watchAllocations', this.get('watchAllocations').perform(model));
},

watchAllocations: watchRelationship('allocations'),

watchers: collect('watchAllocations'),
});
3 changes: 3 additions & 0 deletions ui/app/routes/jobs/job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default Route.extend(WithWatchers, {
controller.set('watchers', {
model: this.get('watch').perform(model),
summary: this.get('watchSummary').perform(model.get('summary')),
allocations: this.get('watchAllocations').perform(model),
evaluations: this.get('watchEvaluations').perform(model),
latestDeployment:
model.get('supportsDeployments') && this.get('watchLatestDeployment').perform(model),
Expand All @@ -21,13 +22,15 @@ export default Route.extend(WithWatchers, {
watch: watchRecord('job'),
watchAll: watchAll('job'),
watchSummary: watchRecord('job-summary'),
watchAllocations: watchRelationship('allocations'),
watchEvaluations: watchRelationship('evaluations'),
watchLatestDeployment: watchRelationship('latestDeployment'),

watchers: collect(
'watch',
'watchAll',
'watchSummary',
'watchAllocations',
'watchEvaluations',
'watchLatestDeployment'
),
Expand Down
3 changes: 3 additions & 0 deletions ui/app/serializers/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default ApplicationSerializer.extend({
hash.ModifyTimeNanos = hash.ModifyTime % 1000000;
hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000);

hash.CreateTimeNanos = hash.CreateTime % 1000000;
hash.CreateTime = Math.floor(hash.CreateTime / 1000000);

hash.RescheduleEvents = (hash.RescheduleTracker || {}).Events;

// API returns empty strings instead of null
Expand Down
10 changes: 7 additions & 3 deletions ui/app/styles/charts.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@import "./charts/distribution-bar";
@import "./charts/tooltip";
@import "./charts/colors";
@import './charts/distribution-bar';
@import './charts/tooltip';
@import './charts/colors';

.inline-chart {
height: 1.5rem;
display: flex;
align-items: center;

&.is-small {
width: 50px;
}
}

// Patterns are templates referenced by other SVG fill properties.
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/clients/client.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<th class="is-narrow"></th>
{{#t.sort-by prop="shortId"}}ID{{/t.sort-by}}
{{#t.sort-by prop="modifyIndex" title="Modify Index"}}Modified{{/t.sort-by}}
{{#t.sort-by prop="name"}}Name{{/t.sort-by}}
{{#t.sort-by prop="createIndex" title="Create Index"}}Created{{/t.sort-by}}
{{#t.sort-by prop="statusIndex"}}Status{{/t.sort-by}}
{{#t.sort-by prop="job.name"}}Job{{/t.sort-by}}
{{#t.sort-by prop="jobVersion"}}Version{{/t.sort-by}}
Expand Down
23 changes: 15 additions & 8 deletions ui/app/templates/components/allocation-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
{{allocation.shortId}}
{{/link-to}}
</td>
<td data-test-modify-time>{{moment-format allocation.modifyTime "MM/DD HH:mm:ss"}}</td>
<td data-test-name>{{allocation.name}}</td>
{{#if (eq context "job")}}
<td data-test-task-group>
{{#link-to "jobs.job.task-group" allocation.job allocation.taskGroupName (query-params jobNamespace=allocation.job.namespace.id)}}
{{allocation.taskGroupName}}
{{/link-to}}
</td>
{{/if}}
<td data-test-create-time>{{moment-format allocation.createTime "MM/DD HH:mm:ss"}}</td>
<td data-test-modify-time>{{moment-from-now allocation.modifyTime}}</td>
<td data-test-client-status class="is-one-line">
<span class="color-swatch {{allocation.clientStatus}}" /> {{allocation.clientStatus}}
</td>
{{#if (eq context "job")}}
{{#if (or (eq context "taskGroup") (eq context "job"))}}
<td data-test-job-version>{{allocation.jobVersion}}</td>
<td data-test-client>{{#link-to "clients.client" allocation.node}}{{allocation.node.shortId}}{{/link-to}}</td>
{{else if (eq context "node")}}
Expand All @@ -32,9 +39,9 @@
<span class="is-faded" data-test-task-group>/ {{allocation.taskGroup.name}}</span>
{{/if}}
</td>
<td data-test-job-version>{{allocation.jobVersion}}</td>
<td data-test-job-version class="is-1">{{allocation.jobVersion}}</td>
{{/if}}
<td data-test-cpu class="has-text-centered">
<td data-test-cpu class="is-1 has-text-centered">
{{#if (and (not stats) fetchStats.isRunning)}}
...
{{else if (not allocation)}}
Expand All @@ -44,7 +51,7 @@
{{x-icon "warning" class="is-warning"}}
</span>
{{else}}
<div class="inline-chart tooltip" aria-label="{{stats.cpuUsed}} / {{stats.reservedCPU}} MHz">
<div class="inline-chart is-small tooltip" aria-label="{{stats.cpuUsed}} / {{stats.reservedCPU}} MHz">
<progress
class="progress is-info is-small"
value="{{stats.percentCPU}}"
Expand All @@ -54,13 +61,13 @@
</div>
{{/if}}
</td>
<td data-test-mem class="has-text-centered">
<td data-test-mem class="is-1 has-text-centered">
{{#if (and (not stats) fetchStats.isRunning)}}
...
{{else if (not allocation)}}
{{! nothing when there's no allocation}}
{{else if statsError}}
<span class="tooltip text-center" aria-label="Couldn't collect stats">
<span class="tooltip is-small text-center" aria-label="Couldn't collect stats">
{{x-icon "warning" class="is-warning"}}
</span>
{{else}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
{{#t.head}}
<th class="is-narrow"></th>
<th>ID</th>
<th>Task Group</th>
<th>Created</th>
<th>Modified</th>
<th>Name</th>
<th>Status</th>
<th>Version</th>
<th>Node</th>
Expand Down
2 changes: 2 additions & 0 deletions ui/app/templates/components/job-page/batch.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
sortProperty=sortProperty
sortDescending=sortDescending
gotoTaskGroup=gotoTaskGroup}}

{{job-page/parts/recent-allocations job=job}}
{{/job-page/parts/body}}
2 changes: 2 additions & 0 deletions ui/app/templates/components/job-page/parameterized-child.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
sortDescending=sortDescending
gotoTaskGroup=gotoTaskGroup}}

{{job-page/parts/recent-allocations job=job}}

<div class="boxed-section">
<div class="boxed-section-head">Payload</div>
<div class="boxed-section-body is-dark">
Expand Down
46 changes: 46 additions & 0 deletions ui/app/templates/components/job-page/parts/recent-allocations.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="boxed-section">
<div class="boxed-section-head">
Recent Allocations
</div>
<div class="boxed-section-body is-full-bleed">
{{#if job.allocations.length}}
{{#list-table
source=sortedAllocations
sortProperty=sortProperty
sortDescending=sortDescending
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>CPU</th>
<th>Memory</th>
{{/t.head}}
{{#t.body as |row|}}
{{allocation-row
data-test-allocation=row.model.id
allocation=row.model
context="job"
onClick=(action "gotoAllocation" row.model)}}
{{/t.body}}
{{/list-table}}
{{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>
</div>
{{/if}}
</div>
{{#if job.allocations.length}}
<div class="boxed-section-foot">
<p class="pull-right" data-test-view-all-allocations>{{#link-to "jobs.job.allocations" job}}
View all {{job.allocations.length}} {{pluralize "allocation" job.allocations.length}}
{{/link-to}}</p>
</div>
{{/if}}
</div>
2 changes: 2 additions & 0 deletions ui/app/templates/components/job-page/periodic-child.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
sortProperty=sortProperty
sortDescending=sortDescending
gotoTaskGroup=gotoTaskGroup}}

{{job-page/parts/recent-allocations job=job}}
{{/job-page/parts/body}}
2 changes: 2 additions & 0 deletions ui/app/templates/components/job-page/service.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
sortProperty=sortProperty
sortDescending=sortDescending
gotoTaskGroup=gotoTaskGroup}}

{{job-page/parts/recent-allocations job=job}}
{{/job-page/parts/body}}
2 changes: 2 additions & 0 deletions ui/app/templates/components/job-page/system.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
sortProperty=sortProperty
sortDescending=sortDescending
gotoTaskGroup=gotoTaskGroup}}

{{job-page/parts/recent-allocations job=job}}
{{/job-page/parts/body}}
Loading