From 5fcec1f8cc6a507b087141594a0b595ae2b78289 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Mon, 19 Aug 2024 13:45:19 -0400 Subject: [PATCH] [ui] Show "Scaled Down" as a valid job status when task groups' counts are set to zero (#23829) * Scaled Down as a status * Scaled Down as a steady-state job panel status as well * Test for badge status and changelog --- .changelog/23829.txt | 3 +++ ui/app/components/job-status/panel/steady.js | 9 ++++++++- ui/app/models/job.js | 9 ++++++++- ui/mirage/factories/job.js | 2 +- ui/tests/acceptance/jobs-list-test.js | 10 ++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 .changelog/23829.txt diff --git a/.changelog/23829.txt b/.changelog/23829.txt new file mode 100644 index 000000000..9c71b9bdb --- /dev/null +++ b/.changelog/23829.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Badge added for Scaled Down jobs +``` diff --git a/ui/app/components/job-status/panel/steady.js b/ui/app/components/job-status/panel/steady.js index c37f99856..d90fb220b 100644 --- a/ui/app/components/job-status/panel/steady.js +++ b/ui/app/components/job-status/panel/steady.js @@ -205,7 +205,7 @@ export default class JobStatusPanelSteadyComponent extends Component { /** * @typedef {Object} CurrentStatus - * @property {"Healthy"|"Failed"|"Degraded"|"Recovering"|"Complete"|"Running"|"Stopped"} label - The current status of the job + * @property {"Healthy"|"Failed"|"Degraded"|"Recovering"|"Complete"|"Running"|"Stopped"|"Scaled Down"} label - The current status of the job * @property {"highlight"|"success"|"warning"|"critical"|"neutral"} state - */ @@ -224,6 +224,13 @@ export default class JobStatusPanelSteadyComponent extends Component { }; } + if (this.totalAllocs === 0) { + return { + label: 'Scaled Down', + state: 'neutral', + }; + } + if (this.job.type === 'batch' || this.job.type === 'sysbatch') { // If all the allocs are complete, the job is Complete const completeAllocs = this.allocBlocks.complete?.healthy?.nonCanary; diff --git a/ui/app/models/job.js b/ui/app/models/job.js index 7d06a0f08..e2ab8de03 100644 --- a/ui/app/models/job.js +++ b/ui/app/models/job.js @@ -90,7 +90,7 @@ export default class Job extends Model { /** * @typedef {Object} CurrentStatus - * @property {"Healthy"|"Failed"|"Deploying"|"Degraded"|"Recovering"|"Complete"|"Running"|"Removed"|"Stopped"} label - The current status of the job + * @property {"Healthy"|"Failed"|"Deploying"|"Degraded"|"Recovering"|"Complete"|"Running"|"Removed"|"Stopped"|"Scaled Down"} label - The current status of the job * @property {"highlight"|"success"|"warning"|"critical"|"neutral"} state - */ @@ -226,6 +226,7 @@ export default class Job extends Model { * - Failed: All allocations are failed, lost, or unplaced * - Removed: The job appeared in our initial query, but has since been garbage collected * - Stopped: The job has been manually stopped (and not purged or yet garbage collected) by a user + * - Scaled Down: The job is intentionally scaled down to 0 desired allocations (all task groups have count=0) * @returns {CurrentStatus} */ /** @@ -248,6 +249,12 @@ export default class Job extends Model { }; } + // If the job is scaled down to 0 desired allocations, we shouldn't call it "failed"; + // we should indicate that it is deliberately set to not have any running parts. + if (totalAllocs === 0) { + return { label: 'Scaled Down', state: 'neutral' }; + } + // If the job was requested initially, but a subsequent request for it was // not found, we can remove links to it but maintain its presence in the list // until the user specifies they want a refresh diff --git a/ui/mirage/factories/job.js b/ui/mirage/factories/job.js index 89bc6903d..ccaa605e4 100644 --- a/ui/mirage/factories/job.js +++ b/ui/mirage/factories/job.js @@ -250,7 +250,7 @@ export default Factory.extend({ groupProps.taskCount = job.groupTaskCount; } - if (job.groupAllocCount) { + if (job.groupAllocCount !== undefined) { groupProps.count = job.groupAllocCount; } diff --git a/ui/tests/acceptance/jobs-list-test.js b/ui/tests/acceptance/jobs-list-test.js index 2c2657941..19843a9bc 100644 --- a/ui/tests/acceptance/jobs-list-test.js +++ b/ui/tests/acceptance/jobs-list-test.js @@ -700,6 +700,13 @@ module('Acceptance | jobs list', function (hooks) { activeDeployment: true, }); + server.create('job', { + ...defaultJobParams, + id: 'scaled-down-job', + groupAllocCount: 0, + status: 'dead', + }); + await JobsList.visit(); assert @@ -732,6 +739,9 @@ module('Acceptance | jobs list', function (hooks) { assert .dom('[data-test-job-row="deploying-job"] [data-test-job-status]') .hasText('Deploying', 'Deploying job is deploying'); + assert + .dom('[data-test-job-row="scaled-down-job"] [data-test-job-status]') + .hasText('Scaled Down', 'Scaled down job is scaled down'); await percySnapshot(assert); });