2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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';
|
2019-10-15 18:32:58 +00:00
|
|
|
import { computed as overridable } from 'ember-overridable-computed';
|
2018-09-20 22:36:13 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
2022-03-08 17:28:36 +00:00
|
|
|
import { scheduleOnce } 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';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2022-03-08 17:28:36 +00:00
|
|
|
import {
|
|
|
|
classNames,
|
|
|
|
tagName,
|
|
|
|
attributeBindings,
|
|
|
|
} from '@ember-decorators/component';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('tr')
|
|
|
|
@classNames('allocation-row', 'is-interactive')
|
2022-03-08 17:28:36 +00:00
|
|
|
@attributeBindings(
|
|
|
|
'data-test-allocation',
|
|
|
|
'data-test-write-allocation',
|
|
|
|
'data-test-read-allocation'
|
|
|
|
)
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class AllocationRow extends Component {
|
|
|
|
@service store;
|
|
|
|
@service token;
|
2017-10-05 22:21:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
allocation = null;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// Used to determine whether the row should mention the node or the job
|
2020-06-10 13:49:16 +00:00
|
|
|
context = null;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-03-22 21:34:57 +00:00
|
|
|
// Internal state
|
2020-06-10 13:49:16 +00:00
|
|
|
statsError = false;
|
2018-03-22 21:34:57 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@overridable(() => !Ember.testing) enablePolling;
|
2018-04-21 01:11:32 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('allocation', 'allocation.isRunning')
|
|
|
|
get stats() {
|
2020-06-10 14:07:16 +00:00
|
|
|
if (!this.get('allocation.isRunning')) return undefined;
|
2018-12-10 23:25:48 +00:00
|
|
|
|
2018-09-20 22:36:13 +00:00
|
|
|
return AllocationStatsTracker.create({
|
2021-12-28 14:45:20 +00:00
|
|
|
fetch: (url) => this.token.authorizedRequest(url),
|
2019-03-26 07:46:44 +00:00
|
|
|
allocation: this.allocation,
|
2018-09-20 22:36:13 +00:00
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-09-20 22:36:13 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('stats.cpu.lastObject') cpu;
|
|
|
|
@alias('stats.memory.lastObject') memory;
|
2018-09-20 22:36:13 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
onClick() {}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
click(event) {
|
2019-03-26 07:46:44 +00:00
|
|
|
lazyClick([this.onClick, event]);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-10-04 00:18:33 +00:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2021-12-28 14:45:20 +00:00
|
|
|
super.didReceiveAttrs();
|
2020-05-12 02:59:38 +00:00
|
|
|
this.updateStatsTracker();
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-12 02:59:38 +00:00
|
|
|
|
|
|
|
updateStatsTracker() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const allocation = this.allocation;
|
2018-03-22 21:34:57 +00:00
|
|
|
|
|
|
|
if (allocation) {
|
2022-03-08 17:28:36 +00:00
|
|
|
scheduleOnce('afterRender', this, qualifyAllocation);
|
2018-03-22 21:34:57 +00:00
|
|
|
} else {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.fetchStats.cancelAll();
|
2018-03-22 21:34:57 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-03-22 21:34:57 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@(task(function* () {
|
2018-03-22 21:34:57 +00:00
|
|
|
do {
|
2019-03-26 07:46:44 +00:00
|
|
|
if (this.stats) {
|
2018-12-10 23:25:48 +00:00
|
|
|
try {
|
2021-12-28 14:45:20 +00:00
|
|
|
yield this.get('stats.poll').linked().perform();
|
2018-12-10 23:25:48 +00:00
|
|
|
this.set('statsError', false);
|
|
|
|
} catch (error) {
|
|
|
|
this.set('statsError', true);
|
|
|
|
}
|
2018-03-22 21:34:57 +00:00
|
|
|
}
|
2018-12-10 23:25:48 +00:00
|
|
|
|
2018-09-20 22:36:13 +00:00
|
|
|
yield timeout(500);
|
2019-03-26 07:46:44 +00:00
|
|
|
} while (this.enablePolling);
|
2020-06-10 13:49:16 +00:00
|
|
|
}).drop())
|
|
|
|
fetchStats;
|
|
|
|
}
|
2017-10-18 02:18:04 +00:00
|
|
|
|
2020-05-05 21:23:25 +00:00
|
|
|
async function qualifyAllocation() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const allocation = this.allocation;
|
2020-05-01 21:27:53 +00:00
|
|
|
|
|
|
|
// Make sure the allocation is a complete record and not a partial so we
|
|
|
|
// can show information such as preemptions and rescheduled allocation.
|
2020-05-13 04:28:40 +00:00
|
|
|
if (allocation.isPartial) {
|
2021-12-28 16:08:12 +00:00
|
|
|
await this.store.findRecord('allocation', allocation.id, {
|
|
|
|
backgroundReload: false,
|
|
|
|
});
|
2020-05-13 04:28:40 +00:00
|
|
|
}
|
2018-05-02 20:59:28 +00:00
|
|
|
|
2020-05-05 21:23:25 +00:00
|
|
|
if (allocation.get('job.isPending')) {
|
|
|
|
// Make sure the job is loaded before starting the stats tracker
|
|
|
|
await allocation.get('job');
|
|
|
|
} else if (!allocation.get('taskGroup')) {
|
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
|
2020-05-05 21:23:25 +00:00
|
|
|
const job = allocation.get('job.content');
|
2022-09-30 20:14:40 +00:00
|
|
|
if (job.isPartial) await job.reload();
|
2020-05-05 21:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.fetchStats.perform();
|
2017-10-18 02:18:04 +00:00
|
|
|
}
|