From 96522e7f53b6bb81ebc82c0a0ca5e608198304c7 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 18 Nov 2019 22:36:07 -0800 Subject: [PATCH] Drain stop and update and notifications --- ui/app/components/drain-popover.js | 3 +- ui/app/controllers/clients/client.js | 19 ++++++ ui/app/models/node.js | 4 ++ ui/app/routes/clients/client.js | 7 ++ ui/app/styles/core/section.scss | 4 ++ ui/app/templates/clients/client.hbs | 67 +++++++++++++++++-- ui/app/templates/components/drain-popover.hbs | 2 +- 7 files changed, 99 insertions(+), 7 deletions(-) diff --git a/ui/app/components/drain-popover.js b/ui/app/components/drain-popover.js index bc7ba1128..f1fb5680d 100644 --- a/ui/app/components/drain-popover.js +++ b/ui/app/components/drain-popover.js @@ -49,6 +49,7 @@ export default Component.extend({ drain: task(function*(close) { if (!this.client) return; + const isUpdating = this.client.isDraining; let deadline; try { @@ -71,7 +72,7 @@ export default Component.extend({ } else { yield this.client.drain(spec); } - this.onDrain(); + this.onDrain(isUpdating); } catch (err) { this.onError(err); } diff --git a/ui/app/controllers/clients/client.js b/ui/app/controllers/clients/client.js index fcdc38872..250a98704 100644 --- a/ui/app/controllers/clients/client.js +++ b/ui/app/controllers/clients/client.js @@ -42,7 +42,10 @@ export default Controller.extend(Sortable, Searchable, { sortedAllocations: alias('listSearched'), eligibilityError: null, + stopDrainError: null, showDrainNotification: false, + showDrainUpdateNotification: false, + showDrainStoppedNotification: false, preemptions: computed('model.allocations.@each.wasPreempted', function() { return this.model.allocations.filterBy('wasPreempted'); @@ -67,6 +70,18 @@ export default Controller.extend(Sortable, Searchable, { } }).drop(), + stopDrain: task(function*() { + try { + this.set('flagAsDraining', false); + yield this.model.cancelDrain(); + this.set('showDrainStoppedNotification', true); + } catch (err) { + this.set('flagAsDraining', true); + const error = messageFromAdapterError(err) || 'Could not stop drain'; + this.set('stopDrainError', error); + } + }).drop(), + triggerDrainNotification: observer('model.isDraining', function() { if (!this.model.isDraining && this.flagAsDraining) { this.set('showDrainNotification', true); @@ -83,5 +98,9 @@ export default Controller.extend(Sortable, Searchable, { setPreemptionFilter(value) { this.set('onlyPreemptions', value); }, + + drainNotify(isUpdating) { + this.set('showDrainUpdateNotification', isUpdating); + }, }, }); diff --git a/ui/app/models/node.js b/ui/app/models/node.js index 631e69ddd..e685d4e54 100644 --- a/ui/app/models/node.js +++ b/ui/app/models/node.js @@ -112,4 +112,8 @@ export default Model.extend({ forceDrain(drainSpec) { return this.store.adapterFor('node').forceDrain(this, drainSpec); }, + + cancelDrain() { + return this.store.adapterFor('node').cancelDrain(this); + }, }); diff --git a/ui/app/routes/clients/client.js b/ui/app/routes/clients/client.js index 5595525d7..19988d7d0 100644 --- a/ui/app/routes/clients/client.js +++ b/ui/app/routes/clients/client.js @@ -35,6 +35,13 @@ export default Route.extend(WithWatchers, { return this._super(...arguments); }, + resetController(controller) { + controller.setProperties({ + eligibilityError: null, + stopDrainError: null, + }); + }, + startWatchers(controller, model) { if (model) { controller.set('watchModel', this.watch.perform(model)); diff --git a/ui/app/styles/core/section.scss b/ui/app/styles/core/section.scss index 14f1d27a7..09bafee30 100644 --- a/ui/app/styles/core/section.scss +++ b/ui/app/styles/core/section.scss @@ -1,6 +1,10 @@ .section { padding: 1.5rem; max-width: 1200px; + + &.with-headspace { + margin-top: 1.5rem; + } } .full-width-section { diff --git a/ui/app/templates/clients/client.hbs b/ui/app/templates/clients/client.hbs index fc2475784..5351dadb3 100644 --- a/ui/app/templates/clients/client.hbs +++ b/ui/app/templates/clients/client.hbs @@ -1,9 +1,55 @@ {{title "Client " (or model.name model.shortId)}} -
+
{{#if eligibilityError}} -
-

Eligibility Error

-

{{eligibilityError}}

+
+
+
+

Eligibility Error

+

{{eligibilityError}}

+
+
+
+ +
+
+ {{/if}} + {{#if stopDrainError}} +
+
+
+

Stop Drain Error

+

{{stopDrainError}}

+
+
+
+ +
+
+ {{/if}} + {{#if showDrainStoppedNotification}} +
+
+
+

Drain Stopped

+

The drain has been stopped and the node has been set to ineligible.

+
+
+ +
+
+
+ {{/if}} + {{#if showDrainUpdateNotification}} +
+
+
+

Drain Updated

+

The new drain specification has been applied.

+
+
+ +
+
{{/if}} {{#if showDrainNotification}} @@ -48,7 +94,18 @@

- {{drain-popover client=model}} + {{#if model.isDraining}} + {{two-step-button + idleText="Stop Drain" + cancelText="Cancel" + confirmText="Yes, Stop" + confirmationMessage="Are you sure you want to stop this drain?" + awaitingConfirmation=stopDrain.isRunning + onConfirm=(perform stopDrain)}} + {{/if}} +
+
+ {{drain-popover client=model onDrain=(action "drainNotify")}}
diff --git a/ui/app/templates/components/drain-popover.hbs b/ui/app/templates/components/drain-popover.hbs index eb954bf3f..4d9c8e899 100644 --- a/ui/app/templates/components/drain-popover.hbs +++ b/ui/app/templates/components/drain-popover.hbs @@ -1,6 +1,6 @@ {{#popover-menu label=(if client.isDraining "Update" "Drain") - triggerClass=(if drain.isRunning "is-loading") as |m|}} + triggerClass=(concat "is-small " (if drain.isRunning "is-loading")) as |m|}}

Drain Options