2018-07-09 19:59:40 +00:00
|
|
|
import config from 'nomad-ui/config/environment';
|
|
|
|
|
|
|
|
const withNamespaces = getConfigValue('mirageWithNamespaces', false);
|
|
|
|
const withTokens = getConfigValue('mirageWithTokens', true);
|
2018-08-10 02:57:21 +00:00
|
|
|
const withRegions = getConfigValue('mirageWithRegions', false);
|
2018-07-09 19:59:40 +00:00
|
|
|
|
|
|
|
const allScenarios = {
|
|
|
|
smallCluster,
|
|
|
|
mediumCluster,
|
|
|
|
largeCluster,
|
|
|
|
massiveCluster,
|
|
|
|
allJobTypes,
|
|
|
|
allNodeTypes,
|
2019-06-13 18:15:42 +00:00
|
|
|
everyFeature,
|
2018-07-09 19:59:40 +00:00
|
|
|
emptyCluster,
|
|
|
|
};
|
|
|
|
|
|
|
|
const scenario = getConfigValue('mirageScenario', 'emptyCluster');
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
export default function(server) {
|
2018-07-09 19:59:40 +00:00
|
|
|
const activeScenario = allScenarios[scenario];
|
|
|
|
if (!activeScenario) {
|
|
|
|
throw new Error(
|
|
|
|
`Selected Mirage scenario does not exist.\n\n${scenario} not in list: \n\n\t${Object.keys(
|
|
|
|
allScenarios
|
|
|
|
).join('\n\t')}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (withNamespaces) createNamespaces(server);
|
|
|
|
if (withTokens) createTokens(server);
|
2018-08-10 02:57:21 +00:00
|
|
|
if (withRegions) createRegions(server);
|
2018-07-09 19:59:40 +00:00
|
|
|
activeScenario(server);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scenarios
|
|
|
|
|
|
|
|
function smallCluster(server) {
|
|
|
|
server.createList('agent', 3);
|
|
|
|
server.createList('node', 5);
|
|
|
|
server.createList('job', 5);
|
2019-07-31 00:21:42 +00:00
|
|
|
server.createList('allocFile', 5);
|
|
|
|
server.create('allocFile', 'dir', { depth: 2 });
|
2018-07-09 19:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mediumCluster(server) {
|
2017-09-19 14:47:10 +00:00
|
|
|
server.createList('agent', 3);
|
|
|
|
server.createList('node', 50);
|
2018-07-09 19:59:40 +00:00
|
|
|
server.createList('job', 25);
|
|
|
|
}
|
2017-10-07 01:27:36 +00:00
|
|
|
|
2018-07-09 19:59:40 +00:00
|
|
|
// Due to Mirage performance, large cluster scenarios will be slow
|
|
|
|
function largeCluster(server) {
|
|
|
|
server.createList('agent', 5);
|
|
|
|
server.createList('node', 1000);
|
|
|
|
server.createList('job', 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
function massiveCluster(server) {
|
|
|
|
server.createList('agent', 7);
|
|
|
|
server.createList('node', 5000);
|
|
|
|
server.createList('job', 2000);
|
|
|
|
}
|
2017-10-07 01:27:36 +00:00
|
|
|
|
2018-07-09 19:59:40 +00:00
|
|
|
function allJobTypes(server) {
|
|
|
|
server.createList('agent', 3);
|
|
|
|
server.createList('node', 5);
|
2017-10-14 18:01:28 +00:00
|
|
|
|
2018-07-09 19:59:40 +00:00
|
|
|
server.create('job', { type: 'service' });
|
|
|
|
server.create('job', { type: 'batch' });
|
|
|
|
server.create('job', { type: 'system' });
|
|
|
|
server.create('job', 'periodic');
|
|
|
|
server.create('job', 'parameterized');
|
|
|
|
server.create('job', { failedPlacements: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
function allNodeTypes(server) {
|
|
|
|
server.createList('agent', 3);
|
|
|
|
|
|
|
|
server.create('node');
|
|
|
|
server.create('node', 'forceIPv4');
|
|
|
|
server.create('node', 'draining');
|
|
|
|
server.create('node', 'forcedDraining');
|
|
|
|
server.create('node', 'noDeadlineDraining');
|
|
|
|
server.create('node', 'withMeta');
|
|
|
|
|
|
|
|
server.createList('job', 3);
|
|
|
|
}
|
|
|
|
|
2019-06-13 18:15:42 +00:00
|
|
|
function everyFeature(server) {
|
2019-06-13 00:40:37 +00:00
|
|
|
server.createList('agent', 3);
|
|
|
|
|
|
|
|
server.create('node', 'forceIPv4');
|
|
|
|
server.create('node', 'draining');
|
|
|
|
server.create('node', 'forcedDraining');
|
|
|
|
server.create('node', 'noDeadlineDraining');
|
|
|
|
server.create('node', 'withMeta');
|
|
|
|
|
|
|
|
const job1 = server.create('job', {
|
|
|
|
type: 'service',
|
|
|
|
activeDeployment: true,
|
|
|
|
namespaceId: 'default',
|
|
|
|
createAllocations: false,
|
|
|
|
});
|
|
|
|
server.create('job', { type: 'batch', failedPlacements: true, namespaceId: 'default' });
|
|
|
|
server.create('job', { type: 'system', namespaceId: 'default' });
|
|
|
|
server.create('job', 'periodic', { namespaceId: 'default' });
|
|
|
|
server.create('job', 'parameterized', { namespaceId: 'default' });
|
|
|
|
|
|
|
|
server.create('allocation', 'rescheduled', { jobId: job1.id });
|
|
|
|
server.create('allocation', 'preempter', { jobId: job1.id });
|
|
|
|
server.create('allocation', 'preempted', { jobId: job1.id });
|
|
|
|
}
|
|
|
|
|
2018-07-09 19:59:40 +00:00
|
|
|
function emptyCluster(server) {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Behaviors
|
|
|
|
|
|
|
|
function createTokens(server) {
|
2017-10-14 18:01:28 +00:00
|
|
|
server.createList('token', 3);
|
|
|
|
logTokens(server);
|
|
|
|
}
|
|
|
|
|
2018-07-09 19:59:40 +00:00
|
|
|
function createNamespaces(server) {
|
|
|
|
server.createList('namespace', 3);
|
|
|
|
}
|
|
|
|
|
2018-08-10 02:57:21 +00:00
|
|
|
function createRegions(server) {
|
|
|
|
['americas', 'europe', 'asia', 'some-long-name-just-to-test'].forEach(id => {
|
|
|
|
server.create('region', { id });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-14 18:01:28 +00:00
|
|
|
/* eslint-disable */
|
|
|
|
function logTokens(server) {
|
|
|
|
console.log('TOKENS:');
|
|
|
|
server.db.tokens.forEach(token => {
|
|
|
|
console.log(`
|
|
|
|
Name: ${token.name}
|
|
|
|
Secret: ${token.secretId}
|
|
|
|
Accessor: ${token.accessorId}
|
|
|
|
|
|
|
|
`);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|
2018-07-09 19:59:40 +00:00
|
|
|
|
|
|
|
function getConfigValue(variableName, defaultValue) {
|
|
|
|
const value = config.APP[variableName];
|
|
|
|
if (value !== undefined) return value;
|
|
|
|
|
|
|
|
console.warn(
|
|
|
|
`No ENV.APP value set for "${variableName}". Defaulting to "${defaultValue}". To set a custom value, modify config/environment.js`
|
|
|
|
);
|
|
|
|
return defaultValue;
|
|
|
|
}
|
2017-10-14 18:01:28 +00:00
|
|
|
/* eslint-enable */
|