From 9b7b465a66b1a5ba62f07e7275b2ad5b6c04db2b Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 17 Aug 2018 11:22:26 -0700 Subject: [PATCH] Show the scheduler dry-run output on the plan page --- ui/app/adapters/job.js | 3 +++ ui/app/components/placement-failure.js | 10 ++++++++++ ui/app/controllers/jobs/run.js | 8 ++++++-- ui/app/models/job-plan.js | 8 ++++++++ ui/app/serializers/job-plan.js | 12 ++++++++++++ ui/app/templates/components/placement-failure.hbs | 7 +++---- ui/app/templates/jobs/run.hbs | 14 +++++++++++++- ui/tests/integration/placement-failure-test.js | 1 + 8 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 ui/app/components/placement-failure.js create mode 100644 ui/app/models/job-plan.js create mode 100644 ui/app/serializers/job-plan.js diff --git a/ui/app/adapters/job.js b/ui/app/adapters/job.js index 2999988fa..a8c09ce09 100644 --- a/ui/app/adapters/job.js +++ b/ui/app/adapters/job.js @@ -77,6 +77,9 @@ export default Watchable.extend({ Job: job.get('_newDefinitionJSON'), Diff: true, }, + }).then(json => { + json.ID = job.get('id'); + this.get('store').pushPayload('job-plan', { jobPlans: [json] }); }); }, diff --git a/ui/app/components/placement-failure.js b/ui/app/components/placement-failure.js new file mode 100644 index 000000000..b8052235f --- /dev/null +++ b/ui/app/components/placement-failure.js @@ -0,0 +1,10 @@ +import Component from '@ember/component'; +import { or } from '@ember/object/computed'; + +export default Component.extend({ + // Either provide a taskGroup or a failedTGAlloc + taskGroup: null, + failedTGAlloc: null, + + placementFailures: or('taskGroup.placementFailures', 'failedTGAlloc'), +}); diff --git a/ui/app/controllers/jobs/run.js b/ui/app/controllers/jobs/run.js index 2c1eca1fe..79525e460 100644 --- a/ui/app/controllers/jobs/run.js +++ b/ui/app/controllers/jobs/run.js @@ -1,10 +1,13 @@ import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; import { task } from 'ember-concurrency'; import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; import localStorageProperty from 'nomad-ui/utils/properties/local-storage'; export default Controller.extend({ + store: service(), + parseError: null, planError: null, runError: null, @@ -30,8 +33,9 @@ export default Controller.extend({ } try { - const planOutput = yield this.get('model').plan(); - this.set('planOutput', planOutput.Diff); + yield this.get('model').plan(); + const plan = this.get('store').peekRecord('job-plan', this.get('model.id')); + this.set('planOutput', plan); } catch (err) { const error = messageFromAdapterError(err) || 'Could not plan job'; this.set('planError', error); diff --git a/ui/app/models/job-plan.js b/ui/app/models/job-plan.js new file mode 100644 index 000000000..8f9c10345 --- /dev/null +++ b/ui/app/models/job-plan.js @@ -0,0 +1,8 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import { fragmentArray } from 'ember-data-model-fragments/attributes'; + +export default Model.extend({ + diff: attr(), + failedTGAllocs: fragmentArray('placement-failure', { defaultValue: () => [] }), +}); diff --git a/ui/app/serializers/job-plan.js b/ui/app/serializers/job-plan.js new file mode 100644 index 000000000..028073438 --- /dev/null +++ b/ui/app/serializers/job-plan.js @@ -0,0 +1,12 @@ +import { get } from '@ember/object'; +import { assign } from '@ember/polyfills'; +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(typeHash, hash) { + hash.FailedTGAllocs = Object.keys(hash.FailedTGAllocs || {}).map(key => { + return assign({ Name: key }, get(hash, `FailedTGAllocs.${key}`) || {}); + }); + return this._super(...arguments); + }, +}); diff --git a/ui/app/templates/components/placement-failure.hbs b/ui/app/templates/components/placement-failure.hbs index 63f49a826..9cf7089ec 100644 --- a/ui/app/templates/components/placement-failure.hbs +++ b/ui/app/templates/components/placement-failure.hbs @@ -1,7 +1,7 @@ -{{#if taskGroup.placementFailures}} - {{#with taskGroup.placementFailures as |failures|}} +{{#if placementFailures}} + {{#with placementFailures as |failures|}}

- {{taskGroup.name}} + {{placementFailures.name}} {{inc failures.coalescedFailures}} unplaced

{{/with}} {{/if}} - diff --git a/ui/app/templates/jobs/run.hbs b/ui/app/templates/jobs/run.hbs index 44b979ec2..2e3856030 100644 --- a/ui/app/templates/jobs/run.hbs +++ b/ui/app/templates/jobs/run.hbs @@ -71,7 +71,19 @@
Job Plan
- {{job-diff data-test-plan-output diff=planOutput verbose=false}} + {{job-diff data-test-plan-output diff=planOutput.diff verbose=false}} +
+
+
+
Scheduler dry-run
+
+ {{#if planOutput.failedTGAllocs}} + {{#each planOutput.failedTGAllocs as |placementFailure|}} + {{placement-failure failedTGAlloc=placementFailure}} + {{/each}} + {{else}} + All tasks successfully allocated. + {{/if}}
diff --git a/ui/tests/integration/placement-failure-test.js b/ui/tests/integration/placement-failure-test.js index b5bf79800..97d8b688e 100644 --- a/ui/tests/integration/placement-failure-test.js +++ b/ui/tests/integration/placement-failure-test.js @@ -108,6 +108,7 @@ function createFixture(obj = {}, name = 'Placement Failure') { name: name, placementFailures: assign( { + name: name, coalescedFailures: 10, nodesEvaluated: 0, nodesAvailable: {