2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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';
|
2021-02-17 21:01:44 +00:00
|
|
|
import Model from '@ember-data/model';
|
|
|
|
import { attr, belongsTo, hasMany } from '@ember-data/model';
|
2017-09-19 14:47:10 +00:00
|
|
|
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.
|
2023-06-19 16:06:18 +00:00
|
|
|
@computed('status', 'taskGroupSummaries.@each.{promoted,requiresPromotion}')
|
2020-06-10 13:49:16 +00:00
|
|
|
get requiresPromotion() {
|
|
|
|
return (
|
|
|
|
this.status === 'running' &&
|
|
|
|
this.taskGroupSummaries
|
|
|
|
.toArray()
|
2021-12-28 16:08:12 +00:00
|
|
|
.some(
|
|
|
|
(summary) =>
|
|
|
|
summary.get('requiresPromotion') && !summary.get('promoted')
|
|
|
|
)
|
2020-06-10 13:49:16 +00:00
|
|
|
);
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2023-06-19 16:06:18 +00:00
|
|
|
@computed('taskGroupSummaries.@each.autoPromote')
|
|
|
|
get isAutoPromoted() {
|
|
|
|
return this.taskGroupSummaries
|
|
|
|
.toArray()
|
|
|
|
.every((summary) => summary.get('autoPromote'));
|
|
|
|
}
|
|
|
|
|
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() {
|
2021-12-28 16:08:12 +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() {
|
2021-12-28 16:08:12 +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
|
|
|
}
|
2021-02-10 14:38:37 +00:00
|
|
|
|
|
|
|
fail() {
|
|
|
|
assert('A deployment must be running to be failed', this.isRunning);
|
|
|
|
return this.store.adapterFor('deployment').fail(this);
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|