github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/app/models/deployment.js (about) 1 import { alias, equal } from '@ember/object/computed'; 2 import { computed } from '@ember/object'; 3 import { assert } from '@ember/debug'; 4 import Model from 'ember-data/model'; 5 import attr from 'ember-data/attr'; 6 import { belongsTo, hasMany } from 'ember-data/relationships'; 7 import { fragmentArray } from 'ember-data-model-fragments/attributes'; 8 import shortUUIDProperty from '../utils/properties/short-uuid'; 9 import sumAggregation from '../utils/properties/sum-aggregation'; 10 11 export default Model.extend({ 12 shortId: shortUUIDProperty('id'), 13 14 job: belongsTo('job', { inverse: 'deployments' }), 15 jobForLatest: belongsTo('job', { inverse: 'latestDeployment' }), 16 versionNumber: attr('number'), 17 18 // If any task group is not promoted yet requires promotion and the deployment 19 // is still running, the deployment needs promotion. 20 requiresPromotion: computed('taskGroupSummaries.@each.promoted', function() { 21 return ( 22 this.get('status') === 'running' && 23 this.get('taskGroupSummaries') 24 .toArray() 25 .some(summary => summary.get('requiresPromotion') && !summary.get('promoted')) 26 ); 27 }), 28 29 status: attr('string'), 30 statusDescription: attr('string'), 31 32 isRunning: equal('status', 'running'), 33 34 taskGroupSummaries: fragmentArray('task-group-deployment-summary'), 35 allocations: hasMany('allocations'), 36 37 version: computed('versionNumber', 'job.versions.content.@each.number', function() { 38 return (this.get('job.versions') || []).findBy('number', this.get('versionNumber')); 39 }), 40 41 // Dependent keys can only go one level past an @each so an alias is needed 42 versionSubmitTime: alias('version.submitTime'), 43 44 placedCanaries: sumAggregation('taskGroupSummaries', 'placedCanaries'), 45 desiredCanaries: sumAggregation('taskGroupSummaries', 'desiredCanaries'), 46 desiredTotal: sumAggregation('taskGroupSummaries', 'desiredTotal'), 47 placedAllocs: sumAggregation('taskGroupSummaries', 'placedAllocs'), 48 healthyAllocs: sumAggregation('taskGroupSummaries', 'healthyAllocs'), 49 unhealthyAllocs: sumAggregation('taskGroupSummaries', 'unhealthyAllocs'), 50 51 statusClass: computed('status', function() { 52 const classMap = { 53 running: 'is-running', 54 successful: 'is-primary', 55 paused: 'is-light', 56 failed: 'is-error', 57 cancelled: 'is-cancelled', 58 }; 59 60 return classMap[this.get('status')] || 'is-dark'; 61 }), 62 63 promote() { 64 assert('A deployment needs to requirePromotion to be promoted', this.get('requiresPromotion')); 65 return this.store.adapterFor('deployment').promote(this); 66 }, 67 });