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

48 lines
1.6 KiB
JavaScript
Raw Normal View History

import { computed } from '@ember/object';
2017-09-19 14:47:10 +00:00
import Fragment from 'ember-data-model-fragments/fragment';
import attr from 'ember-data/attr';
import { fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes';
import sumAggregation from '../utils/properties/sum-aggregation';
const maybe = arr => arr || [];
2017-09-19 14:47:10 +00:00
export default Fragment.extend({
job: fragmentOwner(),
name: attr('string'),
count: attr('number'),
tasks: fragmentArray('task'),
services: fragmentArray('service'),
volumes: fragmentArray('volume-definition'),
2020-02-11 00:19:28 +00:00
drivers: computed('tasks.@each.driver', function() {
return this.tasks.mapBy('driver').uniq();
}),
2017-09-19 14:47:10 +00:00
allocations: computed('job.allocations.@each.taskGroup', function() {
2019-03-26 07:46:44 +00:00
return maybe(this.get('job.allocations')).filterBy('taskGroupName', this.name);
2017-09-19 14:47:10 +00:00
}),
reservedCPU: sumAggregation('tasks', 'reservedCPU'),
reservedMemory: sumAggregation('tasks', 'reservedMemory'),
reservedDisk: sumAggregation('tasks', 'reservedDisk'),
reservedEphemeralDisk: attr('number'),
placementFailures: computed('job.latestFailureEvaluation.failedTGAllocs.[]', function() {
const placementFailures = this.get('job.latestFailureEvaluation.failedTGAllocs');
2019-03-26 07:46:44 +00:00
return placementFailures && placementFailures.findBy('name', this.name);
}),
2017-09-19 14:47:10 +00:00
queuedOrStartingAllocs: computed('summary.{queuedAllocs,startingAllocs}', function() {
return this.get('summary.queuedAllocs') + this.get('summary.startingAllocs');
}),
summary: computed('job.taskGroupSummaries.[]', function() {
2019-03-26 07:46:44 +00:00
return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name);
2017-09-19 14:47:10 +00:00
}),
});