Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: task lifecycle restart all tasks #14223

Merged
merged 5 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/14223.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Add button to restart all tasks in an allocation.
```
6 changes: 6 additions & 0 deletions ui/app/adapters/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
return this.token
.authorizedRequest(
Expand Down
4 changes: 2 additions & 2 deletions ui/app/components/lifecycle-chart-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default class LifecycleChartRow extends Component {
return undefined;
}

@computed('taskState.finishedAt')
@computed('taskState.state')
get finishedClass() {
if (this.taskState && this.taskState.finishedAt) {
if (this.taskState && this.taskState.state === 'dead') {
return 'is-finished';
}

Expand Down
13 changes: 13 additions & 0 deletions ui/app/controllers/allocations/allocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ export default class IndexController extends Controller.extend(Sortable) {
})
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
gotoTask(allocation, task) {
this.transitionToRoute('allocations.allocation.task', task);
Expand Down
4 changes: 4 additions & 0 deletions ui/app/models/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export default class Allocation extends Model {
return this.store.adapterFor('allocation').restart(this, taskName);
}

restartAll() {
return this.store.adapterFor('allocation').restartAll(this);
}

ls(path) {
return this.store.adapterFor('allocation').ls(this, path);
}
Expand Down
18 changes: 16 additions & 2 deletions ui/app/templates/allocations/allocation/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,28 @@
@idleText="Restart Alloc"
@cancelText="Cancel Restart"
@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}}
@disabled={{or
this.stopAllocation.isRunning
this.restartAllocation.isRunning
}}
@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}}
</div>
</h1>
Expand Down Expand Up @@ -184,7 +198,7 @@
</t.head>
<t.body as |row|>
<TaskRow
{{keyboard-shortcut
{{keyboard-shortcut
enumerated=true
action=(action "taskClick" row.model.allocation row.model)
}}
Expand Down
15 changes: 15 additions & 0 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ module('Acceptance | allocation detail', function (hooks) {
});

test('allocation can be restarted', async function (assert) {
await Allocation.restartAll.idle();
await Allocation.restart.idle();
await Allocation.restart.confirm();

Expand All @@ -388,6 +389,18 @@ module('Acceptance | allocation detail', function (hooks) {
`/v1/client/allocation/${allocation.id}/restart`,
'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) {
Expand All @@ -398,6 +411,7 @@ module('Acceptance | allocation detail', function (hooks) {
run.later(() => {
assert.ok(Allocation.stop.isRunning, 'Stop is loading');
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);
}, 500);

Expand Down Expand Up @@ -478,6 +492,7 @@ module('Acceptance | allocation detail (not running)', function (hooks) {
assert.notOk(Allocation.execButton.isPresent);
assert.notOk(Allocation.stop.isPresent);
assert.notOk(Allocation.restart.isPresent);
assert.notOk(Allocation.restartAll.isPresent);
});
});

Expand Down
1 change: 1 addition & 0 deletions ui/tests/integration/components/lifecycle-chart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ module('Integration | Component | lifecycle-chart', function (hooks) {
);

this.set('taskStates.4.finishedAt', new Date());
this.set('taskStates.4.state', 'dead');
await settled();

assert.ok(Chart.tasks[5].isFinished);
Expand Down
1 change: 1 addition & 0 deletions ui/tests/pages/allocations/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default create({

stop: twoStepButton('[data-test-stop]'),
restart: twoStepButton('[data-test-restart]'),
restartAll: twoStepButton('[data-test-restart-all]'),

execButton: {
scope: '[data-test-exec-button]',
Expand Down