github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/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()}-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    afterCreate(group, server) {
    20      const tasks = server.createList('task', group.count, {
    21        taskGroup: group,
    22      });
    23  
    24      group.update({
    25        taskIds: tasks.mapBy('id'),
    26        task_ids: tasks.mapBy('id'),
    27      });
    28  
    29      if (group.createAllocations) {
    30        Array(group.count)
    31          .fill(null)
    32          .forEach((_, i) => {
    33            server.create('allocation', {
    34              jobId: group.job.id,
    35              namespace: group.job.namespace,
    36              taskGroup: group.name,
    37              name: `${group.name}.[${i}]`,
    38            });
    39          });
    40      }
    41    },
    42  });