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

66 lines
2 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/model';
import { fragmentOwner, fragmentArray, fragment } from 'ember-data-model-fragments/attributes';
2017-09-19 14:47:10 +00:00
import sumAggregation from '../utils/properties/sum-aggregation';
import classic from 'ember-classic-decorator';
2017-09-19 14:47:10 +00:00
const maybe = arr => arr || [];
@classic
export default class TaskGroup extends Fragment {
@fragmentOwner() job;
2017-09-19 14:47:10 +00:00
@attr('string') name;
@attr('number') count;
2017-09-19 14:47:10 +00:00
@fragmentArray('task') tasks;
2017-09-19 14:47:10 +00:00
@fragmentArray('service') services;
@fragmentArray('volume-definition') volumes;
2020-02-11 00:19:28 +00:00
@fragment('group-scaling') scaling;
@computed('tasks.@each.driver')
get drivers() {
return this.tasks.mapBy('driver').uniq();
}
@computed('job.allocations.@each.taskGroup', 'name')
get allocations() {
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
@sumAggregation('tasks', 'reservedCPU') reservedCPU;
@sumAggregation('tasks', 'reservedMemory') reservedMemory;
@sumAggregation('tasks', 'reservedDisk') reservedDisk;
2017-09-19 14:47:10 +00:00
@attr('number') reservedEphemeralDisk;
2017-09-19 14:47:10 +00:00
@computed('job.latestFailureEvaluation.failedTGAllocs.[]', 'name')
get placementFailures() {
const placementFailures = this.get('job.latestFailureEvaluation.failedTGAllocs');
2019-03-26 07:46:44 +00:00
return placementFailures && placementFailures.findBy('name', this.name);
}
@computed('summary.{queuedAllocs,startingAllocs}')
get queuedOrStartingAllocs() {
2017-09-19 14:47:10 +00:00
return this.get('summary.queuedAllocs') + this.get('summary.startingAllocs');
}
2017-09-19 14:47:10 +00:00
@computed('job.taskGroupSummaries.[]', 'name')
get summary() {
2019-03-26 07:46:44 +00:00
return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name);
}
@computed('job.scaleState.taskGroupScales.[]', 'name')
get scaleState() {
return maybe(this.get('job.scaleState.taskGroupScales')).findBy('name', this.name);
}
scale(count, message) {
return this.job.scale(this.name, count, message);
}
}