open-nomad/ui/mirage/factories/task.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-09-26 18:47:07 +00:00
import { Factory } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
2017-09-19 14:47:10 +00:00
import { generateResources } from '../common';
import { dasherize } from '@ember/string';
Job Services: fixtures and acceptance tests (#14319) * Added to subnav and basic table implemented * Existing services become service fragments, and services tab aggregated beneath job route * Index page within jobs/job/services * Watchable services * Lintfixes * Links to clients and individual services set up * Child service route * Keyboard shortcuts on service page * Model that shows consul services as well, plus level and provider cols * lintfix * Level as query param * Watch job for service name changes too * Group level service fixtures established * Progress at task level and job-linked services * Task and group services on update * Fixture side-effect cleanup * Basic acceptance tests for job services * Testmodel cleanup * Disabled mirage logging * New cluster type specifically for services * Without explicit job-model binding * Trying to isolate a tostring error * Account for new tab in keyboardnav * More test isolation attempts * Remove skipped tests and link task to parent group by id ui: add service health viz to table (#14369) * ui: add service-status-bar * test: service-status-bar * refact: update component api for new data struct * ui: format service health struct * ui: add service health viz to table * temp: add placeholder to remind conditional watcher * test: write tests for transformation algorithm * refact: update transformation algo * ui: conditionally long poll checks endpoint * refact: add conditional logic for nomad provider refact: update service-fragment model to include owner info ui: differentiate between task and group-level in derived state comp test: add test to document behavior refact: update tests for api change refact: update integration test for API change chore: remove unsused vars chore: elvis operator to protect mirage refact: create refId instead of internalModel refact: update algo refact: update conditional template logic refact: update test for api change: chore: cant use if and not in hbs conditional
2022-08-29 18:04:55 +00:00
import { pickOne } from '../utils';
2017-09-19 14:47:10 +00:00
const DRIVERS = ['docker', 'java', 'rkt', 'qemu', 'exec', 'raw_exec'];
2017-09-19 14:47:10 +00:00
export default Factory.extend({
createRecommendations: false,
Job Services: fixtures and acceptance tests (#14319) * Added to subnav and basic table implemented * Existing services become service fragments, and services tab aggregated beneath job route * Index page within jobs/job/services * Watchable services * Lintfixes * Links to clients and individual services set up * Child service route * Keyboard shortcuts on service page * Model that shows consul services as well, plus level and provider cols * lintfix * Level as query param * Watch job for service name changes too * Group level service fixtures established * Progress at task level and job-linked services * Task and group services on update * Fixture side-effect cleanup * Basic acceptance tests for job services * Testmodel cleanup * Disabled mirage logging * New cluster type specifically for services * Without explicit job-model binding * Trying to isolate a tostring error * Account for new tab in keyboardnav * More test isolation attempts * Remove skipped tests and link task to parent group by id ui: add service health viz to table (#14369) * ui: add service-status-bar * test: service-status-bar * refact: update component api for new data struct * ui: format service health struct * ui: add service health viz to table * temp: add placeholder to remind conditional watcher * test: write tests for transformation algorithm * refact: update transformation algo * ui: conditionally long poll checks endpoint * refact: add conditional logic for nomad provider refact: update service-fragment model to include owner info ui: differentiate between task and group-level in derived state comp test: add test to document behavior refact: update tests for api change refact: update integration test for API change chore: remove unsused vars chore: elvis operator to protect mirage refact: create refId instead of internalModel refact: update algo refact: update conditional template logic refact: update test for api change: chore: cant use if and not in hbs conditional
2022-08-29 18:04:55 +00:00
withServices: false,
2017-09-19 14:47:10 +00:00
// Hidden property used to compute the Summary hash
groupNames: [],
// Set in the TaskGroup factory
volumeMounts: [],
2017-09-19 14:47:10 +00:00
JobID: '',
name: (id) => `task-${dasherize(faker.hacker.noun())}-${id}`,
driver: () => faker.helpers.randomize(DRIVERS),
2017-09-19 14:47:10 +00:00
originalResources: generateResources,
resources: function () {
// Generate resources the usual way, but transform to the old
// shape because that's what the job spec uses.
const resources = this.originalResources;
return {
CPU: resources.Cpu.CpuShares,
MemoryMB: resources.Memory.MemoryMB,
MemoryMaxMB: resources.Memory.MemoryMaxMB,
DiskMB: resources.Disk.DiskMB,
};
},
Lifecycle: (i) => {
const cycle = i % 6;
if (cycle === 0) {
return null;
} else if (cycle === 1) {
return { Hook: 'prestart', Sidecar: false };
} else if (cycle === 2) {
return { Hook: 'prestart', Sidecar: true };
} else if (cycle === 3) {
return { Hook: 'poststart', Sidecar: false };
} else if (cycle === 4) {
return { Hook: 'poststart', Sidecar: true };
} else if (cycle === 5) {
return { Hook: 'poststop' };
}
},
afterCreate(task, server) {
if (task.createRecommendations) {
const recommendations = [];
if (faker.random.number(10) >= 1) {
recommendations.push(
server.create('recommendation', { task, resource: 'CPU' })
);
}
if (faker.random.number(10) >= 1) {
recommendations.push(
server.create('recommendation', { task, resource: 'MemoryMB' })
);
}
task.save({ recommendationIds: recommendations.mapBy('id') });
}
Job Services: fixtures and acceptance tests (#14319) * Added to subnav and basic table implemented * Existing services become service fragments, and services tab aggregated beneath job route * Index page within jobs/job/services * Watchable services * Lintfixes * Links to clients and individual services set up * Child service route * Keyboard shortcuts on service page * Model that shows consul services as well, plus level and provider cols * lintfix * Level as query param * Watch job for service name changes too * Group level service fixtures established * Progress at task level and job-linked services * Task and group services on update * Fixture side-effect cleanup * Basic acceptance tests for job services * Testmodel cleanup * Disabled mirage logging * New cluster type specifically for services * Without explicit job-model binding * Trying to isolate a tostring error * Account for new tab in keyboardnav * More test isolation attempts * Remove skipped tests and link task to parent group by id ui: add service health viz to table (#14369) * ui: add service-status-bar * test: service-status-bar * refact: update component api for new data struct * ui: format service health struct * ui: add service health viz to table * temp: add placeholder to remind conditional watcher * test: write tests for transformation algorithm * refact: update transformation algo * ui: conditionally long poll checks endpoint * refact: add conditional logic for nomad provider refact: update service-fragment model to include owner info ui: differentiate between task and group-level in derived state comp test: add test to document behavior refact: update tests for api change refact: update integration test for API change chore: remove unsused vars chore: elvis operator to protect mirage refact: create refId instead of internalModel refact: update algo refact: update conditional template logic refact: update test for api change: chore: cant use if and not in hbs conditional
2022-08-29 18:04:55 +00:00
if (task.withServices) {
const services = server.createList('service-fragment', 1, {
provider: 'nomad',
taskName: task.name,
Job Services: fixtures and acceptance tests (#14319) * Added to subnav and basic table implemented * Existing services become service fragments, and services tab aggregated beneath job route * Index page within jobs/job/services * Watchable services * Lintfixes * Links to clients and individual services set up * Child service route * Keyboard shortcuts on service page * Model that shows consul services as well, plus level and provider cols * lintfix * Level as query param * Watch job for service name changes too * Group level service fixtures established * Progress at task level and job-linked services * Task and group services on update * Fixture side-effect cleanup * Basic acceptance tests for job services * Testmodel cleanup * Disabled mirage logging * New cluster type specifically for services * Without explicit job-model binding * Trying to isolate a tostring error * Account for new tab in keyboardnav * More test isolation attempts * Remove skipped tests and link task to parent group by id ui: add service health viz to table (#14369) * ui: add service-status-bar * test: service-status-bar * refact: update component api for new data struct * ui: format service health struct * ui: add service health viz to table * temp: add placeholder to remind conditional watcher * test: write tests for transformation algorithm * refact: update transformation algo * ui: conditionally long poll checks endpoint * refact: add conditional logic for nomad provider refact: update service-fragment model to include owner info ui: differentiate between task and group-level in derived state comp test: add test to document behavior refact: update tests for api change refact: update integration test for API change chore: remove unsused vars chore: elvis operator to protect mirage refact: create refId instead of internalModel refact: update algo refact: update conditional template logic refact: update test for api change: chore: cant use if and not in hbs conditional
2022-08-29 18:04:55 +00:00
});
services.push(
server.create('service-fragment', {
provider: 'consul',
taskName: task.name,
Job Services: fixtures and acceptance tests (#14319) * Added to subnav and basic table implemented * Existing services become service fragments, and services tab aggregated beneath job route * Index page within jobs/job/services * Watchable services * Lintfixes * Links to clients and individual services set up * Child service route * Keyboard shortcuts on service page * Model that shows consul services as well, plus level and provider cols * lintfix * Level as query param * Watch job for service name changes too * Group level service fixtures established * Progress at task level and job-linked services * Task and group services on update * Fixture side-effect cleanup * Basic acceptance tests for job services * Testmodel cleanup * Disabled mirage logging * New cluster type specifically for services * Without explicit job-model binding * Trying to isolate a tostring error * Account for new tab in keyboardnav * More test isolation attempts * Remove skipped tests and link task to parent group by id ui: add service health viz to table (#14369) * ui: add service-status-bar * test: service-status-bar * refact: update component api for new data struct * ui: format service health struct * ui: add service health viz to table * temp: add placeholder to remind conditional watcher * test: write tests for transformation algorithm * refact: update transformation algo * ui: conditionally long poll checks endpoint * refact: add conditional logic for nomad provider refact: update service-fragment model to include owner info ui: differentiate between task and group-level in derived state comp test: add test to document behavior refact: update tests for api change refact: update integration test for API change chore: remove unsused vars chore: elvis operator to protect mirage refact: create refId instead of internalModel refact: update algo refact: update conditional template logic refact: update test for api change: chore: cant use if and not in hbs conditional
2022-08-29 18:04:55 +00:00
})
);
services.forEach((fragment) => {
server.createList('service', 5, {
serviceName: fragment.name,
});
});
task.update({ services });
}
},
2017-09-19 14:47:10 +00:00
});