github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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 { fragmentOwner, fragmentArray, fragment } from 'ember-data-model-fragments/attributes'; 5 import sumAggregation from '../utils/properties/sum-aggregation'; 6 import classic from 'ember-classic-decorator'; 7 8 const maybe = arr => arr || []; 9 10 @classic 11 export default class TaskGroup extends Fragment { 12 @fragmentOwner() job; 13 14 @attr('string') name; 15 @attr('number') count; 16 17 @fragmentArray('task') tasks; 18 19 @fragmentArray('service') services; 20 21 @fragmentArray('volume-definition') volumes; 22 23 @fragment('group-scaling') scaling; 24 25 @computed('tasks.@each.driver') 26 get drivers() { 27 return this.tasks.mapBy('driver').uniq(); 28 } 29 30 @computed('job.allocations.@each.taskGroup', 'name') 31 get allocations() { 32 return maybe(this.get('job.allocations')).filterBy('taskGroupName', this.name); 33 } 34 35 @sumAggregation('tasks', 'reservedCPU') reservedCPU; 36 @sumAggregation('tasks', 'reservedMemory') reservedMemory; 37 @sumAggregation('tasks', 'reservedDisk') reservedDisk; 38 39 @attr('number') reservedEphemeralDisk; 40 41 @computed('job.latestFailureEvaluation.failedTGAllocs.[]', 'name') 42 get placementFailures() { 43 const placementFailures = this.get('job.latestFailureEvaluation.failedTGAllocs'); 44 return placementFailures && placementFailures.findBy('name', this.name); 45 } 46 47 @computed('summary.{queuedAllocs,startingAllocs}') 48 get queuedOrStartingAllocs() { 49 return this.get('summary.queuedAllocs') + this.get('summary.startingAllocs'); 50 } 51 52 @computed('job.taskGroupSummaries.[]', 'name') 53 get summary() { 54 return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name); 55 } 56 57 @computed('job.scaleState.taskGroupScales.[]', 'name') 58 get scaleState() { 59 return maybe(this.get('job.scaleState.taskGroupScales')).findBy('name', this.name); 60 } 61 62 scale(count, message) { 63 return this.job.scale(this.name, count, message); 64 } 65 }