github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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 this.status === 'running' && 22 this.taskGroupSummaries 23 .toArray() 24 .some(summary => summary.get('requiresPromotion') && !summary.get('promoted')); 25 }), 26 27 status: attr('string'), 28 statusDescription: attr('string'), 29 30 isRunning: equal('status', 'running'), 31 32 taskGroupSummaries: fragmentArray('task-group-deployment-summary'), 33 allocations: hasMany('allocations'), 34 35 version: computed('versionNumber', 'job.versions.content.@each.number', function() { 36 return (this.get('job.versions') || []).findBy('number', this.versionNumber); 37 }), 38 39 // Dependent keys can only go one level past an @each so an alias is needed 40 versionSubmitTime: alias('version.submitTime'), 41 42 placedCanaries: sumAggregation('taskGroupSummaries', 'placedCanaries'), 43 desiredCanaries: sumAggregation('taskGroupSummaries', 'desiredCanaries'), 44 desiredTotal: sumAggregation('taskGroupSummaries', 'desiredTotal'), 45 placedAllocs: sumAggregation('taskGroupSummaries', 'placedAllocs'), 46 healthyAllocs: sumAggregation('taskGroupSummaries', 'healthyAllocs'), 47 unhealthyAllocs: sumAggregation('taskGroupSummaries', 'unhealthyAllocs'), 48 49 statusClass: computed('status', function() { 50 const classMap = { 51 running: 'is-running', 52 successful: 'is-primary', 53 paused: 'is-light', 54 failed: 'is-error', 55 cancelled: 'is-cancelled', 56 }; 57 58 return classMap[this.status] || 'is-dark'; 59 }), 60 61 promote() { 62 assert('A deployment needs to requirePromotion to be promoted', this.requiresPromotion); 63 return this.store.adapterFor('deployment').promote(this); 64 }, 65 });