2017-09-19 14:47:10 +00:00
|
|
|
import { Factory, faker } from 'ember-cli-mirage';
|
|
|
|
|
|
|
|
const DISK_RESERVATIONS = [200, 500, 1000, 2000, 5000, 10000, 100000];
|
|
|
|
|
|
|
|
export default Factory.extend({
|
2018-04-12 17:47:12 +00:00
|
|
|
name: id => `${faker.hacker.noun().dasherize()}-g-${id}`,
|
2019-04-12 03:08:09 +00:00
|
|
|
count: () => faker.random.number({ min: 1, max: 2 }),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
ephemeralDisk: () => ({
|
|
|
|
Sticky: faker.random.boolean(),
|
|
|
|
SizeMB: faker.random.arrayElement(DISK_RESERVATIONS),
|
|
|
|
Migrate: faker.random.boolean(),
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Directive used to control whether or not allocations are automatically
|
|
|
|
// created.
|
|
|
|
createAllocations: true,
|
|
|
|
|
2018-05-04 20:08:30 +00:00
|
|
|
// Directived used to control whether or not the allocation should fail
|
|
|
|
// and reschedule, creating reschedule events.
|
|
|
|
withRescheduling: false,
|
|
|
|
|
2019-09-04 14:39:56 +00:00
|
|
|
// Directive used to control whether the task group should have services.
|
|
|
|
withServices: false,
|
|
|
|
|
2019-04-12 03:08:09 +00:00
|
|
|
// When true, only creates allocations
|
|
|
|
shallow: false,
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
afterCreate(group, server) {
|
2019-04-12 03:08:09 +00:00
|
|
|
let taskIds = [];
|
|
|
|
|
|
|
|
if (!group.shallow) {
|
|
|
|
const tasks = server.createList('task', group.count, {
|
|
|
|
taskGroup: group,
|
|
|
|
});
|
|
|
|
taskIds = tasks.mapBy('id');
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
group.update({
|
2019-04-12 03:08:09 +00:00
|
|
|
taskIds: taskIds,
|
|
|
|
task_ids: taskIds,
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (group.createAllocations) {
|
|
|
|
Array(group.count)
|
|
|
|
.fill(null)
|
|
|
|
.forEach((_, i) => {
|
2018-05-04 20:08:30 +00:00
|
|
|
const props = {
|
2017-09-19 14:47:10 +00:00
|
|
|
jobId: group.job.id,
|
2018-02-16 02:55:59 +00:00
|
|
|
namespace: group.job.namespace,
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroup: group.name,
|
|
|
|
name: `${group.name}.[${i}]`,
|
2018-05-04 20:08:30 +00:00
|
|
|
rescheduleSuccess: group.withRescheduling ? faker.random.boolean() : null,
|
|
|
|
rescheduleAttempts: group.withRescheduling
|
|
|
|
? faker.random.number({ min: 1, max: 5 })
|
|
|
|
: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (group.withRescheduling) {
|
|
|
|
server.create('allocation', 'rescheduled', props);
|
|
|
|
} else {
|
|
|
|
server.create('allocation', props);
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
}
|
2019-09-04 14:39:56 +00:00
|
|
|
|
|
|
|
if (group.withServices) {
|
|
|
|
Array(faker.random.number({ min: 1, max: 3 }))
|
|
|
|
.fill(null)
|
|
|
|
.forEach(() => {
|
|
|
|
server.create('service', {
|
|
|
|
task_group: group,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|