-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4600 from hashicorp/f-ui-job-writes
UI: Job Writes
- Loading branch information
Showing
64 changed files
with
1,818 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Watchable from './watchable'; | ||
|
||
export default Watchable.extend({ | ||
promote(deployment) { | ||
const id = deployment.get('id'); | ||
const url = urlForAction(this.urlForFindRecord(id, 'deployment'), '/promote'); | ||
return this.ajax(url, 'POST', { | ||
data: { | ||
DeploymentId: id, | ||
All: true, | ||
}, | ||
}); | ||
}, | ||
}); | ||
|
||
// The deployment action API endpoints all end with the ID | ||
// /deployment/:action/:deployment_id instead of /deployment/:deployment_id/:action | ||
function urlForAction(url, extension = '') { | ||
const [path, params] = url.split('?'); | ||
const pathParts = path.split('/'); | ||
const idPart = pathParts.pop(); | ||
let newUrl = `${pathParts.join('/')}${extension}/${idPart}`; | ||
|
||
if (params) { | ||
newUrl += `?${params}`; | ||
} | ||
|
||
return newUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import Component from '@ember/component'; | ||
import { assert } from '@ember/debug'; | ||
import { inject as service } from '@ember/service'; | ||
import { computed } from '@ember/object'; | ||
import { task } from 'ember-concurrency'; | ||
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; | ||
import localStorageProperty from 'nomad-ui/utils/properties/local-storage'; | ||
|
||
export default Component.extend({ | ||
store: service(), | ||
config: service(), | ||
|
||
'data-test-job-editor': true, | ||
|
||
job: null, | ||
onSubmit() {}, | ||
context: computed({ | ||
get() { | ||
return this.get('_context'); | ||
}, | ||
set(key, value) { | ||
const allowedValues = ['new', 'edit']; | ||
|
||
assert(`context must be one of: ${allowedValues.join(', ')}`, allowedValues.includes(value)); | ||
|
||
this.set('_context', value); | ||
return value; | ||
}, | ||
}), | ||
|
||
_context: null, | ||
parseError: null, | ||
planError: null, | ||
runError: null, | ||
|
||
planOutput: null, | ||
|
||
showPlanMessage: localStorageProperty('nomadMessageJobPlan', true), | ||
showEditorMessage: localStorageProperty('nomadMessageJobEditor', true), | ||
|
||
stage: computed('planOutput', function() { | ||
return this.get('planOutput') ? 'plan' : 'editor'; | ||
}), | ||
|
||
plan: task(function*() { | ||
this.reset(); | ||
|
||
try { | ||
yield this.get('job').parse(); | ||
} catch (err) { | ||
const error = messageFromAdapterError(err) || 'Could not parse input'; | ||
this.set('parseError', error); | ||
this.scrollToError(); | ||
return; | ||
} | ||
|
||
try { | ||
const plan = yield this.get('job').plan(); | ||
this.set('planOutput', plan); | ||
} catch (err) { | ||
const error = messageFromAdapterError(err) || 'Could not plan job'; | ||
this.set('planError', error); | ||
this.scrollToError(); | ||
} | ||
}).drop(), | ||
|
||
submit: task(function*() { | ||
try { | ||
if (this.get('context') === 'new') { | ||
yield this.get('job').run(); | ||
} else { | ||
yield this.get('job').update(); | ||
} | ||
|
||
const id = this.get('job.plainId'); | ||
const namespace = this.get('job.namespace.name') || 'default'; | ||
|
||
this.reset(); | ||
|
||
// Treat the job as ephemeral and only provide ID parts. | ||
this.get('onSubmit')(id, namespace); | ||
} catch (err) { | ||
const error = messageFromAdapterError(err) || 'Could not submit job'; | ||
this.set('runError', error); | ||
this.set('planOutput', null); | ||
this.scrollToError(); | ||
} | ||
}), | ||
|
||
reset() { | ||
this.set('planOutput', null); | ||
this.set('planError', null); | ||
this.set('parseError', null); | ||
this.set('runError', null); | ||
}, | ||
|
||
scrollToError() { | ||
if (!this.get('config.isTest')) { | ||
window.scrollTo(0, 0); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
import Component from '@ember/component'; | ||
import { task } from 'ember-concurrency'; | ||
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; | ||
|
||
export default Component.extend({ | ||
job: null, | ||
tagName: '', | ||
|
||
handleError() {}, | ||
|
||
isShowingDeploymentDetails: false, | ||
|
||
promote: task(function*() { | ||
try { | ||
yield this.get('job.latestDeployment.content').promote(); | ||
} catch (err) { | ||
let message = messageFromAdapterError(err); | ||
if (!message || message === 'Forbidden') { | ||
message = 'Your ACL token does not grant permission to promote deployments.'; | ||
} | ||
this.get('handleError')({ | ||
title: 'Could Not Promote Deployment', | ||
description: message, | ||
}); | ||
} | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Component from '@ember/component'; | ||
import { or } from '@ember/object/computed'; | ||
|
||
export default Component.extend({ | ||
// Either provide a taskGroup or a failedTGAlloc | ||
taskGroup: null, | ||
failedTGAlloc: null, | ||
|
||
placementFailures: or('taskGroup.placementFailures', 'failedTGAlloc'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.