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

83 lines
2.4 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;
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
@attr() meta;
2021-10-12 20:36:10 +00:00
@computed('job.meta.raw', 'meta')
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
get mergedMeta() {
return {
2021-10-12 20:36:10 +00:00
...this.job.get('meta.raw'),
ui: add parameterized dispatch interface (#10675) * ui: add parameterized dispatch interface This commit adds a new interface for dispatching parameteried jobs, if the user has the right permissions. The UI can be accessed by viewing a parameterized job and clicking on the "Dispatch Job" button located in the "Job Launches" section. * fix failing lint test * clean up dispatch and remove meta This commit cleans up a few things that had typos and inconsistent naming. In line with this, the custom `meta` view was removed in favor of using the included `AttributesTable`. * ui: encode dispatch job payload and start adding tests * ui: remove unused test imports * ui: redesign job dispatch form * ui: initial acceptance tests for dispatch job * ui: generate parameterized job children with correct id format * ui: fix job dispatch breadcrumb link * ui: refactor job dispatch component into glimmer component and add form validation * ui: remove unused CSS class * ui: align job dispatch button * ui: handle namespace-specific requests on job dispatch * ui: rename payloadMissing to payloadHasError * ui: don't re-fetch job spec on dispatch job * ui: keep overview tab selected on job dispatch page * ui: fix task and task-group linting * ui: URL encode job id on dispatch job tests * ui: fix error when job meta is null * ui: handle job dispatch from adapter * ui: add more tests for dispatch job page * ui: add "job dispatch" capability check * ui: update job dispatch from code review Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
2021-07-20 22:27:41 +00:00
...this.meta,
};
}
@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
@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);
}
@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);
}
}