-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6819 from hashicorp/f-ui-node-drain
UI: Invoke Node Drains
- Loading branch information
Showing
41 changed files
with
1,753 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
import Watchable from './watchable'; | ||
import addToPath from 'nomad-ui/utils/add-to-path'; | ||
|
||
export default Watchable.extend(); | ||
export default Watchable.extend({ | ||
setEligible(node) { | ||
return this.setEligibility(node, true); | ||
}, | ||
|
||
setIneligible(node) { | ||
return this.setEligibility(node, false); | ||
}, | ||
|
||
setEligibility(node, isEligible) { | ||
const url = addToPath(this.urlForFindRecord(node.id, 'node'), '/eligibility'); | ||
return this.ajax(url, 'POST', { | ||
data: { | ||
NodeID: node.id, | ||
Eligibility: isEligible ? 'eligible' : 'ineligible', | ||
}, | ||
}); | ||
}, | ||
|
||
// Force: -1s deadline | ||
// No Deadline: 0 deadline | ||
drain(node, drainSpec) { | ||
const url = addToPath(this.urlForFindRecord(node.id, 'node'), '/drain'); | ||
return this.ajax(url, 'POST', { | ||
data: { | ||
NodeID: node.id, | ||
DrainSpec: Object.assign( | ||
{ | ||
Deadline: 0, | ||
IgnoreSystemJobs: true, | ||
}, | ||
drainSpec | ||
), | ||
}, | ||
}); | ||
}, | ||
|
||
forceDrain(node, drainSpec) { | ||
return this.drain( | ||
node, | ||
Object.assign({}, drainSpec, { | ||
Deadline: -1, | ||
}) | ||
); | ||
}, | ||
|
||
cancelDrain(node) { | ||
const url = addToPath(this.urlForFindRecord(node.id, 'node'), '/drain'); | ||
return this.ajax(url, 'POST', { | ||
data: { | ||
NodeID: node.id, | ||
DrainSpec: null, | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { equal } from '@ember/object/computed'; | ||
import { computed as overridable } from 'ember-overridable-computed'; | ||
import { task } from 'ember-concurrency'; | ||
import Duration from 'duration-js'; | ||
|
||
export default Component.extend({ | ||
tagName: '', | ||
|
||
client: null, | ||
|
||
onError() {}, | ||
onDrain() {}, | ||
|
||
parseError: '', | ||
|
||
deadlineEnabled: false, | ||
forceDrain: false, | ||
drainSystemJobs: true, | ||
|
||
selectedDurationQuickOption: overridable(function() { | ||
return this.durationQuickOptions[0]; | ||
}), | ||
|
||
durationIsCustom: equal('selectedDurationQuickOption.value', 'custom'), | ||
customDuration: '', | ||
|
||
durationQuickOptions: computed(() => [ | ||
{ label: '1 Hour', value: '1h' }, | ||
{ label: '4 Hours', value: '4h' }, | ||
{ label: '8 Hours', value: '8h' }, | ||
{ label: '12 Hours', value: '12h' }, | ||
{ label: '1 Day', value: '1d' }, | ||
{ label: 'Custom', value: 'custom' }, | ||
]), | ||
|
||
deadline: computed( | ||
'deadlineEnabled', | ||
'durationIsCustom', | ||
'customDuration', | ||
'selectedDurationQuickOption.value', | ||
function() { | ||
if (!this.deadlineEnabled) return 0; | ||
if (this.durationIsCustom) return this.customDuration; | ||
return this.selectedDurationQuickOption.value; | ||
} | ||
), | ||
|
||
drain: task(function*(close) { | ||
if (!this.client) return; | ||
const isUpdating = this.client.isDraining; | ||
|
||
let deadline; | ||
try { | ||
deadline = new Duration(this.deadline).nanoseconds(); | ||
} catch (err) { | ||
this.set('parseError', err.message); | ||
return; | ||
} | ||
|
||
const spec = { | ||
Deadline: deadline, | ||
IgnoreSystemJobs: !this.drainSystemJobs, | ||
}; | ||
|
||
close(); | ||
|
||
try { | ||
if (this.forceDrain) { | ||
yield this.client.forceDrain(spec); | ||
} else { | ||
yield this.client.drain(spec); | ||
} | ||
this.onDrain(isUpdating); | ||
} catch (err) { | ||
this.onError(err); | ||
} | ||
}), | ||
|
||
preventDefault(e) { | ||
e.preventDefault(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Component from '@ember/component'; | ||
import { run } from '@ember/runloop'; | ||
|
||
const TAB = 9; | ||
const ARROW_DOWN = 40; | ||
const FOCUSABLE = [ | ||
'a:not([disabled])', | ||
'button:not([disabled])', | ||
'input:not([disabled]):not([type="hidden"])', | ||
'textarea:not([disabled])', | ||
'[tabindex]:not([disabled]):not([tabindex="-1"])', | ||
].join(', '); | ||
|
||
export default Component.extend({ | ||
classnames: ['popover'], | ||
|
||
triggerClass: '', | ||
isOpen: false, | ||
label: '', | ||
|
||
dropdown: null, | ||
|
||
capture(dropdown) { | ||
// It's not a good idea to grab a dropdown reference like this, but it's necessary | ||
// in order to invoke dropdown.actions.close in traverseList as well as | ||
// dropdown.actions.reposition when the label or selection length changes. | ||
this.set('dropdown', dropdown); | ||
}, | ||
|
||
didReceiveAttrs() { | ||
const dropdown = this.dropdown; | ||
if (this.isOpen && dropdown) { | ||
run.scheduleOnce('afterRender', () => { | ||
dropdown.actions.reposition(); | ||
}); | ||
} | ||
}, | ||
|
||
actions: { | ||
openOnArrowDown(dropdown, e) { | ||
if (!this.isOpen && e.keyCode === ARROW_DOWN) { | ||
dropdown.actions.open(e); | ||
e.preventDefault(); | ||
} else if (this.isOpen && (e.keyCode === TAB || e.keyCode === ARROW_DOWN)) { | ||
const optionsId = this.element.querySelector('.popover-trigger').getAttribute('aria-owns'); | ||
const popoverContentEl = document.querySelector(`#${optionsId}`); | ||
const firstFocusableElement = popoverContentEl.querySelector(FOCUSABLE); | ||
|
||
if (firstFocusableElement) { | ||
firstFocusableElement.focus(); | ||
e.preventDefault(); | ||
} | ||
} | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Component from '@ember/component'; | ||
|
||
export default Component.extend({ | ||
tagName: 'label', | ||
classNames: ['toggle'], | ||
classNameBindings: ['isDisabled:is-disabled', 'isActive:is-active'], | ||
|
||
'data-test-label': true, | ||
|
||
isActive: false, | ||
isDisabled: false, | ||
onToggle() {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.