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';
|
2021-12-28 16:08: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
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const maybe = (arr) => arr || [];
|
2018-02-08 23:02:48 +00:00
|
|
|
|
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
|
|
|
|
2022-07-13 15:40:13 +00:00
|
|
|
@computed('job.{variables,parent,plainId}', 'name')
|
|
|
|
get pathLinkedVariable() {
|
|
|
|
if (this.job.parent.get('id')) {
|
|
|
|
return this.job.variables?.findBy(
|
|
|
|
'path',
|
2022-07-20 16:19:01 +00:00
|
|
|
`nomad/jobs/${JSON.parse(this.job.parent.get('id'))[0]}/${this.name}`
|
2022-07-13 15:40:13 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return this.job.variables?.findBy(
|
|
|
|
'path',
|
2022-07-20 16:19:01 +00:00
|
|
|
`nomad/jobs/${this.job.plainId}/${this.name}`
|
2022-07-13 15:40:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragmentArray('task') tasks;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2022-08-26 03:22:55 +00:00
|
|
|
@fragmentArray('service-fragment') 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
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
@computed('job.allocations.{@each.taskGroup,isFulfilled}', 'name')
|
2020-06-10 13:49:16 +00:00
|
|
|
get allocations() {
|
2021-12-28 16:08:12 +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')
|
2021-12-28 14:45:20 +00:00
|
|
|
.map((t) => t.get('reservedMemoryMax') || t.get('reservedMemory'))
|
2021-04-28 20:38:14 +00:00
|
|
|
.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() {
|
2021-12-28 16:08:12 +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() {
|
2021-12-28 16:08:12 +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() {
|
2021-12-28 16:08:12 +00:00
|
|
|
return maybe(this.get('job.scaleState.taskGroupScales')).findBy(
|
|
|
|
'name',
|
|
|
|
this.name
|
|
|
|
);
|
2020-07-24 04:39:50 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|