2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2018-12-07 01:11:01 +00:00
|
|
|
import { alias, none } from '@ember/object/computed';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Fragment from 'ember-data-model-fragments/fragment';
|
|
|
|
import attr from 'ember-data/attr';
|
|
|
|
import { fragment, fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
|
|
|
|
|
|
export default Fragment.extend({
|
2018-12-07 01:11:01 +00:00
|
|
|
allocation: fragmentOwner(),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
name: attr('string'),
|
|
|
|
state: attr('string'),
|
|
|
|
startedAt: attr('date'),
|
|
|
|
finishedAt: attr('date'),
|
|
|
|
failed: attr('boolean'),
|
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
isActive: none('finishedAt'),
|
2018-12-07 01:11:01 +00:00
|
|
|
isRunning: alias('allocation.isRunning'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
task: computed('allocation.taskGroup.tasks.[]', function() {
|
|
|
|
const tasks = this.get('allocation.taskGroup.tasks');
|
|
|
|
return tasks && tasks.findBy('name', this.get('name'));
|
|
|
|
}),
|
|
|
|
|
2018-05-10 00:04:45 +00:00
|
|
|
driver: alias('task.driver'),
|
|
|
|
|
|
|
|
// TaskState represents a task running on a node, so in addition to knowing the
|
|
|
|
// driver via the task, the health of the driver is also known via the node
|
|
|
|
driverStatus: computed('task.driver', 'allocation.node.drivers.[]', function() {
|
|
|
|
const nodeDrivers = this.get('allocation.node.drivers') || [];
|
|
|
|
return nodeDrivers.findBy('name', this.get('task.driver'));
|
|
|
|
}),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
resources: fragment('resources'),
|
|
|
|
events: fragmentArray('task-event'),
|
2017-10-31 04:02:40 +00:00
|
|
|
|
|
|
|
stateClass: computed('state', function() {
|
|
|
|
const classMap = {
|
|
|
|
pending: 'is-pending',
|
|
|
|
running: 'is-primary',
|
|
|
|
finished: 'is-complete',
|
|
|
|
failed: 'is-error',
|
|
|
|
};
|
|
|
|
|
|
|
|
return classMap[this.get('state')] || 'is-dark';
|
|
|
|
}),
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|