Files
nomad/ui/app/models/task-group.js
Nicholas Cioli 801a7324a3 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 18:27:41 -04:00

83 lines
2.3 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;
@attr() meta;
@computed('job.meta', 'meta')
get mergedMeta() {
return {
...this.job.meta,
...this.meta,
};
}
@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;
@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;
@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);
}
}