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

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { computed } from '@ember/object';
     7  import Fragment from 'ember-data-model-fragments/fragment';
     8  import { attr } from '@ember-data/model';
     9  import {
    10    fragmentOwner,
    11    fragmentArray,
    12    fragment,
    13  } from 'ember-data-model-fragments/attributes';
    14  import sumAggregation from '../utils/properties/sum-aggregation';
    15  import classic from 'ember-classic-decorator';
    16  
    17  const maybe = (arr) => arr || [];
    18  
    19  @classic
    20  export default class TaskGroup extends Fragment {
    21    @fragmentOwner() job;
    22  
    23    @attr('string') name;
    24    @attr('number') count;
    25  
    26    @computed('job.{variables,parent,plainId}', 'name')
    27    get pathLinkedVariable() {
    28      if (this.job.parent.get('id')) {
    29        return this.job.variables?.findBy(
    30          'path',
    31          `nomad/jobs/${JSON.parse(this.job.parent.get('id'))[0]}/${this.name}`
    32        );
    33      } else {
    34        return this.job.variables?.findBy(
    35          'path',
    36          `nomad/jobs/${this.job.plainId}/${this.name}`
    37        );
    38      }
    39    }
    40  
    41    @fragmentArray('task') tasks;
    42  
    43    @fragmentArray('service-fragment') services;
    44  
    45    @fragmentArray('volume-definition') volumes;
    46  
    47    @fragment('group-scaling') scaling;
    48  
    49    @attr() meta;
    50  
    51    @computed('job.meta.raw', 'meta')
    52    get mergedMeta() {
    53      return {
    54        ...this.job.get('meta.raw'),
    55        ...this.meta,
    56      };
    57    }
    58  
    59    @computed('tasks.@each.driver')
    60    get drivers() {
    61      return this.tasks.mapBy('driver').uniq();
    62    }
    63  
    64    @computed('job.allocations.{@each.taskGroup,isFulfilled}', 'name')
    65    get allocations() {
    66      return maybe(this.get('job.allocations')).filterBy(
    67        'taskGroupName',
    68        this.name
    69      );
    70    }
    71  
    72    @sumAggregation('tasks', 'reservedCPU') reservedCPU;
    73    @sumAggregation('tasks', 'reservedMemory') reservedMemory;
    74    @sumAggregation('tasks', 'reservedDisk') reservedDisk;
    75  
    76    @computed('tasks.@each.{reservedMemory,reservedMemoryMax}')
    77    get reservedMemoryMax() {
    78      return this.get('tasks')
    79        .map((t) => t.get('reservedMemoryMax') || t.get('reservedMemory'))
    80        .reduce((sum, count) => sum + count, 0);
    81    }
    82  
    83    @attr('number') reservedEphemeralDisk;
    84  
    85    @computed('job.latestFailureEvaluation.failedTGAllocs.[]', 'name')
    86    get placementFailures() {
    87      const placementFailures = this.get(
    88        'job.latestFailureEvaluation.failedTGAllocs'
    89      );
    90      return placementFailures && placementFailures.findBy('name', this.name);
    91    }
    92  
    93    @computed('summary.{queuedAllocs,startingAllocs}')
    94    get queuedOrStartingAllocs() {
    95      return (
    96        this.get('summary.queuedAllocs') + this.get('summary.startingAllocs')
    97      );
    98    }
    99  
   100    @computed('job.taskGroupSummaries.[]', 'name')
   101    get summary() {
   102      return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name);
   103    }
   104  
   105    @computed('job.scaleState.taskGroupScales.[]', 'name')
   106    get scaleState() {
   107      return maybe(this.get('job.scaleState.taskGroupScales')).findBy(
   108        'name',
   109        this.name
   110      );
   111    }
   112  
   113    scale(count, message) {
   114      return this.job.scale(this.name, count, message);
   115    }
   116  }