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';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class Deployment extends Model {
|
|
|
|
@shortUUIDProperty('id') shortId;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@belongsTo('job', { inverse: 'deployments' }) job;
|
|
|
|
@belongsTo('job', { inverse: 'latestDeployment' }) jobForLatest;
|
|
|
|
@attr('number') versionNumber;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// If any task group is not promoted yet requires promotion and the deployment
|
|
|
|
// is still running, the deployment needs promotion.
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('taskGroupSummaries.@each.promoted')
|
|
|
|
get requiresPromotion() {
|
|
|
|
return (
|
|
|
|
this.status === 'running' &&
|
|
|
|
this.taskGroupSummaries
|
|
|
|
.toArray()
|
|
|
|
.some(summary => summary.get('requiresPromotion') && !summary.get('promoted'))
|
|
|
|
);
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@attr('string') status;
|
|
|
|
@attr('string') statusDescription;
|
2018-07-28 00:40:09 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@equal('status', 'running') isRunning;
|
2018-07-28 00:40:09 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragmentArray('task-group-deployment-summary') taskGroupSummaries;
|
|
|
|
@hasMany('allocations') allocations;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('versionNumber', 'job.versions.content.@each.number')
|
|
|
|
get version() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return (this.get('job.versions') || []).findBy('number', this.versionNumber);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-12-12 00:19:49 +00:00
|
|
|
// Dependent keys can only go one level past an @each so an alias is needed
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('version.submitTime') versionSubmitTime;
|
2017-12-12 00:19:49 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@sumAggregation('taskGroupSummaries', 'placedCanaries') placedCanaries;
|
|
|
|
@sumAggregation('taskGroupSummaries', 'desiredCanaries') desiredCanaries;
|
|
|
|
@sumAggregation('taskGroupSummaries', 'desiredTotal') desiredTotal;
|
|
|
|
@sumAggregation('taskGroupSummaries', 'placedAllocs') placedAllocs;
|
|
|
|
@sumAggregation('taskGroupSummaries', 'healthyAllocs') healthyAllocs;
|
|
|
|
@sumAggregation('taskGroupSummaries', 'unhealthyAllocs') unhealthyAllocs;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('status')
|
|
|
|
get statusClass() {
|
2017-09-19 14:47:10 +00:00
|
|
|
const classMap = {
|
|
|
|
running: 'is-running',
|
|
|
|
successful: 'is-primary',
|
|
|
|
paused: 'is-light',
|
|
|
|
failed: 'is-error',
|
|
|
|
cancelled: 'is-cancelled',
|
|
|
|
};
|
|
|
|
|
2019-03-26 07:46:44 +00:00
|
|
|
return classMap[this.status] || 'is-dark';
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-08-24 22:33:04 +00:00
|
|
|
|
|
|
|
promote() {
|
2019-03-26 07:46:44 +00:00
|
|
|
assert('A deployment needs to requirePromotion to be promoted', this.requiresPromotion);
|
2018-08-24 22:33:04 +00:00
|
|
|
return this.store.adapterFor('deployment').promote(this);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|