open-nomad/ui/app/models/job-summary.js
2023-04-10 15:36:59 +00:00

49 lines
1.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { collect, sum } from '@ember/object/computed';
import Model from '@ember-data/model';
import { attr, belongsTo } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import sumAggregation from '../utils/properties/sum-aggregation';
import classic from 'ember-classic-decorator';
@classic
export default class JobSummary extends Model {
@belongsTo('job') job;
@fragmentArray('task-group-summary') taskGroupSummaries;
// Aggregate allocation counts across all summaries
@sumAggregation('taskGroupSummaries', 'queuedAllocs') queuedAllocs;
@sumAggregation('taskGroupSummaries', 'startingAllocs') startingAllocs;
@sumAggregation('taskGroupSummaries', 'runningAllocs') runningAllocs;
@sumAggregation('taskGroupSummaries', 'completeAllocs') completeAllocs;
@sumAggregation('taskGroupSummaries', 'failedAllocs') failedAllocs;
@sumAggregation('taskGroupSummaries', 'unknownAllocs') unknownAllocs;
@sumAggregation('taskGroupSummaries', 'lostAllocs') lostAllocs;
@collect(
'queuedAllocs',
'startingAllocs',
'runningAllocs',
'completeAllocs',
'failedAllocs',
'lostAllocs',
'unknownAllocs'
)
allocsList;
@sum('allocsList') totalAllocs;
@attr('number') pendingChildren;
@attr('number') runningChildren;
@attr('number') deadChildren;
@collect('pendingChildren', 'runningChildren', 'deadChildren') childrenList;
@sum('childrenList') totalChildren;
}