NodeEvent and NodeDriver modeling in Mirage

This commit is contained in:
Michael Lange 2018-05-11 17:30:15 -07:00
parent 9598a18bc1
commit 3f781743e4
6 changed files with 67 additions and 1 deletions

View file

@ -0,0 +1,12 @@
import { Factory, faker } from 'ember-cli-mirage';
import { provide } from '../utils';
const REF_TIME = new Date();
const STATES = provide(10, faker.system.fileExt.bind(faker.system));
export default Factory.extend({
subsystem: faker.list.random(...STATES),
message: () => faker.lorem.sentence(),
time: () => faker.date.past(2 / 365, REF_TIME),
details: null,
});

View file

@ -4,6 +4,7 @@ import { DATACENTERS, HOSTS } from '../common';
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
const NODE_STATUSES = ['initializing', 'ready', 'down'];
const REF_DATE = new Date();
export default Factory.extend({
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
@ -28,6 +29,8 @@ export default Factory.extend({
},
}),
drivers: makeDrivers,
attributes() {
// TODO add variability to these
return {
@ -72,5 +75,42 @@ export default Factory.extend({
server.create('client-stats', {
id: node.httpAddr,
});
const events = server.createList('node-event', faker.random.number({ min: 1, max: 10 }), {
nodeId: node.id,
});
node.update({
eventIds: events.mapBy('id'),
});
},
});
function makeDrivers() {
const generate = () => {
const detected = Math.random() > 0.3;
const healthy = detected && Math.random() > 0.3;
const attributes = {
'driver.name.version': '1.0.0',
'driver.name.status': 'awesome',
'driver.name.more.details': 'yeah',
'driver.name.more.again': 'we got that',
};
return {
Detected: detected,
Healthy: healthy,
HealthDescription: healthy ? 'Driver is healthy' : 'Uh oh',
UpdateTime: faker.date.past(5 / 365, REF_DATE),
Attributes: Math.random() > 0.3 && detected ? attributes : null,
};
};
return {
docker: generate(),
rkt: generate(),
qemu: generate(),
exec: generate(),
raw_exec: generate(),
java: generate(),
};
}

View file

@ -1,4 +1,4 @@
import { Factory, faker, trait } from 'ember-cli-mirage';
import { Factory, faker } from 'ember-cli-mirage';
import { provide } from '../utils';
const REF_TIME = new Date();

View file

@ -1,6 +1,8 @@
import { Factory, faker } from 'ember-cli-mirage';
import { generateResources } from '../common';
const DRIVERS = ['docker', 'java', 'rkt', 'qemu', 'exec', 'raw_exec'];
export default Factory.extend({
// Hidden property used to compute the Summary hash
groupNames: [],
@ -8,6 +10,7 @@ export default Factory.extend({
JobID: '',
name: id => `task-${faker.hacker.noun()}-${id}`,
driver: faker.list.random(...DRIVERS),
Resources: generateResources,
});

5
ui/mirage/models/node.js Normal file
View file

@ -0,0 +1,5 @@
import { Model, hasMany } from 'ember-cli-mirage';
export default Model.extend({
events: hasMany('node-event'),
});

View file

@ -0,0 +1,6 @@
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
embed: true,
include: ['events'],
});