2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Fragment from 'ember-data-model-fragments/fragment';
|
2021-02-17 21:01:44 +00:00
|
|
|
import { attr } from '@ember-data/model';
|
2020-06-17 07:16:12 +00:00
|
|
|
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';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-02-08 23:02:48 +00:00
|
|
|
const maybe = arr => arr || [];
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class TaskGroup extends Fragment {
|
|
|
|
@fragmentOwner() job;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@attr('string') name;
|
|
|
|
@attr('number') count;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragmentArray('task') tasks;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragmentArray('service') services;
|
2019-09-04 14:39:56 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragmentArray('volume-definition') volumes;
|
2020-02-11 00:19:28 +00:00
|
|
|
|
2020-06-17 07:16:12 +00:00
|
|
|
@fragment('group-scaling') scaling;
|
|
|
|
|
2021-07-20 22:27:41 +00:00
|
|
|
@attr() meta;
|
|
|
|
|
2021-10-12 20:36:10 +00:00
|
|
|
@computed('job.meta.raw', 'meta')
|
2021-07-20 22:27:41 +00:00
|
|
|
get mergedMeta() {
|
|
|
|
return {
|
2021-10-12 20:36:10 +00:00
|
|
|
...this.job.get('meta.raw'),
|
2021-07-20 22:27:41 +00:00
|
|
|
...this.meta,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('tasks.@each.driver')
|
|
|
|
get drivers() {
|
2019-09-04 14:39:56 +00:00
|
|
|
return this.tasks.mapBy('driver').uniq();
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-05-10 00:04:45 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('job.allocations.@each.taskGroup', 'name')
|
2020-06-10 13:49:16 +00:00
|
|
|
get allocations() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return maybe(this.get('job.allocations')).filterBy('taskGroupName', 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
|
|
|
@sumAggregation('tasks', 'reservedCPU') reservedCPU;
|
|
|
|
@sumAggregation('tasks', 'reservedMemory') reservedMemory;
|
|
|
|
@sumAggregation('tasks', 'reservedDisk') reservedDisk;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-04-28 20:38:14 +00:00
|
|
|
@computed('tasks.@each.{reservedMemory,reservedMemoryMax}')
|
|
|
|
get reservedMemoryMax() {
|
|
|
|
return this.get('tasks')
|
|
|
|
.map(t => t.get('reservedMemoryMax') || t.get('reservedMemory'))
|
|
|
|
.reduce((sum, count) => sum + count, 0);
|
|
|
|
}
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@attr('number') reservedEphemeralDisk;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('job.latestFailureEvaluation.failedTGAllocs.[]', 'name')
|
2020-06-10 13:49:16 +00:00
|
|
|
get placementFailures() {
|
2017-11-29 01:23:30 +00:00
|
|
|
const placementFailures = this.get('job.latestFailureEvaluation.failedTGAllocs');
|
2019-03-26 07:46:44 +00:00
|
|
|
return placementFailures && placementFailures.findBy('name', this.name);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-11-29 01:23:30 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('summary.{queuedAllocs,startingAllocs}')
|
|
|
|
get queuedOrStartingAllocs() {
|
2017-09-19 14:47:10 +00:00
|
|
|
return this.get('summary.queuedAllocs') + this.get('summary.startingAllocs');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('job.taskGroupSummaries.[]', 'name')
|
2020-06-10 13:49:16 +00:00
|
|
|
get summary() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-06-17 08:48:10 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('job.scaleState.taskGroupScales.[]', 'name')
|
2020-07-24 04:39:50 +00:00
|
|
|
get scaleState() {
|
|
|
|
return maybe(this.get('job.scaleState.taskGroupScales')).findBy('name', this.name);
|
|
|
|
}
|
|
|
|
|
2020-07-30 15:43:15 +00:00
|
|
|
scale(count, message) {
|
|
|
|
return this.job.scale(this.name, count, message);
|
2020-06-17 08:48:10 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|