From 78b9d32eb46698ccf0ba8889dd07cd9337cdb11a Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 24 Aug 2018 15:33:04 -0700 Subject: [PATCH 1/3] Support the promote deployment api action --- ui/app/adapters/deployment.js | 29 +++++++++++++++++++++++++++++ ui/app/models/deployment.js | 6 ++++++ 2 files changed, 35 insertions(+) create mode 100644 ui/app/adapters/deployment.js diff --git a/ui/app/adapters/deployment.js b/ui/app/adapters/deployment.js new file mode 100644 index 00000000000..6dbc20dbd38 --- /dev/null +++ b/ui/app/adapters/deployment.js @@ -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; +} diff --git a/ui/app/models/deployment.js b/ui/app/models/deployment.js index 5d86e9296e7..e3fefb94fb9 100644 --- a/ui/app/models/deployment.js +++ b/ui/app/models/deployment.js @@ -1,5 +1,6 @@ import { alias, equal } from '@ember/object/computed'; import { computed } from '@ember/object'; +import { assert } from '@ember/debug'; import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import { belongsTo, hasMany } from 'ember-data/relationships'; @@ -58,4 +59,9 @@ export default Model.extend({ return classMap[this.get('status')] || 'is-dark'; }), + + promote() { + assert('A deployment needs to requirePromotion to be promoted', this.get('requiresPromotion')); + return this.store.adapterFor('deployment').promote(this); + }, }); From c510060c128c8511f787f37ac85792e9e03cc399 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 24 Aug 2018 15:34:07 -0700 Subject: [PATCH 2/3] Change the latest deployment component to include a Promote Canary button Before it would say the deployment required promotion, now it has a button that triggers the promotion. --- .../job-page/parts/latest-deployment.js | 19 +++++++++++++++++++ .../job-page/parts/latest-deployment.hbs | 6 +++++- .../templates/components/job-page/service.hbs | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ui/app/components/job-page/parts/latest-deployment.js b/ui/app/components/job-page/parts/latest-deployment.js index 72ea12f8ec8..b68978520d1 100644 --- a/ui/app/components/job-page/parts/latest-deployment.js +++ b/ui/app/components/job-page/parts/latest-deployment.js @@ -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, + }); + } + }), }); diff --git a/ui/app/templates/components/job-page/parts/latest-deployment.hbs b/ui/app/templates/components/job-page/parts/latest-deployment.hbs index b67f0bd0b84..04bb69caa34 100644 --- a/ui/app/templates/components/job-page/parts/latest-deployment.hbs +++ b/ui/app/templates/components/job-page/parts/latest-deployment.hbs @@ -13,7 +13,11 @@ {{job.latestDeployment.status}} {{#if job.latestDeployment.requiresPromotion}} - Deployment is running but requires promotion + {{/if}} diff --git a/ui/app/templates/components/job-page/service.hbs b/ui/app/templates/components/job-page/service.hbs index 6a921beb8bb..cbef54c1f24 100644 --- a/ui/app/templates/components/job-page/service.hbs +++ b/ui/app/templates/components/job-page/service.hbs @@ -17,7 +17,7 @@ {{job-page/parts/placement-failures job=job}} - {{job-page/parts/latest-deployment job=job}} + {{job-page/parts/latest-deployment job=job handleError=(action "handleError")}} {{job-page/parts/task-groups job=job From c96c99aa37edc585e22daa83deaf927c8141ef8b Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 24 Aug 2018 16:32:08 -0700 Subject: [PATCH 3/3] Test coverage for the promote canary feature --- .../job-page/parts/latest-deployment.hbs | 1 + ui/mirage/config.js | 3 + .../deployment-task-group-summary.js | 2 + ui/mirage/factories/deployment.js | 2 + ui/tests/integration/job-page/service-test.js | 77 +++++++++++++++++++ 5 files changed, 85 insertions(+) diff --git a/ui/app/templates/components/job-page/parts/latest-deployment.hbs b/ui/app/templates/components/job-page/parts/latest-deployment.hbs index 04bb69caa34..a2a3aef3e6e 100644 --- a/ui/app/templates/components/job-page/parts/latest-deployment.hbs +++ b/ui/app/templates/components/job-page/parts/latest-deployment.hbs @@ -14,6 +14,7 @@ {{#if job.latestDeployment.requiresPromotion}}