open-nomad/ui/app/models/task.js
Phil Renaud 0982ad1079
Change path-linked-variables to start with nomad/jobs/, instead of jobs/ (#13862)
* Support pathLinkedEntities starting with nomad/jobs/ instead of jobs/

* links from jobs/groups/tasks to variables now look for nomad/jobs/ instead of jobs/

* Tests updated to reflect nomad/jobs/ change

* Acceptance test for disallowing nomad/foo/, and hint text updates

* Defensive logic in case path not yet set

* Allow exactly nomad/jobs as a variable path
2022-07-20 12:19:01 -04:00

77 lines
1.8 KiB
JavaScript

import { attr } from '@ember-data/model';
import Fragment from 'ember-data-model-fragments/fragment';
import {
fragment,
fragmentArray,
fragmentOwner,
} from 'ember-data-model-fragments/attributes';
import { computed } from '@ember/object';
export default class Task extends Fragment {
@fragmentOwner() taskGroup;
@attr('string') name;
@attr('string') driver;
@attr('string') kind;
@attr() meta;
@computed('taskGroup.mergedMeta', 'meta')
get mergedMeta() {
return {
...this.taskGroup.mergedMeta,
...this.meta,
};
}
@fragment('lifecycle') lifecycle;
@computed('lifecycle', 'lifecycle.sidecar')
get lifecycleName() {
if (this.lifecycle) {
const { hook, sidecar } = this.lifecycle;
if (hook === 'prestart') {
return sidecar ? 'prestart-sidecar' : 'prestart-ephemeral';
} else if (hook === 'poststart') {
return sidecar ? 'poststart-sidecar' : 'poststart-ephemeral';
} else if (hook === 'poststop') {
return 'poststop';
}
}
return 'main';
}
@attr('number') reservedMemory;
@attr('number') reservedMemoryMax;
@attr('number') reservedCPU;
@attr('number') reservedDisk;
@attr('number') reservedEphemeralDisk;
@fragmentArray('volume-mount', { defaultValue: () => [] }) volumeMounts;
async _fetchParentJob() {
let job = await this.store.findRecord('job', this.taskGroup.job.id, {
reload: true,
});
this._job = job;
}
get pathLinkedVariable() {
if (!this._job) {
this._fetchParentJob();
return null;
} else {
let jobID = this._job.plainId;
if (this._job.parent.get('plainId')) {
jobID = this._job.parent.get('plainId');
}
return this._job.variables?.findBy(
'path',
`nomad/jobs/${jobID}/${this.taskGroup.name}/${this.name}`
);
}
}
}