open-nomad/ui/app/models/task-state.js
Buck Doyle e9e52e0dfe
Update Ember/Ember CLI to 3.20 (#9641)
This doesn’t include Ember Data, as we are still back on 3.12.

Most changes are deprecation updates, linting fixes, and dependencies. It can
be read commit-by-commit, though many of them are mechanical and skimmable.
For the new linting exclusions, I’ve added them to the Tech Debt list.

The decrease in test count is because linting is no longer included in ember test.

There’s a new deprecation warning in the logs that can be fixed by updating Ember
Power Select but when I tried that it caused it to render incorrectly, so I decided to
ignore it for now and address it separately.
2021-02-17 15:01:44 -06:00

61 lines
1.7 KiB
JavaScript

import { computed } from '@ember/object';
import { alias, none, and } from '@ember/object/computed';
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import { fragment, fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes';
import classic from 'ember-classic-decorator';
@classic
export default class TaskState extends Fragment {
@fragmentOwner() allocation;
@attr('string') name;
@attr('string') state;
@attr('date') startedAt;
@attr('date') finishedAt;
@attr('boolean') failed;
@none('finishedAt') isActive;
@and('isActive', 'allocation.isRunning') isRunning;
@computed('task.kind')
get isConnectProxy() {
return (this.get('task.kind') || '').startsWith('connect-proxy:');
}
@computed('name', 'allocation.taskGroup.tasks.[]')
get task() {
const tasks = this.get('allocation.taskGroup.tasks');
return tasks && tasks.findBy('name', this.name);
}
@alias('task.driver') 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
@computed('task.driver', 'allocation.node.drivers.[]')
get driverStatus() {
const nodeDrivers = this.get('allocation.node.drivers') || [];
return nodeDrivers.findBy('name', this.get('task.driver'));
}
@fragment('resources') resources;
@fragmentArray('task-event') events;
@computed('state')
get stateClass() {
const classMap = {
pending: 'is-pending',
running: 'is-primary',
finished: 'is-complete',
failed: 'is-error',
};
return classMap[this.state] || 'is-dark';
}
restart() {
return this.allocation.restart(this.name);
}
}