Skip to content

Commit

Permalink
ui: add button to restart all tasks in the alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Aug 22, 2022
1 parent fa97d11 commit 8b3d338
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
13 changes: 9 additions & 4 deletions ui/app/adapters/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import classic from 'ember-classic-decorator';
export default class AllocationAdapter extends Watchable {
stop = adapterAction('/stop');

restart(allocation, taskName) {
restart(allocation, taskName, allTasks) {
const prefix = `${this.host || '/'}${this.urlPrefix()}`;
const url = `${prefix}/client/allocation/${allocation.id}/restart`;
return this.ajax(url, 'PUT', {
data: taskName && { TaskName: taskName },
});
let data = {};
if (taskName) {
data.TaskName = taskName;
}
if (allTasks) {
data.AllTasks = !!allTasks;
}
return this.ajax(url, 'PUT', { data });
}

ls(model, path) {
Expand Down
4 changes: 2 additions & 2 deletions ui/app/controllers/allocations/allocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export default class IndexController extends Controller.extend(Sortable) {
})
stopAllocation;

@task(function* () {
@task(function* (allTasks) {
try {
yield this.model.restart();
yield this.model.restart('', allTasks);
} catch (err) {
this.set('error', {
title: 'Could Not Restart Allocation',
Expand Down
6 changes: 4 additions & 2 deletions ui/app/models/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ export default class Allocation extends Model {
return this.store.adapterFor('allocation').stop(this);
}

restart(taskName) {
return this.store.adapterFor('allocation').restart(this, taskName);
restart(taskName, allTasks) {
return this.store
.adapterFor('allocation')
.restart(this, taskName, allTasks);
}

ls(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,13 +61,27 @@
@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}}
@onConfirm={{perform this.restartAllocation false}}
/>
<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.restartAllocation true}}
/>
{{/if}}
</div>
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 @@ -353,6 +353,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 @@ -361,6 +362,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 @@ -371,6 +384,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 @@ -451,6 +465,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/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

0 comments on commit 8b3d338

Please sign in to comment.