github.com/hernad/nomad@v1.6.112/ui/app/models/deployment.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { alias, equal } from '@ember/object/computed';
     7  import { computed } from '@ember/object';
     8  import { assert } from '@ember/debug';
     9  import Model from '@ember-data/model';
    10  import { attr, belongsTo, hasMany } from '@ember-data/model';
    11  import { fragmentArray } from 'ember-data-model-fragments/attributes';
    12  import shortUUIDProperty from '../utils/properties/short-uuid';
    13  import sumAggregation from '../utils/properties/sum-aggregation';
    14  import classic from 'ember-classic-decorator';
    15  
    16  @classic
    17  export default class Deployment extends Model {
    18    @shortUUIDProperty('id') shortId;
    19  
    20    @belongsTo('job', { inverse: 'deployments' }) job;
    21    @belongsTo('job', { inverse: 'latestDeployment' }) jobForLatest;
    22    @attr('number') versionNumber;
    23  
    24    // If any task group is not promoted yet requires promotion and the deployment
    25    // is still running, the deployment needs promotion.
    26    @computed('status', 'taskGroupSummaries.@each.{promoted,requiresPromotion}')
    27    get requiresPromotion() {
    28      return (
    29        this.status === 'running' &&
    30        this.taskGroupSummaries
    31          .toArray()
    32          .some(
    33            (summary) =>
    34              summary.get('requiresPromotion') && !summary.get('promoted')
    35          )
    36      );
    37    }
    38  
    39    @computed('taskGroupSummaries.@each.autoPromote')
    40    get isAutoPromoted() {
    41      return this.taskGroupSummaries
    42        .toArray()
    43        .every((summary) => summary.get('autoPromote'));
    44    }
    45  
    46    @attr('string') status;
    47    @attr('string') statusDescription;
    48  
    49    @equal('status', 'running') isRunning;
    50  
    51    @fragmentArray('task-group-deployment-summary') taskGroupSummaries;
    52    @hasMany('allocations') allocations;
    53  
    54    @computed('versionNumber', 'job.versions.content.@each.number')
    55    get version() {
    56      return (this.get('job.versions') || []).findBy(
    57        'number',
    58        this.versionNumber
    59      );
    60    }
    61  
    62    // Dependent keys can only go one level past an @each so an alias is needed
    63    @alias('version.submitTime') versionSubmitTime;
    64  
    65    @sumAggregation('taskGroupSummaries', 'placedCanaries') placedCanaries;
    66    @sumAggregation('taskGroupSummaries', 'desiredCanaries') desiredCanaries;
    67    @sumAggregation('taskGroupSummaries', 'desiredTotal') desiredTotal;
    68    @sumAggregation('taskGroupSummaries', 'placedAllocs') placedAllocs;
    69    @sumAggregation('taskGroupSummaries', 'healthyAllocs') healthyAllocs;
    70    @sumAggregation('taskGroupSummaries', 'unhealthyAllocs') unhealthyAllocs;
    71  
    72    @computed('status')
    73    get statusClass() {
    74      const classMap = {
    75        running: 'is-running',
    76        successful: 'is-primary',
    77        paused: 'is-light',
    78        failed: 'is-error',
    79        cancelled: 'is-cancelled',
    80      };
    81  
    82      return classMap[this.status] || 'is-dark';
    83    }
    84  
    85    promote() {
    86      assert(
    87        'A deployment needs to requirePromotion to be promoted',
    88        this.requiresPromotion
    89      );
    90      return this.store.adapterFor('deployment').promote(this);
    91    }
    92  
    93    fail() {
    94      assert('A deployment must be running to be failed', this.isRunning);
    95      return this.store.adapterFor('deployment').fail(this);
    96    }
    97  }