github.com/hernad/nomad@v1.6.112/ui/app/components/job-status/update-params.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  // @ts-check
     7  import Component from '@glimmer/component';
     8  import { action } from '@ember/object';
     9  import { tracked } from '@glimmer/tracking';
    10  import { inject as service } from '@ember/service';
    11  import formatDuration from 'nomad-ui/utils/format-duration';
    12  
    13  /**
    14   * @typedef {Object} DefinitionUpdateStrategy
    15   * @property {boolean} AutoPromote
    16   * @property {boolean} AutoRevert
    17   * @property {number} Canary
    18   * @property {number} MaxParallel
    19   * @property {string} HealthCheck
    20   * @property {number} MinHealthyTime
    21   * @property {number} HealthyDeadline
    22   * @property {number} ProgressDeadline
    23   * @property {number} Stagger
    24   */
    25  
    26  /**
    27   * @typedef {Object} DefinitionTaskGroup
    28   * @property {string} Name
    29   * @property {number} Count
    30   * @property {DefinitionUpdateStrategy} Update
    31   */
    32  
    33  /**
    34   * @typedef {Object} JobDefinition
    35   * @property {string} ID
    36   * @property {DefinitionUpdateStrategy} Update
    37   * @property {DefinitionTaskGroup[]} TaskGroups
    38   */
    39  
    40  const PARAMS_REQUIRING_CONVERSION = [
    41    'HealthyDeadline',
    42    'MinHealthyTime',
    43    'ProgressDeadline',
    44    'Stagger',
    45  ];
    46  
    47  export default class JobStatusUpdateParamsComponent extends Component {
    48    @service notifications;
    49  
    50    /**
    51     * @type {JobDefinition}
    52     */
    53    @tracked rawDefinition = null;
    54  
    55    get updateParamGroups() {
    56      if (!this.rawDefinition) {
    57        return null;
    58      }
    59      return this.rawDefinition.TaskGroups.map((tg) => ({
    60        name: tg.Name,
    61        update: Object.keys(tg.Update || {}).reduce((newUpdateObj, key) => {
    62          newUpdateObj[key] = PARAMS_REQUIRING_CONVERSION.includes(key)
    63            ? formatDuration(tg.Update[key])
    64            : tg.Update[key];
    65          return newUpdateObj;
    66        }, {}),
    67      }));
    68    }
    69  
    70    @action onError({ Error }) {
    71      const error = Error.errors[0].title || 'Error fetching job parameters';
    72      this.notifications.add({
    73        title: 'Could not fetch job definition',
    74        message: error,
    75        color: 'critical',
    76      });
    77    }
    78  
    79    @action async fetchJobDefinition() {
    80      this.rawDefinition = await this.args.job.fetchRawDefinition();
    81    }
    82  }