mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Data modeling for job scale and scale events
This commit is contained in:
3
ui/app/adapters/job-scale.js
Normal file
3
ui/app/adapters/job-scale.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import WatchableNamespaceIDs from './watchable-namespace-ids';
|
||||
|
||||
export default class JobScaleAdapter extends WatchableNamespaceIDs {}
|
||||
11
ui/app/models/job-scale.js
Normal file
11
ui/app/models/job-scale.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import Model from 'ember-data/model';
|
||||
import { belongsTo } from 'ember-data/relationships';
|
||||
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
@classic
|
||||
export default class JobSummary extends Model {
|
||||
@belongsTo('job') job;
|
||||
|
||||
@fragmentArray('task-group-scale') taskGroupScales;
|
||||
}
|
||||
@@ -119,6 +119,7 @@ export default class Job extends Model {
|
||||
@hasMany('deployments') deployments;
|
||||
@hasMany('evaluations') evaluations;
|
||||
@belongsTo('namespace') namespace;
|
||||
@belongsTo('job-scale') scaleState;
|
||||
|
||||
@computed('taskGroups.@each.drivers')
|
||||
get drivers() {
|
||||
|
||||
18
ui/app/models/scale-event.js
Normal file
18
ui/app/models/scale-event.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import Fragment from 'ember-data-model-fragments/fragment';
|
||||
import attr from 'ember-data/attr';
|
||||
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
|
||||
|
||||
export default class ScaleEvent extends Fragment {
|
||||
@fragmentOwner() taskGroupScale;
|
||||
|
||||
@attr('number') count;
|
||||
@attr('number') previousCount;
|
||||
@attr('boolean') error;
|
||||
@attr('string') evalId;
|
||||
|
||||
@attr('date') time;
|
||||
@attr('number') timeNanos;
|
||||
|
||||
@attr('string') message;
|
||||
@attr() meta;
|
||||
}
|
||||
17
ui/app/models/task-group-scale.js
Normal file
17
ui/app/models/task-group-scale.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Fragment from 'ember-data-model-fragments/fragment';
|
||||
import attr from 'ember-data/attr';
|
||||
import { fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||
|
||||
export default class TaskGroupScale extends Fragment {
|
||||
@fragmentOwner() jobScale;
|
||||
|
||||
@attr('string') name;
|
||||
|
||||
@attr('number') desired;
|
||||
@attr('number') placed;
|
||||
@attr('number') running;
|
||||
@attr('number') healthy;
|
||||
@attr('number') unhealthy;
|
||||
|
||||
@fragmentArray('scale-event') events;
|
||||
}
|
||||
@@ -54,6 +54,11 @@ export default class TaskGroup extends Fragment {
|
||||
return maybe(this.get('job.taskGroupSummaries')).findBy('name', this.name);
|
||||
}
|
||||
|
||||
@computed('job.scaleState.taskGroupScales.[]')
|
||||
get scaleState() {
|
||||
return maybe(this.get('job.scaleState.taskGroupScales')).findBy('name', this.name);
|
||||
}
|
||||
|
||||
scale(count, reason) {
|
||||
return this.job.scale(this.name, count, reason);
|
||||
}
|
||||
|
||||
19
ui/app/serializers/job-scale.js
Normal file
19
ui/app/serializers/job-scale.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { assign } from '@ember/polyfills';
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default class JobScale extends ApplicationSerializer {
|
||||
normalize(modelClass, hash) {
|
||||
// Transform the map-based TaskGroups object into an array-based
|
||||
// TaskGroupScale fragment list
|
||||
hash.PlainJobId = hash.JobID;
|
||||
hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']);
|
||||
hash.JobID = hash.ID;
|
||||
|
||||
const taskGroups = hash.TaskGroups || {};
|
||||
hash.TaskGroupScales = Object.keys(taskGroups).map(key => {
|
||||
return assign(taskGroups[key], { Name: key });
|
||||
});
|
||||
|
||||
return super.normalize(modelClass, hash);
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,11 @@ export default class JobSerializer extends ApplicationSerializer {
|
||||
related: buildURL(`${jobURL}/evaluations`, { namespace }),
|
||||
},
|
||||
},
|
||||
scale: {
|
||||
links: {
|
||||
related: buildURL(`${jobURL}/scale`, { namespace }),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
10
ui/app/serializers/scale-event.js
Normal file
10
ui/app/serializers/scale-event.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import ApplicationSerializer from './application';
|
||||
|
||||
export default class ScaleEventSerializer extends ApplicationSerializer {
|
||||
normalize(typeHash, hash) {
|
||||
hash.TimeNanos = hash.Time % 1000000;
|
||||
hash.Time = Math.floor(hash.Time / 1000000);
|
||||
|
||||
return super.normalize(typeHash, hash);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user