Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Polling Step 2 - Polling on all views #3938

Merged
merged 14 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ui/app/adapters/allocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Watchable from './watchable';

export default Watchable.extend();
4 changes: 2 additions & 2 deletions ui/app/adapters/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ApplicationAdapter from './application';
import Watchable from './watchable';

export default ApplicationAdapter.extend({
export default Watchable.extend({
findAllocations(node) {
const url = `${this.buildURL('node', node.get('id'), node, 'findRecord')}/allocations`;
return this.ajax(url, 'GET').then(allocs => {
Expand Down
21 changes: 12 additions & 9 deletions ui/app/adapters/watchable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { get, computed } from '@ember/object';
import { assign } from '@ember/polyfills';
import { makeArray } from '@ember/array';
import { inject as service } from '@ember/service';
import queryString from 'npm:query-string';
import ApplicationAdapter from './application';
Expand Down Expand Up @@ -37,15 +36,11 @@ export default ApplicationAdapter.extend({

if (get(snapshotRecordArray || {}, 'adapterOptions.watch')) {
params.index = this.get('watchList').getIndexFor(url);
this.cancelFindAll(type.modelName);
}

return this.ajax(url, 'GET', {
data: params,
}).catch(error => {
if (error instanceof AbortError) {
return [];
}
throw error;
});
},

Expand All @@ -55,6 +50,7 @@ export default ApplicationAdapter.extend({

if (get(snapshot || {}, 'adapterOptions.watch')) {
params.index = this.get('watchList').getIndexFor(url);
this.cancelFindRecord(type.modelName, id);
}

return this.ajax(url, 'GET', {
Expand All @@ -79,6 +75,7 @@ export default ApplicationAdapter.extend({

if (watch) {
params.index = this.get('watchList').getIndexFor(url);
this.cancelReloadRelationship(model, relationshipName);
}

if (url.includes('?')) {
Expand All @@ -89,9 +86,15 @@ export default ApplicationAdapter.extend({
data: params,
}).then(
json => {
this.get('store').pushPayload(relationship.type, {
[relationship.type]: makeArray(json),
});
const store = this.get('store');
const normalizeMethod =
relationship.kind === 'belongsTo'
? 'normalizeFindBelongsToResponse'
: 'normalizeFindHasManyResponse';
const serializer = store.serializerFor(relationship.type);
const modelClass = store.modelFor(relationship.type);
const normalizedData = serializer[normalizeMethod](store, modelClass, json);
store.push(normalizedData);
},
error => {
if (error instanceof AbortError) {
Expand Down
15 changes: 14 additions & 1 deletion ui/app/components/client-node-row.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { lazyClick } from '../helpers/lazy-click';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';

export default Component.extend({
store: service(),

tagName: 'tr',
classNames: ['client-node-row', 'is-interactive'],

Expand All @@ -17,7 +21,16 @@ export default Component.extend({
// Reload the node in order to get detail information
const node = this.get('node');
if (node) {
node.reload();
node.reload().then(() => {
this.get('watch').perform(node, 100);
});
}
},

willDestroy() {
this.get('watch').cancelAll();
this._super(...arguments);
},

watch: watchRelationship('allocations'),
});
4 changes: 3 additions & 1 deletion ui/app/components/job-versions-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export default Component.extend({
verbose: true,

annotatedVersions: computed('versions.[]', function() {
const versions = this.get('versions');
const versions = this.get('versions')
.sortBy('submitTime')
.reverse();
return versions.map((version, index) => {
const meta = {};

Expand Down
16 changes: 16 additions & 0 deletions ui/app/mixins/with-watchers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Mixin from '@ember/object/mixin';
import { computed } from '@ember/object';
import { assert } from '@ember/debug';

export default Mixin.create({
watchers: computed(() => []),

actions: {
willTransition() {
this.get('watchers').forEach(watcher => {
assert('Watchers must be Ember Concurrency Tasks.', !!watcher.cancelAll);
watcher.cancelAll();
});
},
},
});
14 changes: 13 additions & 1 deletion ui/app/routes/allocations/allocation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import Route from '@ember/routing/route';
import WithModelErrorHandling from 'nomad-ui/mixins/with-model-error-handling';
import { collect } from '@ember/object/computed';
import { watchRecord } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend(WithModelErrorHandling);
export default Route.extend(WithModelErrorHandling, WithWatchers, {
setupController(controller, model) {
controller.set('watcher', this.get('watch').perform(model));
return this._super(...arguments);
},

watch: watchRecord('allocation'),

watchers: collect('watch'),
});
16 changes: 15 additions & 1 deletion ui/app/routes/clients/client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import notifyError from 'nomad-ui/utils/notify-error';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend({
export default Route.extend(WithWatchers, {
store: service(),

model() {
Expand All @@ -15,4 +18,15 @@ export default Route.extend({
}
return model && model.get('allocations');
},

setupController(controller, model) {
controller.set('watchModel', this.get('watch').perform(model));
controller.set('watchAllocations', this.get('watchAllocations').perform(model));
return this._super(...arguments);
},

watch: watchRecord('node'),
watchAllocations: watchRelationship('allocations'),

watchers: collect('watch', 'watchAllocations'),
});
14 changes: 14 additions & 0 deletions ui/app/routes/clients/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchAll } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend(WithWatchers, {
setupController(controller) {
controller.set('watcher', this.get('watch').perform());
return this._super(...arguments);
},

watch: watchAll('node'),
watchers: collect('watch'),
});
10 changes: 0 additions & 10 deletions ui/app/routes/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Route from '@ember/routing/route';
import { run } from '@ember/runloop';
import WithForbiddenState from 'nomad-ui/mixins/with-forbidden-state';
import notifyForbidden from 'nomad-ui/utils/notify-forbidden';
import { watchAll } from 'nomad-ui/utils/properties/watch';

export default Route.extend(WithForbiddenState, {
system: service(),
Expand Down Expand Up @@ -36,18 +35,9 @@ export default Route.extend(WithForbiddenState, {

setupController(controller) {
this.syncToController(controller);

controller.set('modelWatch', this.get('watch').perform());
return this._super(...arguments);
},

deactivate() {
this.get('watch').cancelAll();
this._super(...arguments);
},

watch: watchAll('job'),

actions: {
refreshRoute() {
this.refresh();
Expand Down
13 changes: 12 additions & 1 deletion ui/app/routes/jobs/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchAll } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend(WithWatchers, {
setupController(controller) {
controller.set('modelWatch', this.get('watch').perform());
return this._super(...arguments);
},

watch: watchAll('job'),
watchers: collect('watch'),

export default Route.extend({
actions: {
refreshRoute() {
return true;
Expand Down
28 changes: 0 additions & 28 deletions ui/app/routes/jobs/job.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { inject as service } from '@ember/service';
import { collect } from '@ember/object/computed';
import Route from '@ember/routing/route';
import RSVP from 'rsvp';
import notifyError from 'nomad-ui/utils/notify-error';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';

export default Route.extend({
store: service(),
token: service(),
watchList: service(),

serialize(model) {
return { job_name: model.get('plainId') };
Expand All @@ -25,29 +22,4 @@ export default Route.extend({
})
.catch(notifyError(this));
},

setupController(controller, model) {
controller.set('watchers', {
model: this.get('watch').perform(model),
summary: this.get('watchSummary').perform(model),
evaluations: this.get('watchEvaluations').perform(model),
deployments: this.get('watchDeployments').perform(model),
});

return this._super(...arguments);
},

deactivate() {
this.get('allWatchers').forEach(watcher => {
watcher.cancelAll();
});
this._super(...arguments);
},

watch: watchRecord('job'),
watchSummary: watchRelationship('summary'),
watchEvaluations: watchRelationship('evaluations'),
watchDeployments: watchRelationship('deployments'),

allWatchers: collect('watch', 'watchSummary', 'watchEvaluations', 'watchDeployments'),
});
16 changes: 15 additions & 1 deletion ui/app/routes/jobs/job/deployments.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import Route from '@ember/routing/route';
import RSVP from 'rsvp';
import { collect } from '@ember/object/computed';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend({
export default Route.extend(WithWatchers, {
model() {
const job = this.modelFor('jobs.job');
return RSVP.all([job.get('deployments'), job.get('versions')]).then(() => job);
},

setupController(controller, model) {
controller.set('watchDeployments', this.get('watchDeployments').perform(model));
controller.set('watchVersions', this.get('watchVersions').perform(model));
return this._super(...arguments);
},

watchDeployments: watchRelationship('deployments'),
watchVersions: watchRelationship('versions'),

watchers: collect('watchDeployments', 'watchVersions'),
});
24 changes: 24 additions & 0 deletions ui/app/routes/jobs/job/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend(WithWatchers, {
setupController(controller, model) {
controller.set('watchers', {
model: this.get('watch').perform(model),
summary: this.get('watchSummary').perform(model),
evaluations: this.get('watchEvaluations').perform(model),
deployments: this.get('watchDeployments').perform(model),
});

return this._super(...arguments);
},

watch: watchRecord('job'),
watchSummary: watchRelationship('summary'),
watchEvaluations: watchRelationship('evaluations'),
watchDeployments: watchRelationship('deployments'),

watchers: collect('watch', 'watchSummary', 'watchEvaluations', 'watchDeployments'),
});
21 changes: 20 additions & 1 deletion ui/app/routes/jobs/job/task-group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend({
export default Route.extend(WithWatchers, {
model({ name }) {
// If the job is a partial (from the list request) it won't have task
// groups. Reload the job to ensure task groups are present.
Expand All @@ -15,4 +18,20 @@ export default Route.extend({
});
});
},

setupController(controller, model) {
const job = model.get('job');
controller.set('watchers', {
job: this.get('watchJob').perform(job),
summary: this.get('watchSummary').perform(job),
allocations: this.get('watchAllocations').perform(job),
});
return this._super(...arguments);
},

watchJob: watchRecord('job'),
watchSummary: watchRelationship('summary'),
watchAllocations: watchRelationship('allocations'),

watchers: collect('watchJob', 'watchSummary', 'watchAllocations'),
});
13 changes: 12 additions & 1 deletion ui/app/routes/jobs/job/versions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default Route.extend({
export default Route.extend(WithWatchers, {
model() {
const job = this.modelFor('jobs.job');
return job.get('versions').then(() => job);
},

setupController(controller, model) {
controller.set('watcher', this.get('watchVersions').perform(model));
return this._super(...arguments);
},

watchVersions: watchRelationship('versions'),
watchers: collect('watchVersions'),
});
1 change: 1 addition & 0 deletions ui/app/serializers/job-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default ApplicationSerializer.extend({
assign({}, version, {
Diff: hash.Diffs && hash.Diffs[index],
ID: `${version.ID}-${version.Version}`,
JobID: JSON.stringify([version.ID, version.Namespace || 'default']),
SubmitTime: Math.floor(version.SubmitTime / 1000000),
SubmitTimeNanos: version.SubmitTime % 1000000,
})
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-deployments-stream.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#each annotatedDeployments as |record|}}
{{#each annotatedDeployments key="deployment.id" as |record|}}
{{#if record.meta.showDate}}
<li data-test-deployment-time class="timeline-note">
{{#if record.deployment.version.submitTime}}
Expand Down
Loading