github.com/hernad/nomad@v1.6.112/ui/mirage/scenarios/sysbatch.js (about)

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