github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/adapters/job.js (about) 1 import WatchableNamespaceIDs from './watchable-namespace-ids'; 2 import addToPath from 'nomad-ui/utils/add-to-path'; 3 4 export default class JobAdapter extends WatchableNamespaceIDs { 5 relationshipFallbackLinks = { 6 summary: '/summary', 7 }; 8 9 fetchRawDefinition(job) { 10 const url = this.urlForFindRecord(job.get('id'), 'job'); 11 return this.ajax(url, 'GET'); 12 } 13 14 forcePeriodic(job) { 15 if (job.get('periodic')) { 16 const url = addToPath(this.urlForFindRecord(job.get('id'), 'job'), '/periodic/force'); 17 return this.ajax(url, 'POST'); 18 } 19 } 20 21 stop(job) { 22 const url = this.urlForFindRecord(job.get('id'), 'job'); 23 return this.ajax(url, 'DELETE'); 24 } 25 26 parse(spec) { 27 const url = addToPath(this.urlForFindAll('job'), '/parse'); 28 return this.ajax(url, 'POST', { 29 data: { 30 JobHCL: spec, 31 Canonicalize: true, 32 }, 33 }); 34 } 35 36 plan(job) { 37 const jobId = job.get('id') || job.get('_idBeforeSaving'); 38 const store = this.store; 39 const url = addToPath(this.urlForFindRecord(jobId, 'job'), '/plan'); 40 41 return this.ajax(url, 'POST', { 42 data: { 43 Job: job.get('_newDefinitionJSON'), 44 Diff: true, 45 }, 46 }).then(json => { 47 json.ID = jobId; 48 store.pushPayload('job-plan', { jobPlans: [json] }); 49 return store.peekRecord('job-plan', jobId); 50 }); 51 } 52 53 // Running a job doesn't follow REST create semantics so it's easier to 54 // treat it as an action. 55 run(job) { 56 return this.ajax(this.urlForCreateRecord('job'), 'POST', { 57 data: { 58 Job: job.get('_newDefinitionJSON'), 59 }, 60 }); 61 } 62 63 update(job) { 64 const jobId = job.get('id') || job.get('_idBeforeSaving'); 65 return this.ajax(this.urlForUpdateRecord(jobId, 'job'), 'POST', { 66 data: { 67 Job: job.get('_newDefinitionJSON'), 68 }, 69 }); 70 } 71 72 scale(job, group, count, message) { 73 const url = addToPath(this.urlForFindRecord(job.get('id'), 'job'), '/scale'); 74 return this.ajax(url, 'POST', { 75 data: { 76 Count: count, 77 Message: message, 78 Target: { 79 Group: group, 80 }, 81 Meta: { 82 Source: 'nomad-ui', 83 }, 84 }, 85 }); 86 } 87 }