mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 19:35:41 +03:00
* Scaffolding actions (#18639) * Task-level actions for job submissions and retrieval * FIXME: Temporary workaround to get ember dev server to pass exec through to 4646 * Update api/tasks.go Co-authored-by: Tim Gross <tgross@hashicorp.com> * Update command/agent/job_endpoint.go Co-authored-by: Tim Gross <tgross@hashicorp.com> * Diff and copy implementations * Action structs get their own file, diff updates to behave like our other diffs * Test to observe actions changes in a version update * Tests migrated into structs/diff_test and modified with PR comments in mind * APIActionToSTructsAction now returns a new value * de-comment some plain parts, remove unused action lookup * unused param in action converter --------- Co-authored-by: Tim Gross <tgross@hashicorp.com> * New endpoint: job/:id/actions (#18690) * unused param in action converter * backing out of parse_job level and moved toward new endpoint level * Adds taskName and taskGroupName to actions at job level * Unmodified job mock actions tests * actionless job test * actionless job test * Multi group multi task actions test * HTTP method check for GET, cleaner errors in job_endpoint_test * decomment * Actions aggregated at job model level (#18733) * Removal of temporary fix to proxy to 4646 * Run Action websocket endpoint (#18760) * Working demo for review purposes * removal of cors passthru for websockets * Remove job_endpoint-specific ws handlers and aimed at existing alloc exec handlers instead * PR comments adressed, no need for taskGroup pass, better group and task lookups from alloc * early return in action validate and removed jobid from req args per PR comments * todo removal, we're checking later in the rpc * boolean style change on tty * Action CLI command (#18778) * Action command init and stuck-notes * Conditional reqpath to aim at Job action endpoint * De-logged * General CLI command cleanup, observe namespace, pass action as string, get random alloc w group adherence * tab and varname cleanup * Remove action param from Allocations().Exec calls * changelog * dont nil-check acl --------- Co-authored-by: Tim Gross <tgross@hashicorp.com>
108 lines
2.8 KiB
JavaScript
108 lines
2.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
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;
|
|
|
|
@fragmentArray('action') actions;
|
|
|
|
@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('service-fragment') services;
|
|
|
|
@fragmentArray('volume-mount', { defaultValue: () => [] }) volumeMounts;
|
|
|
|
async _fetchParentJob() {
|
|
let job = this.store.peekRecord('job', this.taskGroup.job.id);
|
|
if (!job) {
|
|
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}`
|
|
);
|
|
}
|
|
}
|
|
|
|
// TODO: This async fetcher seems like a better fit for most of our use-cases than the above getter (which cannot do async/await)
|
|
async getPathLinkedVariable() {
|
|
if (!this._job) {
|
|
await this._fetchParentJob();
|
|
}
|
|
await this._job.variables;
|
|
let jobID = this._job.plainId;
|
|
// not getting plainID because we dont know the resolution status of the task's job's parent yet
|
|
let parentID = this._job.belongsTo('parent').id()
|
|
? JSON.parse(this._job.belongsTo('parent').id())[0]
|
|
: null;
|
|
if (parentID) {
|
|
jobID = parentID;
|
|
}
|
|
return await this._job.variables?.findBy(
|
|
'path',
|
|
`nomad/jobs/${jobID}/${this.taskGroup.name}/${this.name}`
|
|
);
|
|
}
|
|
}
|