open-nomad/ui/mirage/factories/job.js
Michael Lange f747cc79e4 Revert "UI Placement failures""
This reverts commits
141ecd8d9170f56c8302b5c776532e6d287a40e3
d2d838c2de08aac716a9431d9720b5c12bb19ba1
8099db433641429816e8479c6d23116269f744c0
86262b3ceff607627a9c9e0e25eb81b9b5ee739c
eb4104ec528982e0ee6ae9a05fb0460e53139f3f
0e0e23e238017815bdb6dcfbc056275b3deaacca
6d45658d77fb4c40760a63cced71b74757356e48
b52a8176e85b9c6f13ec012f7fce2ec3df1c8751
2017-11-29 20:03:39 -08:00

89 lines
2.4 KiB
JavaScript

import { Factory, faker } from 'ember-cli-mirage';
import { provide, provider, pickOne } from '../utils';
import { DATACENTERS } from '../common';
const JOB_PREFIXES = provide(5, faker.hacker.abbreviation);
const JOB_TYPES = ['service', 'batch', 'system'];
const JOB_STATUSES = ['pending', 'running', 'dead'];
export default Factory.extend({
id: i => `job-${i}`,
name: i => `${faker.list.random(...JOB_PREFIXES)()}-${faker.hacker.noun()}-${i}`,
groupsCount: () => faker.random.number({ min: 1, max: 5 }),
region: () => 'global',
type: faker.list.random(...JOB_TYPES),
priority: () => faker.random.number(200),
all_at_once: faker.random.boolean,
status: faker.list.random(...JOB_STATUSES),
datacenters: provider(
() => faker.random.number({ min: 1, max: 4 }),
faker.list.random(...DATACENTERS)
),
periodic: () => Math.random() > 0.5,
parameterized() {
return !this.periodic;
},
createIndex: i => i,
modifyIndex: () => faker.random.number({ min: 10, max: 2000 }),
// Directive used to control sub-resources
// When false, no allocations are made
createAllocations: true,
// When true, deployments for the job will never have a 'running' status
noActiveDeployment: false,
// When true, deployments for the job will always have a 'running' status
activeDeployment: false,
afterCreate(job, server) {
const groups = server.createList('task-group', job.groupsCount, {
job,
createAllocations: job.createAllocations,
});
job.update({
taskGroupIds: groups.mapBy('id'),
task_group_ids: groups.mapBy('id'),
});
if (!job.namespaceId) {
const namespace = server.db.namespaces.length ? pickOne(server.db.namespaces).id : null;
job.update({
namespace,
namespaceId: namespace,
});
} else {
job.update({
namespace: job.namespaceId,
});
}
const jobSummary = server.create('job-summary', {
groupNames: groups.mapBy('name'),
job,
});
job.update({
jobSummaryId: jobSummary.id,
job_summary_id: jobSummary.id,
});
Array(faker.random.number({ min: 1, max: 10 }))
.fill(null)
.map((_, index) => {
return server.create('job-version', {
job,
version: index,
noActiveDeployment: job.noActiveDeployment,
activeDeployment: job.activeDeployment,
});
});
},
});