Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of [ui] System, Batch, and Sysbatch jobs' Start Job buttons let you revert to previous versions into release/1.9.x #25218

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25104.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: System, Batch and Sysbatch jobs get a "Revert to prev version" button on their main pages
```
19 changes: 18 additions & 1 deletion ui/app/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions ui/app/templates/components/job-page/parts/title.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions ui/app/templates/components/job-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
31 changes: 31 additions & 0 deletions ui/mirage/scenarios/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ export function createRestartableJobs(server) {
shallow: true,
createAllocations: false,
groupAllocCount: 0,
type: 'service',
});

const nonRevertableJob = server.create('job', {
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions ui/tests/acceptance/job-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/job-versions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module('Acceptance | job versions', function (hooks) {
namespaceId: namespace.id,
createAllocations: false,
noDeployments: true,
type: 'service',
});

// Create some versions
Expand Down