2018-03-22 21:34:57 +00:00
|
|
|
import Ember from 'ember';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Component from '@ember/component';
|
2018-04-21 01:11:32 +00:00
|
|
|
import { computed } from '@ember/object';
|
2018-09-20 22:36:13 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { run } from '@ember/runloop';
|
2018-03-22 21:34:57 +00:00
|
|
|
import { task, timeout } from 'ember-concurrency';
|
2018-09-20 22:36:13 +00:00
|
|
|
import { lazyClick } from '../helpers/lazy-click';
|
|
|
|
import AllocationStatsTracker from 'nomad-ui/utils/classes/allocation-stats-tracker';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
2017-12-15 21:39:18 +00:00
|
|
|
store: service(),
|
2018-09-20 22:36:13 +00:00
|
|
|
token: service(),
|
2017-10-05 22:21:10 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
tagName: 'tr',
|
|
|
|
|
|
|
|
classNames: ['allocation-row', 'is-interactive'],
|
|
|
|
|
|
|
|
allocation: null,
|
|
|
|
|
|
|
|
// Used to determine whether the row should mention the node or the job
|
|
|
|
context: null,
|
|
|
|
|
2018-03-22 21:34:57 +00:00
|
|
|
// Internal state
|
|
|
|
statsError: false,
|
|
|
|
|
2018-05-05 02:04:36 +00:00
|
|
|
enablePolling: computed(() => !Ember.testing),
|
2018-04-21 01:11:32 +00:00
|
|
|
|
2018-09-20 22:36:13 +00:00
|
|
|
stats: computed('allocation', function() {
|
|
|
|
return AllocationStatsTracker.create({
|
|
|
|
fetch: url => this.get('token').authorizedRequest(url),
|
|
|
|
allocation: this.get('allocation'),
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
cpu: alias('stats.cpu.lastObject'),
|
|
|
|
memory: alias('stats.memory.lastObject'),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
onClick() {},
|
|
|
|
|
|
|
|
click(event) {
|
2017-09-26 18:57:46 +00:00
|
|
|
lazyClick([this.get('onClick'), event]);
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
2017-10-04 00:18:33 +00:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2018-03-22 21:34:57 +00:00
|
|
|
const allocation = this.get('allocation');
|
|
|
|
|
|
|
|
if (allocation) {
|
2018-05-02 20:59:28 +00:00
|
|
|
run.scheduleOnce('afterRender', this, qualifyAllocation);
|
2018-03-22 21:34:57 +00:00
|
|
|
} else {
|
|
|
|
this.get('fetchStats').cancelAll();
|
|
|
|
}
|
2017-10-04 00:18:33 +00:00
|
|
|
},
|
2018-03-22 21:34:57 +00:00
|
|
|
|
2018-09-20 22:36:13 +00:00
|
|
|
fetchStats: task(function*() {
|
2018-03-22 21:34:57 +00:00
|
|
|
do {
|
|
|
|
try {
|
2018-09-20 22:36:13 +00:00
|
|
|
yield this.get('stats.poll').perform();
|
2018-04-20 23:50:54 +00:00
|
|
|
this.set('statsError', false);
|
2018-03-22 21:34:57 +00:00
|
|
|
} catch (error) {
|
|
|
|
this.set('statsError', true);
|
|
|
|
}
|
2018-09-20 22:36:13 +00:00
|
|
|
yield timeout(500);
|
2018-04-21 01:11:32 +00:00
|
|
|
} while (this.get('enablePolling'));
|
2018-03-22 21:34:57 +00:00
|
|
|
}).drop(),
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2017-10-18 02:18:04 +00:00
|
|
|
|
2018-05-02 20:59:28 +00:00
|
|
|
function qualifyAllocation() {
|
|
|
|
const allocation = this.get('allocation');
|
|
|
|
return allocation.reload().then(() => {
|
2018-09-20 22:36:13 +00:00
|
|
|
this.get('fetchStats').perform();
|
2018-05-02 20:59:28 +00:00
|
|
|
|
2018-06-13 22:05:18 +00:00
|
|
|
// Make sure that the job record in the store for this allocation
|
|
|
|
// is complete and not a partial from the list endpoint
|
|
|
|
if (
|
|
|
|
allocation &&
|
|
|
|
allocation.get('job') &&
|
|
|
|
!allocation.get('job.isPending') &&
|
|
|
|
!allocation.get('taskGroup')
|
|
|
|
) {
|
|
|
|
const job = allocation.get('job.content');
|
|
|
|
job && job.reload();
|
2017-10-18 02:18:04 +00:00
|
|
|
}
|
2018-06-13 22:05:18 +00:00
|
|
|
});
|
2017-10-18 02:18:04 +00:00
|
|
|
}
|