Add Start Job action on the job overview page for when a job is dead

This commit is contained in:
Michael Lange 2018-08-24 13:17:45 -07:00
parent e9454e1b05
commit a4d951a757
2 changed files with 39 additions and 0 deletions

View File

@ -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,
});
});
},
},
});

View File

@ -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}}
</h1>