github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/routes/allocations/allocation.js (about) 1 import Route from '@ember/routing/route'; 2 import { inject as service } from '@ember/service'; 3 import { collect } from '@ember/object/computed'; 4 import { 5 watchRecord, 6 watchNonStoreRecords, 7 } from 'nomad-ui/utils/properties/watch'; 8 import WithWatchers from 'nomad-ui/mixins/with-watchers'; 9 import notifyError from 'nomad-ui/utils/notify-error'; 10 export default class AllocationRoute extends Route.extend(WithWatchers) { 11 @service store; 12 13 startWatchers(controller, model) { 14 if (model) { 15 controller.set('watcher', this.watch.perform(model)); 16 17 const anyGroupServicesAreNomad = !!model.taskGroup?.services?.filterBy( 18 'provider', 19 'nomad' 20 ).length; 21 22 const anyTaskServicesAreNomad = model.states 23 .mapBy('task.services') 24 .compact() 25 .map((fragmentClass) => fragmentClass.mapBy('provider')) 26 .flat() 27 .any((provider) => provider === 'nomad'); 28 29 // Conditionally Long Poll /checks endpoint if alloc has nomad services 30 if (anyGroupServicesAreNomad || anyTaskServicesAreNomad) { 31 controller.set( 32 'watchHealthChecks', 33 this.watchHealthChecks.perform(model, 'getServiceHealth', 2000) 34 ); 35 } 36 } 37 } 38 39 model() { 40 // Preload the job for the allocation since it's required for the breadcrumb trail 41 return super 42 .model(...arguments) 43 .then((allocation) => { 44 const jobId = allocation.belongsTo('job').id(); 45 return this.store 46 .findRecord('job', jobId) 47 .then(() => this.store.findAll('namespace')) // namespaces belong to a job and are an asynchronous relationship so we can peak them later on 48 .then(() => allocation); 49 }) 50 .catch(notifyError(this)); 51 } 52 53 @watchRecord('allocation') watch; 54 @watchNonStoreRecords('allocation') watchHealthChecks; 55 56 @collect('watch', 'watchHealthChecks') watchers; 57 }