From 2b3dd86dc5c5f1f0d333d97ff5465b90a34fa550 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Fri, 21 Jul 2023 09:16:49 -0400 Subject: [PATCH] ui: handle node pool requests to older regions (#18021) When accessing a region running a version of Nomad without node pools an error was thrown because the request is handled by the nodes endpoint which fails because it assumes `pools` is the node ID. --- .changelog/18021.txt | 3 +++ ui/app/adapters/node-pool.js | 17 +++++++++++++++++ ui/app/templates/clients/client/index.hbs | 2 +- ui/app/templates/components/client-node-row.hbs | 4 +++- .../components/job-page/parts/stats-box.hbs | 2 +- ui/app/templates/components/job-row.hbs | 2 +- 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .changelog/18021.txt diff --git a/.changelog/18021.txt b/.changelog/18021.txt new file mode 100644 index 000000000..e9a355432 --- /dev/null +++ b/.changelog/18021.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fixed a bug that could cause an error when accessing a region running versions of Nomad prior to 1.6.0 +``` diff --git a/ui/app/adapters/node-pool.js b/ui/app/adapters/node-pool.js index 93943b0f0..3fb92d270 100644 --- a/ui/app/adapters/node-pool.js +++ b/ui/app/adapters/node-pool.js @@ -14,4 +14,21 @@ export default class NodePoolAdapter extends ApplicationAdapter { resource = pluralize(resource); return `/v1/${relationshipResource}/${resource}`; } + + findAll() { + return super.findAll(...arguments).catch((error) => { + // Handle the case where the node pool request is sent to a region that + // doesn't have node pools and the request is handled by the nodes + // endpoint. + const isNodeRequest = error.message.includes( + 'node lookup failed: index error: UUID must be 36 characters' + ); + if (isNodeRequest) { + return []; + } + + // Rethrow to be handled downstream. + throw error; + }); + } } diff --git a/ui/app/templates/clients/client/index.hbs b/ui/app/templates/clients/client/index.hbs index 8ef064f1c..8b726508d 100644 --- a/ui/app/templates/clients/client/index.hbs +++ b/ui/app/templates/clients/client/index.hbs @@ -247,7 +247,7 @@ Node Pool - {{this.model.nodePool}} + {{#if this.model.nodePool}}{{this.model.nodePool}}{{else}}-{{/if}} {{#if this.model.nodeClass}} diff --git a/ui/app/templates/components/client-node-row.hbs b/ui/app/templates/components/client-node-row.hbs index 000761d54..716cf903d 100644 --- a/ui/app/templates/components/client-node-row.hbs +++ b/ui/app/templates/components/client-node-row.hbs @@ -18,7 +18,9 @@ {{this.node.httpAddr}} -{{this.node.nodePool}} + + {{#if this.node.nodePool}}{{this.node.nodePool}}{{else}}-{{/if}} + {{this.node.datacenter}} {{this.node.version}} {{if this.node.hostVolumes.length this.node.hostVolumes.length}} diff --git a/ui/app/templates/components/job-page/parts/stats-box.hbs b/ui/app/templates/components/job-page/parts/stats-box.hbs index 1db2330c5..7619c73f8 100644 --- a/ui/app/templates/components/job-page/parts/stats-box.hbs +++ b/ui/app/templates/components/job-page/parts/stats-box.hbs @@ -33,7 +33,7 @@ {{/if}} Node Pool - {{@job.nodePool}} + {{#if @job.nodePool}}{{@job.nodePool}}{{else}}-{{/if}} {{yield to="after-namespace"}} diff --git a/ui/app/templates/components/job-row.hbs b/ui/app/templates/components/job-row.hbs index 41bc464a7..3f1bfe6e9 100644 --- a/ui/app/templates/components/job-row.hbs +++ b/ui/app/templates/components/job-row.hbs @@ -47,7 +47,7 @@ {{this.job.displayType.type}} - {{this.job.nodePool}} + {{#if this.job.nodePool}}{{this.job.nodePool}}{{else}}-{{/if}} {{this.job.priority}}