2019-09-26 18:47:07 +00:00
|
|
|
import { Factory, trait } from 'ember-cli-mirage';
|
2019-10-03 14:13:08 +00:00
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { provide } from '../utils';
|
2018-11-02 05:11:56 +00:00
|
|
|
import { DATACENTERS, HOSTS, generateResources } from '../common';
|
2018-05-30 18:20:59 +00:00
|
|
|
import moment from 'moment';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
|
|
|
|
const NODE_STATUSES = ['initializing', 'ready', 'down'];
|
2019-02-12 04:01:14 +00:00
|
|
|
const NODE_CLASSES = provide(7, faker.company.bsBuzz.bind(faker.company));
|
2018-05-12 00:30:15 +00:00
|
|
|
const REF_DATE = new Date();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Factory.extend({
|
|
|
|
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
|
|
|
|
name: i => `nomad@${HOSTS[i % HOSTS.length]}`,
|
|
|
|
|
2019-09-30 14:44:22 +00:00
|
|
|
datacenter: () => faker.helpers.randomize(DATACENTERS),
|
|
|
|
nodeClass: () => faker.helpers.randomize(NODE_CLASSES),
|
2018-05-30 18:20:59 +00:00
|
|
|
drain: faker.random.boolean,
|
2019-09-30 14:44:22 +00:00
|
|
|
status: () => faker.helpers.randomize(NODE_STATUSES),
|
2020-08-28 00:58:24 +00:00
|
|
|
tlsEnabled: faker.random.boolean,
|
2018-05-30 18:20:59 +00:00
|
|
|
schedulingEligibility: () => (faker.random.boolean() ? 'eligible' : 'ineligible'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
createIndex: i => i,
|
|
|
|
modifyIndex: () => faker.random.number({ min: 10, max: 2000 }),
|
|
|
|
|
|
|
|
httpAddr() {
|
|
|
|
return this.name.split('@')[1];
|
|
|
|
},
|
|
|
|
|
|
|
|
forceIPv4: trait({
|
|
|
|
name: i => {
|
|
|
|
const ipv4Hosts = HOSTS.filter(h => !h.startsWith('['));
|
|
|
|
return `nomad@${ipv4Hosts[i % ipv4Hosts.length]}`;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2018-05-30 18:20:59 +00:00
|
|
|
draining: trait({
|
|
|
|
drain: true,
|
|
|
|
schedulingEligibility: 'ineligible',
|
|
|
|
drainStrategy: {
|
|
|
|
Deadline: faker.random.number({ min: 30 * 1000, max: 5 * 60 * 60 * 1000 }) * 1000000,
|
|
|
|
ForceDeadline: moment(REF_DATE).add(faker.random.number({ min: 1, max: 5 }), 'd'),
|
|
|
|
IgnoreSystemJobs: faker.random.boolean(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2018-05-30 18:26:48 +00:00
|
|
|
forcedDraining: trait({
|
|
|
|
drain: true,
|
|
|
|
schedulingEligibility: 'ineligible',
|
|
|
|
drainStrategy: {
|
|
|
|
Deadline: -1,
|
|
|
|
ForceDeadline: '0001-01-01T00:00:00Z',
|
|
|
|
IgnoreSystemJobs: faker.random.boolean(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
noDeadlineDraining: trait({
|
|
|
|
drain: true,
|
|
|
|
schedulingEligibility: 'ineligible',
|
|
|
|
drainStrategy: {
|
|
|
|
Deadline: 0,
|
|
|
|
ForceDeadline: '0001-01-01T00:00:00Z',
|
|
|
|
IgnoreSystemJobs: faker.random.boolean(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2020-02-11 04:36:51 +00:00
|
|
|
noHostVolumes: trait({
|
|
|
|
hostVolumes: () => ({}),
|
|
|
|
}),
|
|
|
|
|
2021-03-22 06:01:22 +00:00
|
|
|
reserved: trait({
|
|
|
|
reservedResources: generateResources({
|
|
|
|
CPU: 1000,
|
|
|
|
MemoryMB: 2000,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2018-05-30 18:20:59 +00:00
|
|
|
drainStrategy: null,
|
|
|
|
|
2018-05-12 00:30:15 +00:00
|
|
|
drivers: makeDrivers,
|
|
|
|
|
2020-03-13 07:18:05 +00:00
|
|
|
hostVolumes: makeHostVolumes,
|
2020-02-11 04:36:51 +00:00
|
|
|
|
2020-10-12 22:26:54 +00:00
|
|
|
nodeResources: generateResources,
|
2018-11-02 05:11:56 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
attributes() {
|
|
|
|
// TODO add variability to these
|
|
|
|
return {
|
|
|
|
'os.version': '10.12.5',
|
|
|
|
'cpu.modelname': 'Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz',
|
|
|
|
'nomad.revision': 'f551dcb83e3ac144c9dbb90583b6e82d234662e9',
|
|
|
|
'driver.docker.volumes.enabled': '1',
|
|
|
|
'driver.docker': '1',
|
|
|
|
'cpu.frequency': '2300',
|
|
|
|
'memory.totalbytes': '17179869184',
|
|
|
|
'driver.mock_driver': '1',
|
|
|
|
'kernel.version': '16.6.0',
|
|
|
|
'unique.network.ip-address': '127.0.0.1',
|
|
|
|
'nomad.version': '0.5.5dev',
|
|
|
|
'unique.hostname': 'bacon-mac',
|
|
|
|
'cpu.arch': 'amd64',
|
|
|
|
'os.name': 'darwin',
|
|
|
|
'kernel.name': 'darwin',
|
|
|
|
'unique.storage.volume': '/dev/disk1',
|
|
|
|
'driver.docker.version': '17.03.1-ce',
|
|
|
|
'cpu.totalcompute': '18400',
|
|
|
|
'unique.storage.bytestotal': '249783500800',
|
|
|
|
'cpu.numcores': '8',
|
|
|
|
'os.signals':
|
|
|
|
'SIGCONT,SIGSTOP,SIGSYS,SIGINT,SIGIOT,SIGXCPU,SIGSEGV,SIGUSR1,SIGTTIN,SIGURG,SIGUSR2,SIGABRT,SIGALRM,SIGCHLD,SIGFPE,SIGTSTP,SIGIO,SIGKILL,SIGQUIT,SIGXFSZ,SIGBUS,SIGHUP,SIGPIPE,SIGPROF,SIGTRAP,SIGTTOU,SIGILL,SIGTERM',
|
|
|
|
'driver.raw_exec': '1',
|
|
|
|
'unique.storage.bytesfree': '142954643456',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:52:16 +00:00
|
|
|
withMeta: trait({
|
|
|
|
meta: {
|
|
|
|
just: 'some',
|
|
|
|
prop: 'erties',
|
|
|
|
'over.here': 100,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
afterCreate(node, server) {
|
2019-04-02 01:30:44 +00:00
|
|
|
// Each node has a corresponding client stat resource that's queried via node IP.
|
2017-09-19 14:47:10 +00:00
|
|
|
// Create that record, even though it's not a relationship.
|
2019-04-02 01:30:44 +00:00
|
|
|
server.create('client-stat', {
|
2017-11-17 01:35:02 +00:00
|
|
|
id: node.httpAddr,
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2018-05-12 00:30:15 +00:00
|
|
|
|
|
|
|
const events = server.createList('node-event', faker.random.number({ min: 1, max: 10 }), {
|
|
|
|
nodeId: node.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
node.update({
|
|
|
|
eventIds: events.mapBy('id'),
|
|
|
|
});
|
2018-08-31 21:37:13 +00:00
|
|
|
|
2019-04-02 01:30:44 +00:00
|
|
|
server.create('client-stat', {
|
2018-08-31 21:37:13 +00:00
|
|
|
id: node.id,
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|
2018-05-12 00:30:15 +00:00
|
|
|
|
|
|
|
function makeDrivers() {
|
2018-05-13 03:22:45 +00:00
|
|
|
const generate = name => {
|
2019-10-03 14:13:08 +00:00
|
|
|
const detected = faker.random.number(10) >= 3;
|
|
|
|
const healthy = detected && faker.random.number(10) >= 3;
|
2018-05-12 00:30:15 +00:00
|
|
|
const attributes = {
|
2018-05-13 03:22:45 +00:00
|
|
|
[`driver.${name}.version`]: '1.0.0',
|
|
|
|
[`driver.${name}.status`]: 'awesome',
|
|
|
|
[`driver.${name}.more.details`]: 'yeah',
|
|
|
|
[`driver.${name}.more.again`]: 'we got that',
|
2018-05-12 00:30:15 +00:00
|
|
|
};
|
|
|
|
return {
|
|
|
|
Detected: detected,
|
|
|
|
Healthy: healthy,
|
|
|
|
HealthDescription: healthy ? 'Driver is healthy' : 'Uh oh',
|
|
|
|
UpdateTime: faker.date.past(5 / 365, REF_DATE),
|
2019-10-03 14:13:08 +00:00
|
|
|
Attributes: faker.random.number(10) >= 3 && detected ? attributes : null,
|
2018-05-12 00:30:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2018-05-13 03:22:45 +00:00
|
|
|
docker: generate('docker'),
|
|
|
|
rkt: generate('rkt'),
|
|
|
|
qemu: generate('qemu'),
|
|
|
|
exec: generate('exec'),
|
|
|
|
raw_exec: generate('raw_exec'),
|
|
|
|
java: generate('java'),
|
2018-05-12 00:30:15 +00:00
|
|
|
};
|
|
|
|
}
|
2020-02-11 04:36:51 +00:00
|
|
|
|
|
|
|
function makeHostVolumes() {
|
|
|
|
const generate = () => ({
|
|
|
|
Name: faker.internet.domainWord(),
|
|
|
|
Path: `/${faker.internet.userName()}/${faker.internet.domainWord()}/${faker.internet.color()}`,
|
|
|
|
ReadOnly: faker.random.boolean(),
|
|
|
|
});
|
|
|
|
|
2020-02-12 03:51:09 +00:00
|
|
|
const volumes = provide(faker.random.number({ min: 1, max: 5 }), generate);
|
2020-02-11 04:36:51 +00:00
|
|
|
return volumes.reduce((hash, volume) => {
|
|
|
|
hash[volume.Name] = volume;
|
|
|
|
return hash;
|
|
|
|
}, {});
|
|
|
|
}
|