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