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: Add specificity to exec allocation URL generation #8463

Merged
merged 1 commit into from
Jul 20, 2020
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
39 changes: 31 additions & 8 deletions ui/app/utils/generate-exec-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,39 @@ export default function generateExecUrl(router, { job, taskGroup, task, allocati
const queryParams = router.currentRoute.queryParams;

if (task) {
return router.urlFor('exec.task-group.task', get(job, 'plainId'), get(taskGroup, 'name'), get(task, 'name'), {
queryParams: {
allocation: get(allocation, 'shortId'),
...queryParams,
},
});
return router.urlFor(
'exec.task-group.task',
get(job, 'plainId'),
get(taskGroup, 'name'),
get(task, 'name'),
{
queryParams: {
allocation: get(allocation, 'shortId'),
...queryParams,
},
}
);
} else if (taskGroup) {
return router.urlFor('exec.task-group', get(job, 'plainId'), get(taskGroup, 'name'), { queryParams });
return router.urlFor('exec.task-group', get(job, 'plainId'), get(taskGroup, 'name'), {
queryParams,
});
} else if (allocation) {
return router.urlFor('exec', get(job, 'plainId'), { queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } });
if (get(allocation, 'taskGroup.tasks.length') === 1) {
return router.urlFor(
'exec.task-group.task',
get(job, 'plainId'),
get(allocation, 'taskGroup.name'),
get(allocation, 'taskGroup.tasks.firstObject.name'),
{ queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
);
} else {
return router.urlFor(
'exec.task-group',
get(job, 'plainId'),
get(allocation, 'taskGroup.name'),
{ queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
);
}
} else {
return router.urlFor('exec', get(job, 'plainId'), { queryParams });
}
Expand Down
46 changes: 40 additions & 6 deletions ui/tests/unit/utils/generate-exec-url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,49 @@ module('Unit | Utility | generate-exec-url', function(hooks) {
assert.ok(this.urlForSpy.calledWith('exec', 'job-name', emptyOptions));
});

test('it generates an exec job URL with an allocation', function(assert) {
generateExecUrl(this.router, { job: { plainId: 'job-name' }, allocation: { shortId: 'allocation-short-id' } });
test('it generates an exec job URL with an allocation and task group when there are multiple tasks', function(assert) {
generateExecUrl(this.router, {
job: { plainId: 'job-name' },
allocation: {
shortId: 'allocation-short-id',
taskGroup: { name: 'task-group-name', tasks: [0, 1, 2] },
},
});

assert.ok(
this.urlForSpy.calledWith('exec', 'job-name', {
this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', {
queryParams: { allocation: 'allocation-short-id' },
})
);
});

test('it generates an exec job URL with an allocation, task group, and task when there is only one task', function(assert) {
generateExecUrl(this.router, {
job: { plainId: 'job-name' },
allocation: {
shortId: 'allocation-short-id',
taskGroup: { name: 'task-group-name', tasks: [{ name: 'task-name' }] },
},
});

assert.ok(
this.urlForSpy.calledWith(
'exec.task-group.task',
'job-name',
'task-group-name',
'task-name',
{
queryParams: { allocation: 'allocation-short-id' },
}
)
);
});

test('it generates an exec task group URL', function(assert) {
generateExecUrl(this.router, { job: { plainId: 'job-name' }, taskGroup: { name: 'task-group-name' } });
generateExecUrl(this.router, {
job: { plainId: 'job-name' },
taskGroup: { name: 'task-group-name' },
});

assert.ok(
this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', emptyOptions)
Expand Down Expand Up @@ -59,10 +90,13 @@ module('Unit | Utility | generate-exec-url', function(hooks) {
region: 'a-region',
};

generateExecUrl(this.router, { job: { plainId: 'job-name' }, allocation: { shortId: 'id' } });
generateExecUrl(this.router, {
job: { plainId: 'job-name' },
allocation: { shortId: 'id', taskGroup: { name: 'task-group-name', tasks: [0, 1] } },
});

assert.ok(
this.urlForSpy.calledWith('exec', 'job-name', {
this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', {
queryParams: { allocation: 'id', namespace: 'a-namespace', region: 'a-region' },
})
);
Expand Down