github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/models/task-group.js (about)

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