2018-01-23 21:24:13 +00:00
|
|
|
import { collect, sum, bool, equal, or } from '@ember/object/computed';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Model from 'ember-data/model';
|
|
|
|
import attr from 'ember-data/attr';
|
2017-10-10 16:36:15 +00:00
|
|
|
import { belongsTo, hasMany } from 'ember-data/relationships';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
|
|
import sumAggregation from '../utils/properties/sum-aggregation';
|
|
|
|
|
2018-01-25 17:29:47 +00:00
|
|
|
const JOB_TYPES = ['service', 'batch', 'system'];
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
export default Model.extend({
|
|
|
|
region: attr('string'),
|
|
|
|
name: attr('string'),
|
2017-10-23 17:22:58 +00:00
|
|
|
plainId: attr('string'),
|
2017-09-19 14:47:10 +00:00
|
|
|
type: attr('string'),
|
|
|
|
priority: attr('number'),
|
|
|
|
allAtOnce: attr('boolean'),
|
|
|
|
|
|
|
|
status: attr('string'),
|
|
|
|
statusDescription: attr('string'),
|
|
|
|
createIndex: attr('number'),
|
|
|
|
modifyIndex: attr('number'),
|
|
|
|
|
2018-01-23 21:24:13 +00:00
|
|
|
// True when the job is the parent periodic or parameterized jobs
|
|
|
|
// Instances of periodic or parameterized jobs are false for both properties
|
2017-09-19 14:47:10 +00:00
|
|
|
periodic: attr('boolean'),
|
|
|
|
parameterized: attr('boolean'),
|
|
|
|
|
2018-01-25 17:29:47 +00:00
|
|
|
periodicDetails: attr(),
|
|
|
|
parameterizedDetails: attr(),
|
|
|
|
|
2018-01-23 21:24:13 +00:00
|
|
|
hasChildren: or('periodic', 'parameterized'),
|
|
|
|
|
|
|
|
parent: belongsTo('job', { inverse: 'children' }),
|
|
|
|
children: hasMany('job', { inverse: 'parent' }),
|
|
|
|
|
2018-01-27 00:27:04 +00:00
|
|
|
// The parent job name is prepended to child launch job names
|
|
|
|
trimmedName: computed('name', 'parent', function() {
|
|
|
|
return this.get('parent.content') ? this.get('name').replace(/.+?\//, '') : this.get('name');
|
|
|
|
}),
|
|
|
|
|
2018-01-26 23:01:10 +00:00
|
|
|
// A composite of type and other job attributes to determine
|
|
|
|
// a better type descriptor for human interpretation rather
|
|
|
|
// than for scheduling.
|
|
|
|
displayType: computed('type', 'periodic', 'parameterized', function() {
|
|
|
|
if (this.get('periodic')) {
|
|
|
|
return 'periodic';
|
|
|
|
} else if (this.get('parameterized')) {
|
|
|
|
return 'parameterized';
|
|
|
|
}
|
|
|
|
return this.get('type');
|
|
|
|
}),
|
|
|
|
|
2018-01-25 17:29:47 +00:00
|
|
|
// A composite of type and other job attributes to determine
|
|
|
|
// type for templating rather than scheduling
|
|
|
|
templateType: computed(
|
|
|
|
'type',
|
|
|
|
'periodic',
|
|
|
|
'parameterized',
|
|
|
|
'parent.periodic',
|
|
|
|
'parent.parameterized',
|
|
|
|
function() {
|
|
|
|
const type = this.get('type');
|
|
|
|
|
|
|
|
if (this.get('periodic')) {
|
|
|
|
return 'periodic';
|
|
|
|
} else if (this.get('parameterized')) {
|
|
|
|
return 'parameterized';
|
|
|
|
} else if (this.get('parent.periodic')) {
|
|
|
|
return 'periodic-child';
|
|
|
|
} else if (this.get('parent.parameterized')) {
|
|
|
|
return 'parameterized-child';
|
|
|
|
} else if (JOB_TYPES.includes(type)) {
|
|
|
|
// Guard against the API introducing a new type before the UI
|
|
|
|
// is prepared to handle it.
|
|
|
|
return this.get('type');
|
|
|
|
}
|
2018-01-26 23:01:10 +00:00
|
|
|
|
|
|
|
// A fail-safe in the event the API introduces a new type.
|
|
|
|
return 'service';
|
2018-01-25 17:29:47 +00:00
|
|
|
}
|
|
|
|
),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
datacenters: attr(),
|
|
|
|
taskGroups: fragmentArray('task-group', { defaultValue: () => [] }),
|
|
|
|
taskGroupSummaries: fragmentArray('task-group-summary'),
|
|
|
|
|
|
|
|
// Aggregate allocation counts across all summaries
|
|
|
|
queuedAllocs: sumAggregation('taskGroupSummaries', 'queuedAllocs'),
|
|
|
|
startingAllocs: sumAggregation('taskGroupSummaries', 'startingAllocs'),
|
|
|
|
runningAllocs: sumAggregation('taskGroupSummaries', 'runningAllocs'),
|
|
|
|
completeAllocs: sumAggregation('taskGroupSummaries', 'completeAllocs'),
|
|
|
|
failedAllocs: sumAggregation('taskGroupSummaries', 'failedAllocs'),
|
|
|
|
lostAllocs: sumAggregation('taskGroupSummaries', 'lostAllocs'),
|
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
allocsList: collect(
|
2017-09-19 14:47:10 +00:00
|
|
|
'queuedAllocs',
|
|
|
|
'startingAllocs',
|
|
|
|
'runningAllocs',
|
|
|
|
'completeAllocs',
|
|
|
|
'failedAllocs',
|
|
|
|
'lostAllocs'
|
|
|
|
),
|
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
totalAllocs: sum('allocsList'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
pendingChildren: attr('number'),
|
|
|
|
runningChildren: attr('number'),
|
|
|
|
deadChildren: attr('number'),
|
|
|
|
|
2018-01-25 17:29:47 +00:00
|
|
|
childrenList: collect('pendingChildren', 'runningChildren', 'deadChildren'),
|
|
|
|
|
|
|
|
totalChildren: sum('childrenList'),
|
|
|
|
|
|
|
|
version: attr('number'),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
versions: hasMany('job-versions'),
|
|
|
|
allocations: hasMany('allocations'),
|
|
|
|
deployments: hasMany('deployments'),
|
2017-11-29 01:23:30 +00:00
|
|
|
evaluations: hasMany('evaluations'),
|
2017-10-10 16:36:15 +00:00
|
|
|
namespace: belongsTo('namespace'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
hasPlacementFailures: bool('latestFailureEvaluation'),
|
2017-11-29 01:23:30 +00:00
|
|
|
|
|
|
|
latestEvaluation: computed('evaluations.@each.modifyIndex', 'evaluations.isPending', function() {
|
|
|
|
const evaluations = this.get('evaluations');
|
|
|
|
if (!evaluations || evaluations.get('isPending')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return evaluations.sortBy('modifyIndex').get('lastObject');
|
|
|
|
}),
|
|
|
|
|
|
|
|
latestFailureEvaluation: computed(
|
|
|
|
'evaluations.@each.modifyIndex',
|
|
|
|
'evaluations.isPending',
|
|
|
|
function() {
|
|
|
|
const evaluations = this.get('evaluations');
|
|
|
|
if (!evaluations || evaluations.get('isPending')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const failureEvaluations = evaluations.filterBy('hasPlacementFailures');
|
|
|
|
if (failureEvaluations) {
|
|
|
|
return failureEvaluations.sortBy('modifyIndex').get('lastObject');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
supportsDeployments: equal('type', 'service'),
|
2017-10-24 19:35:29 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
runningDeployment: computed('deployments.@each.status', function() {
|
|
|
|
return this.get('deployments').findBy('status', 'running');
|
|
|
|
}),
|
|
|
|
|
|
|
|
fetchRawDefinition() {
|
|
|
|
return this.store.adapterFor('job').fetchRawDefinition(this);
|
|
|
|
},
|
|
|
|
|
2018-01-26 22:32:11 +00:00
|
|
|
forcePeriodic() {
|
|
|
|
return this.store.adapterFor('job').forcePeriodic(this);
|
|
|
|
},
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
statusClass: computed('status', function() {
|
|
|
|
const classMap = {
|
|
|
|
pending: 'is-pending',
|
|
|
|
running: 'is-primary',
|
|
|
|
dead: 'is-light',
|
|
|
|
};
|
|
|
|
|
|
|
|
return classMap[this.get('status')] || 'is-dark';
|
|
|
|
}),
|
2018-01-26 00:50:31 +00:00
|
|
|
|
|
|
|
payload: attr('string'),
|
|
|
|
decodedPayload: computed('payload', function() {
|
|
|
|
// Lazily decode the base64 encoded payload
|
|
|
|
return window.atob(this.get('payload') || '');
|
|
|
|
}),
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|