ui: task lifecycle restart all tasks (#14223)

Now that tasks that have finished running can be restarted, the UI needs
to use the actual task state to determine which CSS class to use when
rendering the task lifecycle chart element.
This commit is contained in:
Luiz Aoqui 2022-08-24 18:43:44 -04:00 committed by GitHub
parent e012d9411e
commit 31ab7964bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 4 deletions

3
.changelog/14223.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
ui: Add button to restart all tasks in an allocation.
```

View File

@ -14,6 +14,12 @@ export default class AllocationAdapter extends Watchable {
}); });
} }
restartAll(allocation) {
const prefix = `${this.host || '/'}${this.urlPrefix()}`;
const url = `${prefix}/client/allocation/${allocation.id}/restart`;
return this.ajax(url, 'PUT', { data: { AllTasks: true } });
}
ls(model, path) { ls(model, path) {
return this.token return this.token
.authorizedRequest( .authorizedRequest(

View File

@ -15,9 +15,9 @@ export default class LifecycleChartRow extends Component {
return undefined; return undefined;
} }
@computed('taskState.finishedAt') @computed('taskState.state')
get finishedClass() { get finishedClass() {
if (this.taskState && this.taskState.finishedAt) { if (this.taskState && this.taskState.state === 'dead') {
return 'is-finished'; return 'is-finished';
} }

View File

@ -109,6 +109,19 @@ export default class IndexController extends Controller.extend(Sortable) {
}) })
restartAllocation; restartAllocation;
@task(function* () {
try {
yield this.model.restartAll();
} catch (err) {
this.set('error', {
title: 'Could Not Restart All Tasks',
description: messageForError(err, 'manage allocation lifecycle'),
});
console.error(err);
}
})
restartAll;
@action @action
gotoTask(allocation, task) { gotoTask(allocation, task) {
this.transitionToRoute('allocations.allocation.task', task); this.transitionToRoute('allocations.allocation.task', task);

View File

@ -157,6 +157,10 @@ export default class Allocation extends Model {
return this.store.adapterFor('allocation').restart(this, taskName); return this.store.adapterFor('allocation').restart(this, taskName);
} }
restartAll() {
return this.store.adapterFor('allocation').restartAll(this);
}
ls(path) { ls(path) {
return this.store.adapterFor('allocation').ls(this, path); return this.store.adapterFor('allocation').ls(this, path);
} }

View File

@ -61,7 +61,7 @@
@idleText="Restart Alloc" @idleText="Restart Alloc"
@cancelText="Cancel Restart" @cancelText="Cancel Restart"
@confirmText="Yes, Restart Alloc" @confirmText="Yes, Restart Alloc"
@confirmationMessage="Are you sure? This will restart the allocation in-place." @confirmationMessage="Are you sure? This will restart the tasks that are currently running in-place."
@awaitingConfirmation={{this.restartAllocation.isRunning}} @awaitingConfirmation={{this.restartAllocation.isRunning}}
@disabled={{or @disabled={{or
this.stopAllocation.isRunning this.stopAllocation.isRunning
@ -69,6 +69,20 @@
}} }}
@onConfirm={{perform this.restartAllocation}} @onConfirm={{perform this.restartAllocation}}
/> />
<TwoStepButton
data-test-restart-all
@alignRight={{true}}
@idleText="Restart All Tasks"
@cancelText="Cancel Restart"
@confirmText="Yes, Restart All Tasks"
@confirmationMessage="Are you sure? This will restart all tasks in-place."
@awaitingConfirmation={{this.restartAllocation.isRunning}}
@disabled={{or
this.stopAllocation.isRunning
this.restartAllocation.isRunning
}}
@onConfirm={{perform this.restartAll}}
/>
{{/if}} {{/if}}
</div> </div>
</h1> </h1>

View File

@ -380,6 +380,7 @@ module('Acceptance | allocation detail', function (hooks) {
}); });
test('allocation can be restarted', async function (assert) { test('allocation can be restarted', async function (assert) {
await Allocation.restartAll.idle();
await Allocation.restart.idle(); await Allocation.restart.idle();
await Allocation.restart.confirm(); await Allocation.restart.confirm();
@ -388,6 +389,18 @@ module('Acceptance | allocation detail', function (hooks) {
`/v1/client/allocation/${allocation.id}/restart`, `/v1/client/allocation/${allocation.id}/restart`,
'Restart request is made for the allocation' 'Restart request is made for the allocation'
); );
await Allocation.restart.idle();
await Allocation.restartAll.idle();
await Allocation.restartAll.confirm();
assert.ok(
server.pretender.handledRequests.filterBy(
'requestBody',
JSON.stringify({ AllTasks: true })
),
'Restart all tasks request is made for the allocation'
);
}); });
test('while an allocation is being restarted, the stop button is disabled', async function (assert) { test('while an allocation is being restarted, the stop button is disabled', async function (assert) {
@ -398,6 +411,7 @@ module('Acceptance | allocation detail', function (hooks) {
run.later(() => { run.later(() => {
assert.ok(Allocation.stop.isRunning, 'Stop is loading'); assert.ok(Allocation.stop.isRunning, 'Stop is loading');
assert.ok(Allocation.restart.isDisabled, 'Restart is disabled'); assert.ok(Allocation.restart.isDisabled, 'Restart is disabled');
assert.ok(Allocation.restartAll.isDisabled, 'Restart All is disabled');
server.pretender.resolve(server.pretender.requestReferences[0].request); server.pretender.resolve(server.pretender.requestReferences[0].request);
}, 500); }, 500);
@ -478,6 +492,7 @@ module('Acceptance | allocation detail (not running)', function (hooks) {
assert.notOk(Allocation.execButton.isPresent); assert.notOk(Allocation.execButton.isPresent);
assert.notOk(Allocation.stop.isPresent); assert.notOk(Allocation.stop.isPresent);
assert.notOk(Allocation.restart.isPresent); assert.notOk(Allocation.restart.isPresent);
assert.notOk(Allocation.restartAll.isPresent);
}); });
}); });

View File

@ -146,6 +146,7 @@ module('Integration | Component | lifecycle-chart', function (hooks) {
); );
this.set('taskStates.4.finishedAt', new Date()); this.set('taskStates.4.finishedAt', new Date());
this.set('taskStates.4.state', 'dead');
await settled(); await settled();
assert.ok(Chart.tasks[5].isFinished); assert.ok(Chart.tasks[5].isFinished);

View File

@ -19,6 +19,7 @@ export default create({
stop: twoStepButton('[data-test-stop]'), stop: twoStepButton('[data-test-stop]'),
restart: twoStepButton('[data-test-restart]'), restart: twoStepButton('[data-test-restart]'),
restartAll: twoStepButton('[data-test-restart-all]'),
execButton: { execButton: {
scope: '[data-test-exec-button]', scope: '[data-test-exec-button]',