Skip to content

Commit

Permalink
ui: persist node drain setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Oct 21, 2021
1 parent 82a3ae7 commit b58f27a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
26 changes: 26 additions & 0 deletions ui/app/components/drain-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { task } from 'ember-concurrency';
import Duration from 'duration-js';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';

@classic
@tagName('')
Expand All @@ -22,6 +23,23 @@ export default class DrainPopover extends Component {
forceDrain = false;
drainSystemJobs = true;

@localStorageProperty('nomadDrainOptions', {}) drainOptions;

didReceiveAttrs() {
// Load drain config values from local storage if availabe.
[
'deadlineEnabled',
'customDuration',
'forceDrain',
'drainSystemJobs',
'selectedDurationQuickOption',
].forEach(k => {
if (k in this.drainOptions) {
this[k] = this.drainOptions[k];
}
});
}

@overridable(function() {
return this.durationQuickOptions[0];
})
Expand Down Expand Up @@ -71,6 +89,14 @@ export default class DrainPopover extends Component {
IgnoreSystemJobs: !this.drainSystemJobs,
};

this.drainOptions = {
deadlineEnabled: this.deadlineEnabled,
customDuration: this.deadline,
selectedDurationQuickOption: this.selectedDurationQuickOption,
drainSystemJobs: this.drainSystemJobs,
forceDrain: this.forceDrain,
};

close();

try {
Expand Down
1 change: 1 addition & 0 deletions ui/app/templates/components/drain-popover.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
type="text"
class="input {{if this.parseError "is-danger"}}"
placeholder="1h30m"
value="{{this.customDuration}}"
oninput={{action (queue
(action (mut this.parseError) '')
(action (mut this.customDuration) value="target.value"))}} />
Expand Down
45 changes: 44 additions & 1 deletion ui/tests/acceptance/client-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ let clientToken;
const wasPreemptedFilter = allocation => !!allocation.preemptedByAllocation;

function nonSearchPOSTS() {
return server.pretender.handledRequests.reject(request => request.url.includes('fuzzy')).filterBy('method', 'POST');
return server.pretender.handledRequests
.reject(request => request.url.includes('fuzzy'))
.filterBy('method', 'POST');
}

module('Acceptance | client detail', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(function() {
window.localStorage.clear();

server.create('node', 'forceIPv4', { schedulingEligibility: 'eligible' });
node = server.db.nodes[0];

Expand Down Expand Up @@ -734,6 +738,45 @@ module('Acceptance | client detail', function(hooks) {
);
});

test('starting a drain persists options to localstorage', async function(assert) {
const nodes = server.createList('node', 2, {
drain: false,
schedulingEligibility: 'eligible',
});

await ClientDetail.visit({ id: nodes[0].id });
await ClientDetail.drainPopover.toggle();

// Change all options to non-default values.
await ClientDetail.drainPopover.deadlineToggle.toggle();
await ClientDetail.drainPopover.deadlineOptions.open();
const optionsCount = ClientDetail.drainPopover.deadlineOptions.options.length;
await ClientDetail.drainPopover.deadlineOptions.options.objectAt(optionsCount - 1).choose();
await ClientDetail.drainPopover.setCustomDeadline('1h40m20s');
await ClientDetail.drainPopover.forceDrainToggle.toggle();
await ClientDetail.drainPopover.systemJobsToggle.toggle();

await ClientDetail.drainPopover.submit();

const got = JSON.parse(window.localStorage.nomadDrainOptions);
const want = {
deadlineEnabled: true,
customDuration: '1h40m20s',
selectedDurationQuickOption: { label: 'Custom', value: 'custom' },
drainSystemJobs: false,
forceDrain: true,
};
assert.deepEqual(got, want);

// Visit another node and check that drain config is persisted.
await ClientDetail.visit({ id: nodes[1].id });
await ClientDetail.drainPopover.toggle();
assert.true(ClientDetail.drainPopover.deadlineToggle.isActive);
assert.equal(ClientDetail.drainPopover.customDeadline, '1h40m20s');
assert.true(ClientDetail.drainPopover.forceDrainToggle.isActive);
assert.false(ClientDetail.drainPopover.systemJobsToggle.isActive);
});

test('the drain popover cancel button closes the popover', async function(assert) {
node = server.create('node', {
drain: false,
Expand Down
7 changes: 5 additions & 2 deletions ui/tests/pages/clients/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
fillable,
text,
isPresent,
value,
visitable,
} from 'ember-cli-page-object';

Expand Down Expand Up @@ -118,15 +119,17 @@ export default create({

deadlineToggle: toggle('[data-test-drain-deadline-toggle]'),
deadlineOptions: {
open: clickable('[data-test-drain-deadline-option-select-parent] .ember-power-select-trigger'),
open: clickable(
'[data-test-drain-deadline-option-select-parent] .ember-power-select-trigger'
),
options: collection('.ember-power-select-option', {
label: text(),
choose: clickable(),
}),
},

setCustomDeadline: fillable('[data-test-drain-custom-deadline]'),
customDeadline: attribute('value', '[data-test-drain-custom-deadline]'),
customDeadline: value('[data-test-drain-custom-deadline]'),
forceDrainToggle: toggle('[data-test-force-drain-toggle]'),
systemJobsToggle: toggle('[data-test-system-jobs-toggle]'),

Expand Down

0 comments on commit b58f27a

Please sign in to comment.