mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 09:55:44 +03:00
This partially addresses #7799. Task state filesystems are contained within a subdirectory of their parent allocation, so almost everything that existed for browsing task state filesystems was applicable to browsing allocations, just without the task name prepended to the path. I aimed to push this differential handling into as few contained places as possible. The tests also have significant overlap, so this includes an extracted behavior to run the same tests for allocations and task states.
55 lines
1.7 KiB
JavaScript
55 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/attr';
|
|
import { fragment, fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
|
|
export default Fragment.extend({
|
|
allocation: fragmentOwner(),
|
|
|
|
name: attr('string'),
|
|
state: attr('string'),
|
|
startedAt: attr('date'),
|
|
finishedAt: attr('date'),
|
|
failed: attr('boolean'),
|
|
|
|
isActive: none('finishedAt'),
|
|
isRunning: and('isActive', 'allocation.isRunning'),
|
|
|
|
isConnectProxy: computed('task.kind', function() {
|
|
return (this.get('task.kind') || '').startsWith('connect-proxy:');
|
|
}),
|
|
|
|
task: computed('name', 'allocation.taskGroup.tasks.[]', function() {
|
|
const tasks = this.get('allocation.taskGroup.tasks');
|
|
return tasks && tasks.findBy('name', this.name);
|
|
}),
|
|
|
|
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'));
|
|
}),
|
|
|
|
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',
|
|
};
|
|
|
|
return classMap[this.state] || 'is-dark';
|
|
}),
|
|
|
|
restart() {
|
|
return this.allocation.restart(this.name);
|
|
},
|
|
});
|