From 32b4e5e8abbea6476cc174cded1e61b2c7115b2a Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 11 May 2020 19:59:38 -0700 Subject: [PATCH] Properly manage the lifecycle of allocations for storage nodes and controllers --- ui/app/components/allocation-row.js | 4 ++++ ui/app/components/plugin-allocation-row.js | 20 ++++++++++++++++++-- ui/app/models/storage-controller.js | 17 +++++------------ ui/app/models/storage-node.js | 17 +++++------------ 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/ui/app/components/allocation-row.js b/ui/app/components/allocation-row.js index 3e00ea645..de07e0b0a 100644 --- a/ui/app/components/allocation-row.js +++ b/ui/app/components/allocation-row.js @@ -46,6 +46,10 @@ export default Component.extend({ }, didReceiveAttrs() { + this.updateStatsTracker(); + }, + + updateStatsTracker() { const allocation = this.allocation; if (allocation) { diff --git a/ui/app/components/plugin-allocation-row.js b/ui/app/components/plugin-allocation-row.js index f3fef64d8..802c70034 100644 --- a/ui/app/components/plugin-allocation-row.js +++ b/ui/app/components/plugin-allocation-row.js @@ -1,7 +1,23 @@ -import { alias } from '@ember/object/computed'; import AllocationRow from 'nomad-ui/components/allocation-row'; export default AllocationRow.extend({ pluginAllocation: null, - allocation: alias('pluginAllocation.allocation'), + allocation: null, + + didReceiveAttrs() { + this.setAllocation(); + }, + + // The allocation for the plugin's controller or storage plugin needs + // to be imperatively fetched since these plugins are Fragments which + // can't have relationships. + async setAllocation() { + if (this.pluginAllocation && !this.allocation) { + const allocation = await this.pluginAllocation.getAllocation(); + if (!this.isDestroyed) { + this.set('allocation', allocation); + this.updateStatsTracker(); + } + } + }, }); diff --git a/ui/app/models/storage-controller.js b/ui/app/models/storage-controller.js index e7b3aeea7..4d7c44114 100644 --- a/ui/app/models/storage-controller.js +++ b/ui/app/models/storage-controller.js @@ -1,9 +1,7 @@ -import { computed } from '@ember/object'; import attr from 'ember-data/attr'; import { belongsTo } from 'ember-data/relationships'; import Fragment from 'ember-data-model-fragments/fragment'; import { fragmentOwner } from 'ember-data-model-fragments/attributes'; -import PromiseObject from 'nomad-ui/utils/classes/promise-object'; export default Fragment.extend({ plugin: fragmentOwner(), @@ -11,16 +9,6 @@ export default Fragment.extend({ node: belongsTo('node'), allocID: attr('string'), - // Model fragments don't support relationships, but with an allocation ID - // a "belongsTo" can be sufficiently mocked. - allocation: computed('allocID', function() { - if (!this.allocID) return null; - return PromiseObject.create({ - promise: this.store.findRecord('allocation', this.allocID), - reload: () => this.store.findRecord('allocation', this.allocID), - }); - }), - provider: attr('string'), version: attr('string'), healthy: attr('boolean'), @@ -30,4 +18,9 @@ export default Fragment.extend({ requiresTopologies: attr('boolean'), controllerInfo: attr(), + + // Fragments can't have relationships, so provider a manual getter instead. + async getAllocation() { + return this.store.findRecord('allocation', this.allocID); + }, }); diff --git a/ui/app/models/storage-node.js b/ui/app/models/storage-node.js index 819279717..65e43050e 100644 --- a/ui/app/models/storage-node.js +++ b/ui/app/models/storage-node.js @@ -1,9 +1,7 @@ -import { computed } from '@ember/object'; import attr from 'ember-data/attr'; import { belongsTo } from 'ember-data/relationships'; import Fragment from 'ember-data-model-fragments/fragment'; import { fragmentOwner } from 'ember-data-model-fragments/attributes'; -import PromiseObject from 'nomad-ui/utils/classes/promise-object'; export default Fragment.extend({ plugin: fragmentOwner(), @@ -11,16 +9,6 @@ export default Fragment.extend({ node: belongsTo('node'), allocID: attr('string'), - // Model fragments don't support relationships, but with an allocation ID - // a "belongsTo" can be sufficiently mocked. - allocation: computed('allocID', function() { - if (!this.allocID) return null; - return PromiseObject.create({ - promise: this.store.findRecord('allocation', this.allocID), - reload: () => this.store.findRecord('allocation', this.allocID), - }); - }), - provider: attr('string'), version: attr('string'), healthy: attr('boolean'), @@ -30,4 +18,9 @@ export default Fragment.extend({ requiresTopologies: attr('boolean'), nodeInfo: attr(), + + // Fragments can't have relationships, so provider a manual getter instead. + async getAllocation() { + return this.store.findRecord('allocation', this.allocID); + }, });