open-nomad/ui/app/models/allocation.js

99 lines
2.9 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';
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 intersection from 'lodash.intersection';
2017-09-19 14:47:10 +00:00
import shortUUIDProperty from '../utils/properties/short-uuid';
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({
token: service(),
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'),
2018-07-19 20:31:39 +00:00
jobVersion: attr('number'),
2017-09-19 14:47:10 +00:00
modifyIndex: attr('number'),
2017-11-30 23:08:31 +00:00
modifyTime: attr('date'),
2018-07-19 20:31:39 +00:00
createIndex: attr('number'),
createTime: attr('date'),
2017-09-19 14:47:10 +00:00
clientStatus: attr('string'),
desiredStatus: attr('string'),
statusIndex: computed('clientStatus', function() {
return STATUS_ORDER[this.get('clientStatus')] || 100;
}),
2017-09-19 14:47:10 +00:00
isRunning: equal('clientStatus', 'running'),
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' }),
followUpEvaluation: belongsTo('evaluation'),
2018-04-25 22:50:15 +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'));
}),
unhealthyDrivers: computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]', function() {
const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');
if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
}
return [];
}),
2017-09-19 14:47:10 +00:00
states: fragmentArray('task-state'),
2018-04-25 22:50:15 +00:00
rescheduleEvents: fragmentArray('reschedule-event'),
hasRescheduleEvents: computed('rescheduleEvents.length', 'nextAllocation', function() {
return this.get('rescheduleEvents.length') > 0 || this.get('nextAllocation');
}),
2018-05-03 19:17:06 +00:00
hasStoppedRescheduling: computed(
'nextAllocation',
'clientStatus',
'followUpEvaluation',
function() {
return (
!this.get('nextAllocation.content') &&
!this.get('followUpEvaluation.content') &&
2018-05-03 19:17:06 +00:00
this.get('clientStatus') === 'failed'
);
}
),
2017-09-19 14:47:10 +00:00
});