From a4d951a75758c80d3103798c5bd15173e763107e Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 24 Aug 2018 13:17:45 -0700 Subject: [PATCH] Add Start Job action on the job overview page for when a job is dead --- ui/app/components/job-page/parts/title.js | 31 +++++++++++++++++++ .../components/job-page/parts/title.hbs | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/ui/app/components/job-page/parts/title.js b/ui/app/components/job-page/parts/title.js index fb8e3232c..a7f079705 100644 --- a/ui/app/components/job-page/parts/title.js +++ b/ui/app/components/job-page/parts/title.js @@ -1,4 +1,5 @@ import Component from '@ember/component'; +import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; export default Component.extend({ tagName: '', @@ -19,5 +20,35 @@ export default Component.extend({ }); }); }, + + startJob() { + const job = this.get('job'); + job + .fetchRawDefinition() + .then(definition => { + // A stopped job will have this Stop = true metadata + // If Stop is true when submitted to the cluster, the job + // won't transition from the Dead to Running state. + delete definition.Stop; + job.set('_newDefinition', JSON.stringify(definition)); + }) + .then(() => { + return job.parse(); + }) + .then(() => { + return job.update(); + }) + .catch(err => { + let message = messageFromAdapterError(err); + if (!message || message === 'Forbidden') { + message = 'Your ACL token does not grant permission to stop jobs.'; + } + + this.get('handleError')({ + title: 'Could Not Start Job', + description: message, + }); + }); + }, }, }); diff --git a/ui/app/templates/components/job-page/parts/title.hbs b/ui/app/templates/components/job-page/parts/title.hbs index 445640d76..6bbd9f9b4 100644 --- a/ui/app/templates/components/job-page/parts/title.hbs +++ b/ui/app/templates/components/job-page/parts/title.hbs @@ -10,5 +10,13 @@ confirmText="Yes, Stop" confirmationMessage="Are you sure you want to stop this job?" onConfirm=(action "stopJob")}} + {{else}} + {{two-step-button + data-test-start + idleText="Start" + cancelText="Cancel" + confirmText="Yes, Start" + confirmationMessage="Are you sure you want to start this job?" + onConfirm=(action "startJob")}} {{/if}}