diff --git a/.changelog/24723.txt b/.changelog/24723.txt new file mode 100644 index 00000000000..b788768b7c8 --- /dev/null +++ b/.changelog/24723.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: add leadership status for servers in other regions +``` diff --git a/ui/app/models/agent.js b/ui/app/models/agent.js index 306e642ad92..fbf9f009857 100644 --- a/ui/app/models/agent.js +++ b/ui/app/models/agent.js @@ -7,10 +7,10 @@ import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; import Model from '@ember-data/model'; import { attr } from '@ember-data/model'; -import classic from 'ember-classic-decorator'; +import { tracked } from '@glimmer/tracking'; +import { action } from '@ember/object'; import formatHost from 'nomad-ui/utils/format-host'; -@classic export default class Agent extends Model { @service system; @@ -29,9 +29,12 @@ export default class Agent extends Model { return formatHost(address, rpcPort); } - @computed('rpcAddr', 'system.leader.rpcAddr') - get isLeader() { - return this.get('system.leader.rpcAddr') === this.rpcAddr; + @tracked isLeader = false; + + @action async checkForLeadership() { + const leaders = await this.system.leaders; + this.isLeader = leaders.includes(this.rpcAddr); + return this.isLeader; } @computed('tags.build') diff --git a/ui/app/routes/clients.js b/ui/app/routes/clients.js index e74f9bdc0e4..afda9aba99e 100644 --- a/ui/app/routes/clients.js +++ b/ui/app/routes/clients.js @@ -13,11 +13,6 @@ import classic from 'ember-classic-decorator'; @classic export default class ClientsRoute extends Route.extend(WithForbiddenState) { @service store; - @service system; - - beforeModel() { - return this.get('system.leader'); - } model() { return RSVP.hash({ diff --git a/ui/app/routes/servers.js b/ui/app/routes/servers.js index 3dcb8d733c8..f11aa28657a 100644 --- a/ui/app/routes/servers.js +++ b/ui/app/routes/servers.js @@ -15,14 +15,16 @@ export default class ServersRoute extends Route.extend(WithForbiddenState) { @service store; @service system; - beforeModel() { - return this.get('system.leader'); + async beforeModel() { + await this.system.leaders; } - model() { + async model() { + const agents = await this.store.findAll('agent'); + await Promise.all(agents.map((agent) => agent.checkForLeadership())); return RSVP.hash({ nodes: this.store.findAll('node'), - agents: this.store.findAll('agent'), + agents, }).catch(notifyForbidden(this)); } } diff --git a/ui/app/services/system.js b/ui/app/services/system.js index f88163b4bb0..864d61e5e9c 100644 --- a/ui/app/services/system.js +++ b/ui/app/services/system.js @@ -12,27 +12,23 @@ import { namespace } from '../adapters/application'; import jsonWithDefault from '../utils/json-with-default'; import classic from 'ember-classic-decorator'; import { task } from 'ember-concurrency'; - @classic export default class SystemService extends Service { @service token; @service store; - @computed('activeRegion') - get leader() { - const token = this.token; - - return PromiseObject.create({ - promise: token - .authorizedRequest(`/${namespace}/status/leader`) - .then((res) => res.json()) - .then((rpcAddr) => ({ rpcAddr })) - .then((leader) => { - // Dirty self so leader can be used as a dependent key - this.notifyPropertyChange('leader.rpcAddr'); - return leader; - }), - }); + /** + * Iterates over all regions and returns a list of leaders' rpcAddrs + */ + @computed('regions.[]') + get leaders() { + return Promise.all( + this.regions.map((region) => { + return this.token + .authorizedRequest(`/${namespace}/status/leader?region=${region}`) + .then((res) => res.json()); + }) + ); } @computed diff --git a/ui/app/styles/core/table.scss b/ui/app/styles/core/table.scss index 549fdd11637..3dbb8d91c7b 100644 --- a/ui/app/styles/core/table.scss +++ b/ui/app/styles/core/table.scss @@ -110,7 +110,8 @@ white-space: nowrap; } - &.node-status-badges { + &.node-status-badges, + &.server-status-badges { .hds-badge__text { white-space: nowrap; } diff --git a/ui/app/templates/components/server-agent-row.hbs b/ui/app/templates/components/server-agent-row.hbs index 302ace102b2..5cf4e892d91 100644 --- a/ui/app/templates/components/server-agent-row.hbs +++ b/ui/app/templates/components/server-agent-row.hbs @@ -4,7 +4,7 @@ ~}}