github.com/aminovpavel/nomad@v0.11.8/ui/mirage/factories/csi-plugin.js (about)

     1  import { Factory } from 'ember-cli-mirage';
     2  import faker from 'nomad-ui/mirage/faker';
     3  import { STORAGE_PROVIDERS } from '../common';
     4  
     5  export default Factory.extend({
     6    id: () => faker.random.uuid(),
     7  
     8    // Topologies is currently unused by the UI. This should
     9    // eventually become dynamic.
    10    topologies: () => [{ foo: 'bar' }],
    11  
    12    provider: faker.helpers.randomize(STORAGE_PROVIDERS),
    13    version: '1.0.1',
    14  
    15    controllerRequired: faker.random.boolean,
    16  
    17    controllersHealthy() {
    18      if (!this.controllerRequired) return 0;
    19      return faker.random.number(3);
    20    },
    21    controllersExpected() {
    22      // This property must be read before the conditional
    23      // or Mirage will incorrectly sort dependent properties.
    24      const healthy = this.controllersHealthy;
    25      if (!this.controllerRequired) return 0;
    26      return healthy + faker.random.number({ min: 1, max: 2 });
    27    },
    28  
    29    nodesHealthy: () => faker.random.number(3),
    30    nodesExpected() {
    31      return this.nodesHealthy + faker.random.number({ min: 1, max: 2 });
    32    },
    33  
    34    // Internal property to determine whether or not this plugin
    35    // Should create one or two Jobs to represent Node and
    36    // Controller plugins.
    37    isMonolith() {
    38      if (!this.controllerRequired) return false;
    39      return faker.random.boolean;
    40    },
    41  
    42    // When false, the plugin will not make its own volumes
    43    createVolumes: true,
    44  
    45    // When true, doesn't create any resources, state, or events for associated allocations
    46    shallow: false,
    47  
    48    afterCreate(plugin, server) {
    49      let storageNodes;
    50      let storageControllers;
    51  
    52      if (plugin.isMonolith) {
    53        const pluginJob = server.create('job', { type: 'service', createAllocations: false });
    54        const count = plugin.nodesExpected;
    55        storageNodes = server.createList('storage-node', count, {
    56          job: pluginJob,
    57          shallow: plugin.shallow,
    58        });
    59        storageControllers = server.createList('storage-controller', count, {
    60          job: pluginJob,
    61          shallow: plugin.shallow,
    62        });
    63      } else {
    64        const controllerJob =
    65          plugin.controllerRequired &&
    66          server.create('job', {
    67            type: 'service',
    68            createAllocations: false,
    69            shallow: plugin.shallow,
    70          });
    71        const nodeJob = server.create('job', {
    72          type: 'service',
    73          createAllocations: false,
    74          shallow: plugin.shallow,
    75        });
    76        storageNodes = server.createList('storage-node', plugin.nodesExpected, {
    77          job: nodeJob,
    78          shallow: plugin.shallow,
    79        });
    80        storageControllers =
    81          plugin.controllerRequired &&
    82          server.createList('storage-controller', plugin.controllersExpected, {
    83            job: controllerJob,
    84            shallow: plugin.shallow,
    85          });
    86      }
    87  
    88      plugin.update({
    89        controllers: storageControllers,
    90        nodes: storageNodes,
    91      });
    92  
    93      if (plugin.createVolumes) {
    94        server.createList('csi-volume', faker.random.number({ min: 1, max: 5 }), {
    95          plugin,
    96          provider: plugin.provider,
    97        });
    98      }
    99    },
   100  });