open-nomad/ui/app/models/task-state.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

import { computed } from '@ember/object';
import { alias, none, and } 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({
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'),
isActive: none('finishedAt'),
isRunning: and('isActive', 'allocation.isRunning'),
2017-09-19 14:47:10 +00:00
task: computed('allocation.taskGroup.tasks.[]', function() {
const tasks = this.get('allocation.taskGroup.tasks');
2019-03-26 07:46:44 +00:00
return tasks && tasks.findBy('name', this.name);
2017-09-19 14:47:10 +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'),
stateClass: computed('state', function() {
const classMap = {
pending: 'is-pending',
running: 'is-primary',
finished: 'is-complete',
failed: 'is-error',
};
2019-03-26 07:46:44 +00:00
return classMap[this.state] || 'is-dark';
}),
restart() {
return this.allocation.restart(this.name);
},
ls(path) {
return this.store.adapterFor('task-state').ls(this, path);
},
stat(path) {
return this.store.adapterFor('task-state').stat(this, path);
},
2017-09-19 14:47:10 +00:00
});