2020-03-25 12:51:26 +00:00
|
|
|
import { Factory } from 'ember-cli-mirage';
|
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
|
|
|
import { STORAGE_PROVIDERS } from '../common';
|
|
|
|
|
|
|
|
export default Factory.extend({
|
|
|
|
id: () => faker.random.uuid(),
|
|
|
|
|
|
|
|
// Topologies is currently unused by the UI. This should
|
|
|
|
// eventually become dynamic.
|
|
|
|
topologies: () => [{ foo: 'bar' }],
|
|
|
|
|
|
|
|
provider: faker.helpers.randomize(STORAGE_PROVIDERS),
|
|
|
|
version: '1.0.1',
|
2020-05-18 21:53:18 +00:00
|
|
|
|
2020-03-25 12:51:26 +00:00
|
|
|
controllerRequired: faker.random.boolean,
|
2020-05-18 21:53:18 +00:00
|
|
|
|
|
|
|
controllersHealthy() {
|
|
|
|
if (!this.controllerRequired) return 0;
|
|
|
|
return faker.random.number(3);
|
|
|
|
},
|
2020-05-03 04:31:17 +00:00
|
|
|
controllersExpected() {
|
2020-05-19 00:04:50 +00:00
|
|
|
// This property must be read before the conditional
|
|
|
|
// or Mirage will incorrectly sort dependent properties.
|
|
|
|
const healthy = this.controllersHealthy;
|
2020-05-18 21:53:18 +00:00
|
|
|
if (!this.controllerRequired) return 0;
|
2020-05-19 00:04:50 +00:00
|
|
|
return healthy + faker.random.number({ min: 1, max: 2 });
|
2020-05-03 04:31:17 +00:00
|
|
|
},
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-05-05 21:28:15 +00:00
|
|
|
nodesHealthy: () => faker.random.number(3),
|
2020-05-03 04:31:17 +00:00
|
|
|
nodesExpected() {
|
2020-05-05 21:28:15 +00:00
|
|
|
return this.nodesHealthy + faker.random.number({ min: 1, max: 2 });
|
2020-05-03 04:31:17 +00:00
|
|
|
},
|
2020-03-25 12:51:26 +00:00
|
|
|
|
|
|
|
// Internal property to determine whether or not this plugin
|
|
|
|
// Should create one or two Jobs to represent Node and
|
|
|
|
// Controller plugins.
|
2020-05-18 21:53:18 +00:00
|
|
|
isMonolith() {
|
|
|
|
if (!this.controllerRequired) return false;
|
|
|
|
return faker.random.boolean;
|
|
|
|
},
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-04 02:25:33 +00:00
|
|
|
// When false, the plugin will not make its own volumes
|
|
|
|
createVolumes: true,
|
|
|
|
|
2020-05-08 00:29:42 +00:00
|
|
|
// When true, doesn't create any resources, state, or events for associated allocations
|
|
|
|
shallow: false,
|
|
|
|
|
2020-03-25 12:51:26 +00:00
|
|
|
afterCreate(plugin, server) {
|
|
|
|
let storageNodes;
|
|
|
|
let storageControllers;
|
|
|
|
|
|
|
|
if (plugin.isMonolith) {
|
|
|
|
const pluginJob = server.create('job', { type: 'service', createAllocations: false });
|
2020-05-05 21:28:15 +00:00
|
|
|
const count = plugin.nodesExpected;
|
2020-05-08 00:29:42 +00:00
|
|
|
storageNodes = server.createList('storage-node', count, {
|
|
|
|
job: pluginJob,
|
|
|
|
shallow: plugin.shallow,
|
|
|
|
});
|
|
|
|
storageControllers = server.createList('storage-controller', count, {
|
|
|
|
job: pluginJob,
|
|
|
|
shallow: plugin.shallow,
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
} else {
|
2020-05-18 21:53:18 +00:00
|
|
|
const controllerJob =
|
|
|
|
plugin.controllerRequired &&
|
|
|
|
server.create('job', {
|
|
|
|
type: 'service',
|
|
|
|
createAllocations: false,
|
|
|
|
shallow: plugin.shallow,
|
|
|
|
});
|
2020-05-08 00:29:42 +00:00
|
|
|
const nodeJob = server.create('job', {
|
|
|
|
type: 'service',
|
|
|
|
createAllocations: false,
|
|
|
|
shallow: plugin.shallow,
|
|
|
|
});
|
2020-05-05 21:28:15 +00:00
|
|
|
storageNodes = server.createList('storage-node', plugin.nodesExpected, {
|
2020-03-25 12:51:26 +00:00
|
|
|
job: nodeJob,
|
2020-05-08 00:29:42 +00:00
|
|
|
shallow: plugin.shallow,
|
2020-03-25 12:51:26 +00:00
|
|
|
});
|
2020-05-18 21:53:18 +00:00
|
|
|
storageControllers =
|
|
|
|
plugin.controllerRequired &&
|
|
|
|
server.createList('storage-controller', plugin.controllersExpected, {
|
|
|
|
job: controllerJob,
|
|
|
|
shallow: plugin.shallow,
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin.update({
|
|
|
|
controllers: storageControllers,
|
|
|
|
nodes: storageNodes,
|
|
|
|
});
|
|
|
|
|
2020-04-04 02:25:33 +00:00
|
|
|
if (plugin.createVolumes) {
|
2020-05-03 04:31:17 +00:00
|
|
|
server.createList('csi-volume', faker.random.number({ min: 1, max: 5 }), {
|
2020-04-04 02:25:33 +00:00
|
|
|
plugin,
|
|
|
|
provider: plugin.provider,
|
|
|
|
});
|
|
|
|
}
|
2020-03-25 12:51:26 +00:00
|
|
|
},
|
|
|
|
});
|