2018-07-28 00:40:09 +00:00
|
|
|
import { alias, equal } from '@ember/object/computed';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2018-08-24 22:33:04 +00:00
|
|
|
import { assert } from '@ember/debug';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Model from 'ember-data/model';
|
|
|
|
import attr from 'ember-data/attr';
|
|
|
|
import { belongsTo, hasMany } from 'ember-data/relationships';
|
|
|
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
|
|
import shortUUIDProperty from '../utils/properties/short-uuid';
|
|
|
|
import sumAggregation from '../utils/properties/sum-aggregation';
|
|
|
|
|
|
|
|
export default Model.extend({
|
|
|
|
shortId: shortUUIDProperty('id'),
|
|
|
|
|
2018-07-28 00:40:09 +00:00
|
|
|
job: belongsTo('job', { inverse: 'deployments' }),
|
2018-07-28 02:28:05 +00:00
|
|
|
jobForLatest: belongsTo('job', { inverse: 'latestDeployment' }),
|
2017-09-19 14:47:10 +00:00
|
|
|
versionNumber: attr('number'),
|
|
|
|
|
|
|
|
// If any task group is not promoted yet requires promotion and the deployment
|
|
|
|
// is still running, the deployment needs promotion.
|
|
|
|
requiresPromotion: computed('taskGroupSummaries.@each.promoted', function() {
|
|
|
|
return (
|
|
|
|
this.get('status') === 'running' &&
|
|
|
|
this.get('taskGroupSummaries')
|
|
|
|
.toArray()
|
|
|
|
.some(summary => summary.get('requiresPromotion') && !summary.get('promoted'))
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
|
|
|
status: attr('string'),
|
|
|
|
statusDescription: attr('string'),
|
2018-07-28 00:40:09 +00:00
|
|
|
|
|
|
|
isRunning: equal('status', 'running'),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroupSummaries: fragmentArray('task-group-deployment-summary'),
|
|
|
|
allocations: hasMany('allocations'),
|
|
|
|
|
|
|
|
version: computed('versionNumber', 'job.versions.content.@each.number', function() {
|
|
|
|
return (this.get('job.versions') || []).findBy('number', this.get('versionNumber'));
|
|
|
|
}),
|
|
|
|
|
2017-12-12 00:19:49 +00:00
|
|
|
// Dependent keys can only go one level past an @each so an alias is needed
|
2017-12-15 21:39:18 +00:00
|
|
|
versionSubmitTime: alias('version.submitTime'),
|
2017-12-12 00:19:49 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
placedCanaries: sumAggregation('taskGroupSummaries', 'placedCanaries'),
|
|
|
|
desiredCanaries: sumAggregation('taskGroupSummaries', 'desiredCanaries'),
|
|
|
|
desiredTotal: sumAggregation('taskGroupSummaries', 'desiredTotal'),
|
|
|
|
placedAllocs: sumAggregation('taskGroupSummaries', 'placedAllocs'),
|
|
|
|
healthyAllocs: sumAggregation('taskGroupSummaries', 'healthyAllocs'),
|
|
|
|
unhealthyAllocs: sumAggregation('taskGroupSummaries', 'unhealthyAllocs'),
|
|
|
|
|
|
|
|
statusClass: computed('status', function() {
|
|
|
|
const classMap = {
|
|
|
|
running: 'is-running',
|
|
|
|
successful: 'is-primary',
|
|
|
|
paused: 'is-light',
|
|
|
|
failed: 'is-error',
|
|
|
|
cancelled: 'is-cancelled',
|
|
|
|
};
|
|
|
|
|
|
|
|
return classMap[this.get('status')] || 'is-dark';
|
|
|
|
}),
|
2018-08-24 22:33:04 +00:00
|
|
|
|
|
|
|
promote() {
|
|
|
|
assert('A deployment needs to requirePromotion to be promoted', this.get('requiresPromotion'));
|
|
|
|
return this.store.adapterFor('deployment').promote(this);
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|