2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { computed } from '@ember/object';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Model from 'ember-data/model';
|
|
|
|
import attr from 'ember-data/attr';
|
|
|
|
import { belongsTo } from 'ember-data/relationships';
|
|
|
|
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
|
|
import shortUUIDProperty from '../utils/properties/short-uuid';
|
2018-03-22 21:34:13 +00:00
|
|
|
import AllocationStats from '../utils/classes/allocation-stats';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-18 00:48:52 +00:00
|
|
|
const STATUS_ORDER = {
|
|
|
|
pending: 1,
|
|
|
|
running: 2,
|
|
|
|
complete: 3,
|
|
|
|
failed: 4,
|
|
|
|
lost: 5,
|
|
|
|
};
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
export default Model.extend({
|
2017-12-15 21:39:18 +00:00
|
|
|
token: service(),
|
2017-10-19 02:04:19 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
shortId: shortUUIDProperty('id'),
|
|
|
|
job: belongsTo('job'),
|
|
|
|
node: belongsTo('node'),
|
|
|
|
name: attr('string'),
|
|
|
|
taskGroupName: attr('string'),
|
|
|
|
resources: fragment('resources'),
|
|
|
|
modifyIndex: attr('number'),
|
2017-11-30 23:08:31 +00:00
|
|
|
modifyTime: attr('date'),
|
2017-10-18 19:29:33 +00:00
|
|
|
jobVersion: attr('number'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-05 22:21:10 +00:00
|
|
|
// TEMPORARY: https://github.com/emberjs/data/issues/5209
|
|
|
|
originalJobId: attr('string'),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
clientStatus: attr('string'),
|
|
|
|
desiredStatus: attr('string'),
|
2017-10-18 00:48:52 +00:00
|
|
|
statusIndex: computed('clientStatus', function() {
|
|
|
|
return STATUS_ORDER[this.get('clientStatus')] || 100;
|
|
|
|
}),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-04-25 22:50:15 +00:00
|
|
|
// When allocations are server-side rescheduled, a paper trail
|
|
|
|
// is left linking all reschedule attempts.
|
|
|
|
previousAllocation: belongsTo('allocation', { inverse: 'nextAllocation' }),
|
|
|
|
nextAllocation: belongsTo('allocation', { inverse: 'previousAllocation' }),
|
|
|
|
previousNode: belongsTo('node', { inverse: null }),
|
|
|
|
|
2017-10-30 21:16:08 +00:00
|
|
|
statusClass: computed('clientStatus', function() {
|
|
|
|
const classMap = {
|
|
|
|
pending: 'is-pending',
|
|
|
|
running: 'is-primary',
|
|
|
|
complete: 'is-complete',
|
|
|
|
failed: 'is-error',
|
|
|
|
lost: 'is-light',
|
|
|
|
};
|
|
|
|
|
|
|
|
return classMap[this.get('clientStatus')] || 'is-dark';
|
|
|
|
}),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroup: computed('taskGroupName', 'job.taskGroups.[]', function() {
|
|
|
|
const taskGroups = this.get('job.taskGroups');
|
|
|
|
return taskGroups && taskGroups.findBy('name', this.get('taskGroupName'));
|
|
|
|
}),
|
|
|
|
|
2018-03-22 21:34:13 +00:00
|
|
|
fetchStats() {
|
|
|
|
return this.get('token')
|
|
|
|
.authorizedRequest(`/v1/client/allocation/${this.get('id')}/stats`)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(json => {
|
|
|
|
return new AllocationStats({
|
|
|
|
stats: json,
|
|
|
|
allocation: this,
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2018-03-22 21:34:13 +00:00
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
states: fragmentArray('task-state'),
|
2018-04-25 22:50:15 +00:00
|
|
|
rescheduleEvents: fragmentArray('reschedule-event'),
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|