Properly manage the lifecycle of allocations for storage nodes and controllers
This commit is contained in:
parent
c84070fc42
commit
de74239430
|
@ -46,6 +46,10 @@ export default Component.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
|
this.updateStatsTracker();
|
||||||
|
},
|
||||||
|
|
||||||
|
updateStatsTracker() {
|
||||||
const allocation = this.allocation;
|
const allocation = this.allocation;
|
||||||
|
|
||||||
if (allocation) {
|
if (allocation) {
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
import { alias } from '@ember/object/computed';
|
|
||||||
import AllocationRow from 'nomad-ui/components/allocation-row';
|
import AllocationRow from 'nomad-ui/components/allocation-row';
|
||||||
|
|
||||||
export default AllocationRow.extend({
|
export default AllocationRow.extend({
|
||||||
pluginAllocation: null,
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import { computed } from '@ember/object';
|
|
||||||
import attr from 'ember-data/attr';
|
import attr from 'ember-data/attr';
|
||||||
import { belongsTo } from 'ember-data/relationships';
|
import { belongsTo } from 'ember-data/relationships';
|
||||||
import Fragment from 'ember-data-model-fragments/fragment';
|
import Fragment from 'ember-data-model-fragments/fragment';
|
||||||
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
|
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
|
||||||
import PromiseObject from 'nomad-ui/utils/classes/promise-object';
|
|
||||||
|
|
||||||
export default Fragment.extend({
|
export default Fragment.extend({
|
||||||
plugin: fragmentOwner(),
|
plugin: fragmentOwner(),
|
||||||
|
@ -11,16 +9,6 @@ export default Fragment.extend({
|
||||||
node: belongsTo('node'),
|
node: belongsTo('node'),
|
||||||
allocID: attr('string'),
|
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'),
|
provider: attr('string'),
|
||||||
version: attr('string'),
|
version: attr('string'),
|
||||||
healthy: attr('boolean'),
|
healthy: attr('boolean'),
|
||||||
|
@ -30,4 +18,9 @@ export default Fragment.extend({
|
||||||
requiresTopologies: attr('boolean'),
|
requiresTopologies: attr('boolean'),
|
||||||
|
|
||||||
controllerInfo: attr(),
|
controllerInfo: attr(),
|
||||||
|
|
||||||
|
// Fragments can't have relationships, so provider a manual getter instead.
|
||||||
|
async getAllocation() {
|
||||||
|
return this.store.findRecord('allocation', this.allocID);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import { computed } from '@ember/object';
|
|
||||||
import attr from 'ember-data/attr';
|
import attr from 'ember-data/attr';
|
||||||
import { belongsTo } from 'ember-data/relationships';
|
import { belongsTo } from 'ember-data/relationships';
|
||||||
import Fragment from 'ember-data-model-fragments/fragment';
|
import Fragment from 'ember-data-model-fragments/fragment';
|
||||||
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
|
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
|
||||||
import PromiseObject from 'nomad-ui/utils/classes/promise-object';
|
|
||||||
|
|
||||||
export default Fragment.extend({
|
export default Fragment.extend({
|
||||||
plugin: fragmentOwner(),
|
plugin: fragmentOwner(),
|
||||||
|
@ -11,16 +9,6 @@ export default Fragment.extend({
|
||||||
node: belongsTo('node'),
|
node: belongsTo('node'),
|
||||||
allocID: attr('string'),
|
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'),
|
provider: attr('string'),
|
||||||
version: attr('string'),
|
version: attr('string'),
|
||||||
healthy: attr('boolean'),
|
healthy: attr('boolean'),
|
||||||
|
@ -30,4 +18,9 @@ export default Fragment.extend({
|
||||||
requiresTopologies: attr('boolean'),
|
requiresTopologies: attr('boolean'),
|
||||||
|
|
||||||
nodeInfo: attr(),
|
nodeInfo: attr(),
|
||||||
|
|
||||||
|
// Fragments can't have relationships, so provider a manual getter instead.
|
||||||
|
async getAllocation() {
|
||||||
|
return this.store.findRecord('allocation', this.allocID);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue