open-nomad/ui/app/models/task-group.js
Buck Doyle e9e52e0dfe
Update Ember/Ember CLI to 3.20 (#9641)
This doesn’t include Ember Data, as we are still back on 3.12.

Most changes are deprecation updates, linting fixes, and dependencies. It can
be read commit-by-commit, though many of them are mechanical and skimmable.
For the new linting exclusions, I’ve added them to the Tech Debt list.

The decrease in test count is because linting is no longer included in ember test.

There’s a new deprecation warning in the logs that can be fixed by updating Ember
Power Select but when I tried that it caused it to render incorrectly, so I decided to
ignore it for now and address it separately.
2021-02-17 15:01:44 -06:00

66 lines
2 KiB
JavaScript

import { computed } from '@ember/object';
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import { fragmentOwner, fragmentArray, fragment } from 'ember-data-model-fragments/attributes';
import sumAggregation from '../utils/properties/sum-aggregation';
import classic from 'ember-classic-decorator';
const maybe = arr => arr || [];
@classic
export default class TaskGroup extends Fragment {
@fragmentOwner() job;
@attr('string') name;
@attr('number') count;
@fragmentArray('task') tasks;
@fragmentArray('service') services;
@fragmentArray('volume-definition') volumes;
@fragment('group-scaling') scaling;
@computed('tasks.@each.driver')
get drivers() {
return this.tasks.mapBy('driver').uniq();
}
@computed('job.allocations.@each.taskGroup', 'name')
get allocations() {
return maybe(this.get('job.allocations')).filterBy('taskGroupName', this.name);
}
@sumAggregation('tasks', 'reservedCPU') reservedCPU;
@sumAggregation('tasks', 'reservedMemory') reservedMemory;
@sumAggregation('tasks', 'reservedDisk') reservedDisk;
@attr('number') reservedEphemeralDisk;
@computed('job.latestFailureEvaluation.failedTGAllocs.[]', 'name')
get placementFailures() {
const placementFailures = this.get('job.latestFailureEvaluation.failedTGAllocs');
return placementFailures && placementFailures.findBy('name', this.name);
}
@computed('summary.{queuedAllocs,startingAllocs}')
get queuedOrStartingAllocs() {
return this.get('summary.queuedAllocs') + this.get('summary.startingAllocs');
}
@computed('job.taskGroupSummaries.[]', 'name')
get summary() {
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);
}
}