github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/routes/jobs/job/task-group.js (about)

     1  import Route from '@ember/routing/route';
     2  import { collect } from '@ember/object/computed';
     3  import EmberError from '@ember/error';
     4  import { resolve, all } from 'rsvp';
     5  import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
     6  import WithWatchers from 'nomad-ui/mixins/with-watchers';
     7  import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
     8  import notifyError from 'nomad-ui/utils/notify-error';
     9  
    10  export default class TaskGroupRoute extends Route.extend(WithWatchers) {
    11    breadcrumbs(model) {
    12      if (!model) return [];
    13      return [
    14        {
    15          label: model.get('name'),
    16          args: [
    17            'jobs.job.task-group',
    18            model.get('job'),
    19            model.get('name'),
    20            qpBuilder({ jobNamespace: model.get('job.namespace.name') || 'default' }),
    21          ],
    22        },
    23      ];
    24    }
    25  
    26    model({ name }) {
    27      const job = this.modelFor('jobs.job');
    28  
    29      // If there is no job, then there is no task group.
    30      // Let the job route handle the 404.
    31      if (!job) return;
    32  
    33      // If the job is a partial (from the list request) it won't have task
    34      // groups. Reload the job to ensure task groups are present.
    35      const reload = job.get('isPartial') ? job.reload() : resolve();
    36      return reload
    37        .then(() => {
    38          const taskGroup = job.get('taskGroups').findBy('name', name);
    39          if (!taskGroup) {
    40            const err = new EmberError(`Task group ${name} for job ${job.get('name')} not found`);
    41            err.code = '404';
    42            throw err;
    43          }
    44  
    45          // Refresh job allocations before-hand (so page sort works on load)
    46          return all([job.hasMany('allocations').reload(), job.get('scaleState')]).then(
    47            () => taskGroup
    48          );
    49        })
    50        .catch(notifyError(this));
    51    }
    52  
    53    startWatchers(controller, model) {
    54      if (model) {
    55        const job = model.get('job');
    56        controller.set('watchers', {
    57          job: this.watchJob.perform(job),
    58          summary: this.watchSummary.perform(job.get('summary')),
    59          scale: this.watchScale.perform(job.get('scaleState')),
    60          allocations: this.watchAllocations.perform(job),
    61          latestDeployment: job.get('supportsDeployments') && this.watchLatestDeployment.perform(job),
    62        });
    63      }
    64    }
    65  
    66    @watchRecord('job') watchJob;
    67    @watchRecord('job-summary') watchSummary;
    68    @watchRecord('job-scale') watchScale;
    69    @watchRelationship('allocations') watchAllocations;
    70    @watchRelationship('latestDeployment') watchLatestDeployment;
    71  
    72    @collect('watchJob', 'watchSummary', 'watchScale', 'watchAllocations', 'watchLatestDeployment')
    73    watchers;
    74  }