github.com/manicqin/nomad@v0.9.5/ui/mirage/factories/task-group.js (about) 1 import { Factory } from 'ember-cli-mirage'; 2 import faker from 'nomad-ui/mirage/faker'; 3 4 const DISK_RESERVATIONS = [200, 500, 1000, 2000, 5000, 10000, 100000]; 5 6 export default Factory.extend({ 7 name: id => `${faker.hacker.noun().dasherize()}-g-${id}`, 8 count: () => faker.random.number({ min: 1, max: 2 }), 9 10 ephemeralDisk: () => ({ 11 Sticky: faker.random.boolean(), 12 SizeMB: faker.helpers.randomize(DISK_RESERVATIONS), 13 Migrate: faker.random.boolean(), 14 }), 15 16 // Directive used to control whether or not allocations are automatically 17 // created. 18 createAllocations: true, 19 20 // Directived used to control whether or not the allocation should fail 21 // and reschedule, creating reschedule events. 22 withRescheduling: false, 23 24 // Directive used to control whether the task group should have services. 25 withServices: false, 26 27 // When true, only creates allocations 28 shallow: false, 29 30 afterCreate(group, server) { 31 let taskIds = []; 32 33 if (!group.shallow) { 34 const tasks = server.createList('task', group.count, { 35 taskGroup: group, 36 }); 37 taskIds = tasks.mapBy('id'); 38 } 39 40 group.update({ 41 taskIds: taskIds, 42 task_ids: taskIds, 43 }); 44 45 if (group.createAllocations) { 46 Array(group.count) 47 .fill(null) 48 .forEach((_, i) => { 49 const props = { 50 jobId: group.job.id, 51 namespace: group.job.namespace, 52 taskGroup: group.name, 53 name: `${group.name}.[${i}]`, 54 rescheduleSuccess: group.withRescheduling ? faker.random.boolean() : null, 55 rescheduleAttempts: group.withRescheduling 56 ? faker.random.number({ min: 1, max: 5 }) 57 : 0, 58 }; 59 60 if (group.withRescheduling) { 61 server.create('allocation', 'rescheduled', props); 62 } else { 63 server.create('allocation', props); 64 } 65 }); 66 } 67 68 if (group.withServices) { 69 Array(faker.random.number({ min: 1, max: 3 })) 70 .fill(null) 71 .forEach(() => { 72 server.create('service', { 73 task_group: group, 74 }); 75 }); 76 } 77 }, 78 });