Model job scaling and events in Mirage
This commit is contained in:
parent
17e6d5b836
commit
765077eb03
|
@ -157,6 +157,15 @@ export default function() {
|
|||
return deployment ? this.serialize(deployment) : new Response(200, {}, 'null');
|
||||
});
|
||||
|
||||
this.get(
|
||||
'/job/:id/scale',
|
||||
withBlockingSupport(function({ jobScales }, { params }) {
|
||||
const obj = jobScales.findBy({ jobId: params.id });
|
||||
console.log('Job Scale Object', obj);
|
||||
return this.serialize(jobScales.findBy({ jobId: params.id }));
|
||||
})
|
||||
);
|
||||
|
||||
this.post('/job/:id/periodic/force', function(schema, { params }) {
|
||||
// Create the child job
|
||||
const parent = schema.jobs.find(params.id);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import { Factory, trait } from 'ember-cli-mirage';
|
||||
import faker from 'nomad-ui/mirage/faker';
|
||||
|
||||
export default Factory.extend({
|
||||
groupNames: [],
|
||||
|
||||
jobId: '',
|
||||
JobID() {
|
||||
return this.jobId;
|
||||
},
|
||||
namespace: null,
|
||||
shallow: false,
|
||||
|
||||
afterCreate(jobScale, server) {
|
||||
const groups = jobScale.groupNames.map(group =>
|
||||
server.create('task-group-scale', {
|
||||
id: group,
|
||||
shallow: jobScale.shallow,
|
||||
})
|
||||
);
|
||||
|
||||
jobScale.update({
|
||||
taskGroupScaleIds: groups.mapBy('id'),
|
||||
});
|
||||
},
|
||||
});
|
|
@ -158,6 +158,17 @@ export default Factory.extend({
|
|||
job_summary_id: jobSummary.id,
|
||||
});
|
||||
|
||||
const jobScale = server.create('job-scale', {
|
||||
groupNames: groups.mapBy('name'),
|
||||
jobId: job.id,
|
||||
namespace: job.namespace,
|
||||
shallow: job.shallow,
|
||||
});
|
||||
|
||||
job.update({
|
||||
jobScaleId: jobScale.id,
|
||||
});
|
||||
|
||||
if (!job.noDeployments) {
|
||||
Array(faker.random.number({ min: 1, max: 3 }))
|
||||
.fill(null)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import { Factory, trait } from 'ember-cli-mirage';
|
||||
import faker from 'nomad-ui/mirage/faker';
|
||||
|
||||
const REF_TIME = new Date();
|
||||
|
||||
export default Factory.extend({
|
||||
time: () => faker.date.past(2 / 365, REF_TIME) * 1000000,
|
||||
count: () => faker.random.number(10),
|
||||
previousCount: () => faker.random.number(10),
|
||||
error: () => faker.random.number(10) > 9,
|
||||
message: 'Sample message for a job scale event',
|
||||
meta: () => ({
|
||||
'nomad_autoscaler.count.capped': true,
|
||||
'nomad_autoscaler.count.original': 0,
|
||||
'nomad_autoscaler.reason_history': ['scaling down because factor is 0.000000'],
|
||||
}),
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
import { Factory, trait } from 'ember-cli-mirage';
|
||||
import faker from 'nomad-ui/mirage/faker';
|
||||
|
||||
export default Factory.extend({
|
||||
name: id => id,
|
||||
|
||||
desired: 1,
|
||||
placed: 1,
|
||||
running: 1,
|
||||
healthy: 1,
|
||||
unhealthy: 1,
|
||||
|
||||
shallow: false,
|
||||
|
||||
afterCreate(taskGroupScale, server) {
|
||||
if (!taskGroupScale.shallow) {
|
||||
const events = server.createList('scale-event', faker.random.number({ min: 1, max: 10 }));
|
||||
|
||||
taskGroupScale.update({
|
||||
eventIds: events.mapBy('id'),
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
job: belongsTo(),
|
||||
taskGroupScales: hasMany(),
|
||||
});
|
|
@ -3,4 +3,5 @@ import { Model, hasMany, belongsTo } from 'ember-cli-mirage';
|
|||
export default Model.extend({
|
||||
task_groups: hasMany('task-group'),
|
||||
job_summary: belongsTo('job-summary'),
|
||||
job_scale: belongsTo('job-scale'),
|
||||
});
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import { Model, belongsTo } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
taskGroupScale: belongsTo(),
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
|
||||
|
||||
export default Model.extend({
|
||||
jobScale: belongsTo(),
|
||||
events: hasMany('scale-event'),
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
import ApplicationSerializer from './application';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
embed: true,
|
||||
include: ['taskGroupScales'],
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
import ApplicationSerializer from './application';
|
||||
|
||||
export default ApplicationSerializer.extend({
|
||||
embed: true,
|
||||
include: ['events'],
|
||||
});
|
Loading…
Reference in New Issue