[ui] System, Batch, and Sysbatch jobs' Start Job buttons let you revert to previous versions (#25104)

* Changes the behaviour of system/batch/sysbatch jobs not to look for a latest stable version, as their versions never go to stable

* Dont show job stability on versions page for system/sysbatch/batch jobs

* Tests that depend on jobs to revert specify that they are Service jobs

* Batch jobs added to detail-restart test loop

* Right, they're not stable, they're just versions
This commit is contained in:
Phil Renaud
2025-02-25 11:10:14 -05:00
committed by GitHub
parent db5022b965
commit 7d08e79da3
7 changed files with 90 additions and 5 deletions

View File

@@ -351,6 +351,18 @@ export default class Job extends Model {
return this.type === 'system' || this.type === 'sysbatch';
}
// version.Stable is determined by having an associated healthy deployment
// but System, Sysbatch, and Batch jobs do not have deployments.
// Use this as a boolean to determine if we should show the version stability badge
@computed('type')
get hasVersionStability() {
return (
this.type !== 'system' &&
this.type !== 'sysbatch' &&
this.type !== 'batch'
);
}
@belongsTo('job', { inverse: 'children' }) parent;
@hasMany('job', { inverse: 'parent' }) children;
@@ -455,12 +467,17 @@ export default class Job extends Model {
.any((version) => version.get('stable'));
}
@computed('versions.@each.stable')
@computed('versions.@each.stable', 'aggregateAllocStatus.label')
get latestStableVersion() {
return this.versions.filterBy('stable').sortBy('number').reverse().slice(1)
.firstObject;
}
@computed('versions.[]', 'aggregateAllocStatus.label')
get latestVersion() {
return this.versions.sortBy('number').reverse().slice(1).firstObject;
}
get actions() {
return this.taskGroups.reduce((acc, taskGroup) => {
return acc.concat(

View File

@@ -101,6 +101,25 @@
@awaitingConfirmation={{this.revertTo.isRunning}}
@onConfirm={{perform this.revertTo this.job.latestStableVersion}}
/>
{{else if
(and
(not this.job.hasVersionStability)
this.job.latestVersion
)
}}
<TwoStepButton
data-test-revert
@alignRight={{true}}
@idleText="Revert to last version (v{{this.job.latestVersion.number}})"
@cancelText="Cancel"
@confirmText="Yes, Revert to last version"
@confirmationMessage="Are you sure you want to revert to the last version?"
@awaitingConfirmation={{this.revertTo.isRunning}}
@onConfirm={{perform this.revertTo this.job.latestVersion}}
/>
<Hds::Button
data-test-edit-and-resubmit
@color="primary" @isInline={{true}} @text="Edit and Resubmit job" @route={{"jobs.job.definition" this.job.id}} @query={{hash isEditing=true}} />
{{else}}
<Hds::Button
data-test-edit-and-resubmit

View File

@@ -8,10 +8,15 @@
<div class="boxed-section {{if this.version.versionTag "tagged"}}" data-test-tagged-version={{if this.version.versionTag "true" "false"}}>
<header class="boxed-section-head is-light inline-definitions">
Version #{{this.version.number}}
<span class="bumper-left pair is-faded">
<span class="term">Stable</span>
<span class="badge is-light is-faded" data-test-version-stability><code>{{this.version.stable}}</code></span>
</span>
{{#if this.version.job.hasVersionStability}}
<span class="bumper-left pair is-faded">
<span class="term">Stable</span>
<span class="badge is-light is-faded" data-test-version-stability><code>{{this.version.stable}}</code></span>
</span>
{{else}}
<span class="bumper-left" />
{{/if}}
<span class="pair is-faded">
<span class="term">Submitted</span>
<span data-test-version-submit-time class="submit-date">{{format-ts this.version.submitTime}}</span>

View File

@@ -1237,6 +1237,7 @@ export function createRestartableJobs(server) {
shallow: true,
createAllocations: false,
groupAllocCount: 0,
type: 'service',
});
const nonRevertableJob = server.create('job', {
@@ -1246,6 +1247,16 @@ export function createRestartableJobs(server) {
shallow: true,
createAllocations: false,
groupAllocCount: 0,
type: 'service',
});
const revertableBatchJob = server.create('job', {
name: 'revertable-batch-job',
stopped: false,
status: 'dead',
noDeployments: true,
shallow: true,
type: 'batch',
});
// So it shows up as "Failed" instead of "Scaled Down"
@@ -1272,6 +1283,10 @@ export function createRestartableJobs(server) {
.all()
.filter((v) => v.jobId === nonRevertableJob.id)
.models.forEach((v) => v.destroy());
server.schema.jobVersions
.all()
.filter((v) => v.jobId === revertableBatchJob.id)
.models.forEach((v) => v.destroy());
server.create('job-version', {
job: revertableJob,
@@ -1322,6 +1337,22 @@ export function createRestartableJobs(server) {
noActiveDeployment: true,
});
server.create('job-version', {
job: revertableBatchJob,
namespace: revertableBatchJob.namespace,
version: 0,
stable: false, // <--- ignored by the UI by way of job.hasVersionStability
noActiveDeployment: true,
});
server.create('job-version', {
job: revertableBatchJob,
namespace: revertableBatchJob.namespace,
version: 1,
stable: false, // <--- ignored by the UI by way of job.hasVersionStability
noActiveDeployment: true,
});
server.schema.jobVersions
.all()
.filter((v) => v.jobId === revertableJob.id)

View File

@@ -864,6 +864,15 @@ module('Job Start/Stop/Revert/Edit and Resubmit', function (hooks) {
assert.ok(JobDetail.editAndResubmit.isPresent);
});
test('A batch job with a previous version can be reverted', async function (assert) {
const revertableSystemJob = server.db.jobs.findBy(
(j) => j.name === 'revertable-batch-job'
);
await JobDetail.visit({ id: revertableSystemJob.id });
assert.ok(JobDetail.revert.isPresent);
assert.equal(JobDetail.revert.text, 'Revert to last version (v0)');
});
test('Clicking the resubmit button navigates to the job definition page in edit mode', async function (assert) {
const job = server.db.jobs.findBy((j) => j.name === 'non-revertable-job');
await JobDetail.visit({ id: job.id });

View File

@@ -31,6 +31,7 @@ module('Acceptance | job versions', function (hooks) {
namespaceId: namespace.id,
createAllocations: false,
noDeployments: true,
type: 'service',
});
// Create some versions