github.com/anuvu/nomad@v0.8.7-atom1/ui/mirage/factories/task-group.js (about)

     1  import { Factory, faker } from 'ember-cli-mirage';
     2  
     3  const DISK_RESERVATIONS = [200, 500, 1000, 2000, 5000, 10000, 100000];
     4  
     5  export default Factory.extend({
     6    name: id => `${faker.hacker.noun().dasherize()}-g-${id}`,
     7    count: () => faker.random.number({ min: 1, max: 4 }),
     8  
     9    ephemeralDisk: () => ({
    10      Sticky: faker.random.boolean(),
    11      SizeMB: faker.random.arrayElement(DISK_RESERVATIONS),
    12      Migrate: faker.random.boolean(),
    13    }),
    14  
    15    // Directive used to control whether or not allocations are automatically
    16    // created.
    17    createAllocations: true,
    18  
    19    // Directived used to control whether or not the allocation should fail
    20    // and reschedule, creating reschedule events.
    21    withRescheduling: false,
    22  
    23    afterCreate(group, server) {
    24      const tasks = server.createList('task', group.count, {
    25        taskGroup: group,
    26      });
    27  
    28      group.update({
    29        taskIds: tasks.mapBy('id'),
    30        task_ids: tasks.mapBy('id'),
    31      });
    32  
    33      if (group.createAllocations) {
    34        Array(group.count)
    35          .fill(null)
    36          .forEach((_, i) => {
    37            const props = {
    38              jobId: group.job.id,
    39              namespace: group.job.namespace,
    40              taskGroup: group.name,
    41              name: `${group.name}.[${i}]`,
    42              rescheduleSuccess: group.withRescheduling ? faker.random.boolean() : null,
    43              rescheduleAttempts: group.withRescheduling
    44                ? faker.random.number({ min: 1, max: 5 })
    45                : 0,
    46            };
    47  
    48            if (group.withRescheduling) {
    49              server.create('allocation', 'rescheduled', props);
    50            } else {
    51              server.create('allocation', props);
    52            }
    53          });
    54      }
    55    },
    56  });