2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2018-12-10 23:24:39 +00:00
|
|
|
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';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class TaskState extends Fragment {
|
|
|
|
@fragmentOwner() allocation;
|
2018-12-07 01:11:01 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@attr('string') name;
|
|
|
|
@attr('string') state;
|
|
|
|
@attr('date') startedAt;
|
|
|
|
@attr('date') finishedAt;
|
|
|
|
@attr('boolean') failed;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@none('finishedAt') isActive;
|
|
|
|
@and('isActive', 'allocation.isRunning') isRunning;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('task.kind')
|
|
|
|
get isConnectProxy() {
|
2019-09-05 18:14:54 +00:00
|
|
|
return (this.get('task.kind') || '').startsWith('connect-proxy:');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-09-04 14:39:56 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('name', 'allocation.taskGroup.tasks.[]')
|
|
|
|
get task() {
|
2017-09-19 14:47:10 +00:00
|
|
|
const tasks = this.get('allocation.taskGroup.tasks');
|
2019-03-26 07:46:44 +00:00
|
|
|
return tasks && tasks.findBy('name', this.name);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('task.driver') driver;
|
2018-05-10 00:04:45 +00:00
|
|
|
|
|
|
|
// 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
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('task.driver', 'allocation.node.drivers.[]')
|
|
|
|
get driverStatus() {
|
2018-05-10 00:04:45 +00:00
|
|
|
const nodeDrivers = this.get('allocation.node.drivers') || [];
|
|
|
|
return nodeDrivers.findBy('name', this.get('task.driver'));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-05-10 00:04:45 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragment('resources') resources;
|
|
|
|
@fragmentArray('task-event') events;
|
2017-10-31 04:02:40 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('state')
|
|
|
|
get stateClass() {
|
2017-10-31 04:02:40 +00:00
|
|
|
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';
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-05-20 22:27:20 +00:00
|
|
|
|
|
|
|
restart() {
|
|
|
|
return this.allocation.restart(this.name);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|