github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/mirage/scenarios/sysbatch.js (about)

     1  export function sysbatchSmall(server) {
     2    return sysbatchScenario(server, 15);
     3  }
     4  
     5  export function sysbatchLarge(server) {
     6    return sysbatchScenario(server, 55);
     7  }
     8  
     9  function sysbatchScenario(server, clientCount) {
    10    server.createList('agent', 3, 'withConsulLink', 'withVaultLink');
    11  
    12    const clients = server.createList('node', clientCount, {
    13      datacenter: 'dc1',
    14      status: 'ready',
    15    });
    16  
    17    // Create some clients not targeted by the sysbatch job.
    18    server.createList('node', 3, {
    19      datacenter: 'dc3',
    20      status: 'ready',
    21    });
    22  
    23    // Generate non-system/sysbatch job as counter-example.
    24    server.create('job', {
    25      status: 'running',
    26      type: 'service',
    27      resourceSpec: ['M: 256, C: 500'],
    28      createAllocations: true,
    29    });
    30  
    31    server.create('job', 'pack');
    32  
    33    ['system', 'sysbatch'].forEach(type => {
    34      // Job with 1 task group.
    35      const job1 = server.create('job', {
    36        status: 'running',
    37        datacenters: ['dc1', 'dc2'],
    38        type,
    39        resourceSpec: ['M: 256, C: 500'],
    40        createAllocations: false,
    41      });
    42      clients.forEach(c => {
    43        server.create('allocation', { jobId: job1.id, nodeId: c.id });
    44      });
    45  
    46      // Job with 2 task groups.
    47      const job2 = server.create('job', {
    48        status: 'running',
    49        datacenters: ['dc1'],
    50        type,
    51        resourceSpec: ['M: 256, C: 500', 'M: 256, C: 500'],
    52        createAllocations: false,
    53      });
    54      clients.forEach(c => {
    55        server.create('allocation', { jobId: job2.id, nodeId: c.id });
    56        server.create('allocation', { jobId: job2.id, nodeId: c.id });
    57      });
    58  
    59      // Job with 3 task groups.
    60      const job3 = server.create('job', {
    61        status: 'running',
    62        datacenters: ['dc1'],
    63        type,
    64        resourceSpec: ['M: 256, C: 500', 'M: 256, C: 500', 'M: 256, C: 500'],
    65        createAllocations: false,
    66      });
    67      clients.forEach(c => {
    68        server.create('allocation', { jobId: job3.id, nodeId: c.id });
    69        server.create('allocation', { jobId: job3.id, nodeId: c.id });
    70        server.create('allocation', { jobId: job3.id, nodeId: c.id });
    71      });
    72  
    73      // Job with client not scheduled.
    74      const jobNotScheduled = server.create('job', {
    75        status: 'running',
    76        datacenters: ['dc1'],
    77        type,
    78        resourceSpec: ['M: 256, C: 500'],
    79        createAllocations: false,
    80      });
    81      clients.forEach((c, i) => {
    82        if (i > clients.length - 3) return;
    83        server.create('allocation', { jobId: jobNotScheduled.id, nodeId: c.id });
    84      });
    85    });
    86  }