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 Use ModifyTime instead of ModifyIndex in allocation lists #3607

Merged
merged 1 commit into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions ui/app/models/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default Model.extend({
taskGroupName: attr('string'),
resources: fragment('resources'),
modifyIndex: attr('number'),
modifyTime: attr('date'),
jobVersion: attr('number'),

// TEMPORARY: https://github.com/emberjs/data/issues/5209
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 @@ -35,6 +35,9 @@ export default ApplicationSerializer.extend({
// TEMPORARY: https://github.com/emberjs/data/issues/5209
hash.OriginalJobId = hash.JobID;

hash.ModifyTimeNanos = hash.ModifyTime % 1000000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ever think of using exponential notation for this or a constant of some sort? Could just be me, but counting the zeros makes me squint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I suppose it's about time to turn this into a function. Something like

const { datetime, nanos } = nsToDate(hash.ModifyTime);

hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000);

return this._super(typeHash, hash);
},
});
2 changes: 1 addition & 1 deletion ui/app/serializers/task-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default ApplicationSerializer.extend({
// only understand time to the millisecond precision. So store
// the time (precise to ms) as a date, and store the remaining ns
// as a number to deal with when it comes up.
hash.Time = Math.floor(hash.Time / 1000000);
hash.TimeNanos = hash.Time % 1000000;
hash.Time = Math.floor(hash.Time / 1000000);

return this._super(typeHash, hash);
},
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/allocation-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{allocation.shortId}}
{{/link-to}}
</td>
<td>{{allocation.modifyIndex}}</td>
<td>{{moment-format allocation.modifyTime "MM/DD HH:mm:ss"}}</td>
<td>{{allocation.name}}</td>
<td>
<span class="color-swatch {{allocation.clientStatus}}" /> {{allocation.clientStatus}}
Expand Down
3 changes: 3 additions & 0 deletions ui/mirage/factories/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { provide, pickOne } from '../utils';
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
const CLIENT_STATUSES = ['pending', 'running', 'complete', 'failed', 'lost'];
const DESIRED_STATUSES = ['run', 'stop', 'evict'];
const REF_TIME = new Date();

export default Factory.extend({
id: i => (i >= 100 ? `${UUIDS[i % 100]}-${i}` : UUIDS[i]),

modifyIndex: () => faker.random.number({ min: 10, max: 2000 }),
jobVersion: () => faker.random.number(10),

modifyTime: () => faker.date.past(2 / 365, REF_TIME) * 1000000,

clientStatus: faker.list.random(...CLIENT_STATUSES),
desiredStatus: faker.list.random(...DESIRED_STATUSES),

Expand Down
5 changes: 3 additions & 2 deletions ui/tests/acceptance/client-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { click, find, findAll, currentURL, visit } from 'ember-native-dom-helper
import { test } from 'qunit';
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import moment from 'moment';

const { $ } = Ember;

Expand Down Expand Up @@ -127,8 +128,8 @@ test('each allocation should have high-level details for the allocation', functi
.find('td:eq(1)')
.text()
.trim(),
allocation.modifyIndex,
'Allocation modify index'
moment(allocation.modifyTime / 1000000).format('MM/DD HH:mm:ss'),
'Allocation modify time'
);
assert.equal(
allocationRow
Expand Down
5 changes: 3 additions & 2 deletions ui/tests/acceptance/task-group-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { click, find, findAll, fillIn, currentURL, visit } from 'ember-native-do
import { test } from 'qunit';
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import moment from 'moment';

const { $ } = Ember;

Expand Down Expand Up @@ -157,8 +158,8 @@ test('each allocation should show basic information about the allocation', funct
.find('td:eq(1)')
.text()
.trim(),
allocation.modifyIndex,
'Allocation modify index'
moment(allocation.modifyTime / 1000000).format('MM/DD HH:mm:ss'),
'Allocation modify time'
);
assert.equal(
allocationRow
Expand Down