github.com/aminovpavel/nomad@v0.11.8/ui/app/adapters/job.js (about)

     1  import Watchable from './watchable';
     2  import addToPath from 'nomad-ui/utils/add-to-path';
     3  import WithNamespaceIDs from 'nomad-ui/mixins/with-namespace-ids';
     4  
     5  export default Watchable.extend(WithNamespaceIDs, {
     6    relationshipFallbackLinks: {
     7      summary: '/summary',
     8    },
     9  
    10    fetchRawDefinition(job) {
    11      const url = this.urlForFindRecord(job.get('id'), 'job');
    12      return this.ajax(url, 'GET');
    13    },
    14  
    15    forcePeriodic(job) {
    16      if (job.get('periodic')) {
    17        const url = addToPath(this.urlForFindRecord(job.get('id'), 'job'), '/periodic/force');
    18        return this.ajax(url, 'POST');
    19      }
    20    },
    21  
    22    stop(job) {
    23      const url = this.urlForFindRecord(job.get('id'), 'job');
    24      return this.ajax(url, 'DELETE');
    25    },
    26  
    27    parse(spec) {
    28      const url = addToPath(this.urlForFindAll('job'), '/parse');
    29      return this.ajax(url, 'POST', {
    30        data: {
    31          JobHCL: spec,
    32          Canonicalize: true,
    33        },
    34      });
    35    },
    36  
    37    plan(job) {
    38      const jobId = job.get('id') || job.get('_idBeforeSaving');
    39      const store = this.store;
    40      const url = addToPath(this.urlForFindRecord(jobId, 'job'), '/plan');
    41  
    42      return this.ajax(url, 'POST', {
    43        data: {
    44          Job: job.get('_newDefinitionJSON'),
    45          Diff: true,
    46        },
    47      }).then(json => {
    48        json.ID = jobId;
    49        store.pushPayload('job-plan', { jobPlans: [json] });
    50        return store.peekRecord('job-plan', jobId);
    51      });
    52    },
    53  
    54    // Running a job doesn't follow REST create semantics so it's easier to
    55    // treat it as an action.
    56    run(job) {
    57      return this.ajax(this.urlForCreateRecord('job'), 'POST', {
    58        data: {
    59          Job: job.get('_newDefinitionJSON'),
    60        },
    61      });
    62    },
    63  
    64    update(job) {
    65      const jobId = job.get('id') || job.get('_idBeforeSaving');
    66      return this.ajax(this.urlForUpdateRecord(jobId, 'job'), 'POST', {
    67        data: {
    68          Job: job.get('_newDefinitionJSON'),
    69        },
    70      });
    71    },
    72  });