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: Bugs around dots in task/task-group/driver names #4994

Merged
merged 6 commits into from
Dec 17, 2018
5 changes: 3 additions & 2 deletions ui/app/serializers/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export default ApplicationSerializer.extend({
normalize(typeHash, hash) {
// Transform the map-based TaskStates object into an array-based
// TaskState fragment list
hash.TaskStates = Object.keys(get(hash, 'TaskStates') || {}).map(key => {
const state = get(hash, `TaskStates.${key}`);
const states = hash.TaskStates || {};
hash.TaskStates = Object.keys(states).map(key => {
const state = states[key] || {};
const summary = { Name: key };
Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
summary.Resources = hash.TaskResources && hash.TaskResources[key];
Expand Down
5 changes: 3 additions & 2 deletions ui/app/serializers/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({

normalize(typeHash, hash) {
if (hash) {
hash.TaskGroupSummaries = Object.keys(get(hash, 'TaskGroups') || {}).map(key => {
const deploymentStats = get(hash, `TaskGroups.${key}`);
const taskGroups = hash.TaskGroups || {};
hash.TaskGroupSummaries = Object.keys(taskGroups).map(key => {
const deploymentStats = taskGroups[key];
return assign({ Name: key }, deploymentStats);
});

Expand Down
6 changes: 4 additions & 2 deletions ui/app/serializers/evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export default ApplicationSerializer.extend({
system: service(),

normalize(typeHash, hash) {
hash.FailedTGAllocs = Object.keys(hash.FailedTGAllocs || {}).map(key => {
return assign({ Name: key }, get(hash, `FailedTGAllocs.${key}`) || {});
const failures = hash.FailedTGAllocs || {};
hash.FailedTGAllocs = Object.keys(failures).map(key => {
const propertiesForKey = failures[key] || {};
return assign({ Name: key }, propertiesForKey);
});

hash.PlainJobId = hash.JobID;
Expand Down
6 changes: 3 additions & 3 deletions ui/app/serializers/job-plan.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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}`) || {});
const failures = hash.FailedTGAllocs || {};
hash.FailedTGAllocs = Object.keys(failures).map(key => {
return assign({ Name: key }, failures[key] || {});
});
return this._super(...arguments);
},
Expand Down
5 changes: 3 additions & 2 deletions ui/app/serializers/job-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({
hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']);
hash.JobID = hash.ID;

hash.TaskGroupSummaries = Object.keys(get(hash, 'Summary') || {}).map(key => {
const allocStats = get(hash, `Summary.${key}`) || {};
const fullSummary = hash.Summary || {};
hash.TaskGroupSummaries = Object.keys(fullSummary).map(key => {
const allocStats = fullSummary[key] || {};
const summary = { Name: key };

Object.keys(allocStats).forEach(
Expand Down
6 changes: 3 additions & 3 deletions ui/app/serializers/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { get } from '@ember/object';
import { assign } from '@ember/polyfills';
import { inject as service } from '@ember/service';
import ApplicationSerializer from './application';
Expand All @@ -13,8 +12,9 @@ export default ApplicationSerializer.extend({

normalize(modelClass, hash) {
// Transform the map-based Drivers object into an array-based NodeDriver fragment list
hash.Drivers = Object.keys(get(hash, 'Drivers') || {}).map(key => {
return assign({}, get(hash, `Drivers.${key}`), { Name: key });
const drivers = hash.Drivers || {};
hash.Drivers = Object.keys(drivers).map(key => {
return assign({}, drivers[key], { Name: key });
});

return this._super(modelClass, hash);
Expand Down
149 changes: 149 additions & 0 deletions ui/tests/unit/serializers/allocation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { test } from 'ember-qunit';
import AllocationModel from 'nomad-ui/models/allocation';
import moduleForSerializer from '../../helpers/module-for-serializer';

moduleForSerializer('allocation', 'Unit | Serializer | Allocation', {
needs: [
'service:token',
'service:system',
'serializer:allocation',
'transform:fragment',
'transform:fragment-array',
'model:job',
'model:node',
'model:namespace',
'model:evaluation',
'model:allocation',
'model:resources',
'model:task-state',
'model:reschedule-event',
],
});

const sampleDate = new Date('2018-12-12T00:00:00');
const normalizationTestCases = [
{
name: 'Normal',
in: {
ID: 'test-allocation',
JobID: 'test-summary',
Name: 'test-summary[1]',
Namespace: 'test-namespace',
TaskGroup: 'test-group',
CreateTime: +sampleDate * 1000000,
ModifyTime: +sampleDate * 1000000,
TaskStates: {
testTask: {
State: 'running',
Failed: false,
},
},
},
out: {
data: {
id: 'test-allocation',
type: 'allocation',
attributes: {
taskGroupName: 'test-group',
name: 'test-summary[1]',
modifyTime: sampleDate,
createTime: sampleDate,
states: [
{
name: 'testTask',
state: 'running',
failed: false,
},
],
},
relationships: {
followUpEvaluation: {
data: null,
},
nextAllocation: {
data: null,
},
previousAllocation: {
data: null,
},
job: {
data: {
id: '["test-summary","test-namespace"]',
type: 'job',
},
},
},
},
},
},

{
name: 'Dots in task names',
in: {
ID: 'test-allocation',
JobID: 'test-summary',
Name: 'test-summary[1]',
Namespace: 'test-namespace',
TaskGroup: 'test-group',
CreateTime: +sampleDate * 1000000,
ModifyTime: +sampleDate * 1000000,
TaskStates: {
'one.two': {
State: 'running',
Failed: false,
},
'three.four': {
State: 'pending',
Failed: true,
},
},
},
out: {
data: {
id: 'test-allocation',
type: 'allocation',
attributes: {
taskGroupName: 'test-group',
name: 'test-summary[1]',
modifyTime: sampleDate,
createTime: sampleDate,
states: [
{
name: 'one.two',
state: 'running',
failed: false,
},
{
name: 'three.four',
state: 'pending',
failed: true,
},
],
},
relationships: {
followUpEvaluation: {
data: null,
},
nextAllocation: {
data: null,
},
previousAllocation: {
data: null,
},
job: {
data: {
id: '["test-summary","test-namespace"]',
type: 'job',
},
},
},
},
},
},
];

normalizationTestCases.forEach(testCase => {
test(`normalization: ${testCase.name}`, function(assert) {
assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out);
});
});
129 changes: 129 additions & 0 deletions ui/tests/unit/serializers/deployment-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { test } from 'ember-qunit';
import DeploymentModel from 'nomad-ui/models/deployment';
import moduleForSerializer from '../../helpers/module-for-serializer';

moduleForSerializer('deployment', 'Unit | Serializer | Deployment', {
needs: [
'adapter:application',
'serializer:deployment',
'service:system',
'service:token',
'transform:fragment-array',
'model:allocation',
'model:job',
'model:task-group-deployment-summary',
],
});

const normalizationTestCases = [
{
name: 'Normal',
in: {
ID: 'test-deployment',
JobID: 'test-job',
Namespace: 'test-namespace',
Status: 'canceled',
TaskGroups: {
taskGroup: {
DesiredCanaries: 2,
},
},
},
out: {
data: {
id: 'test-deployment',
type: 'deployment',
attributes: {
status: 'canceled',
taskGroupSummaries: [
{
name: 'taskGroup',
desiredCanaries: 2,
},
],
},
relationships: {
allocations: {
links: {
related: '/v1/deployment/allocations/test-deployment',
},
},
job: {
data: {
id: '["test-job","test-namespace"]',
type: 'job',
},
},
jobForLatest: {
data: {
id: '["test-job","test-namespace"]',
type: 'job',
},
},
},
},
},
},

{
name: 'Dots in task group names',
in: {
ID: 'test-deployment',
JobID: 'test-job',
Namespace: 'test-namespace',
Status: 'canceled',
TaskGroups: {
'one.two': {
DesiredCanaries: 2,
},
'three.four': {
DesiredCanaries: 3,
},
},
},
out: {
data: {
id: 'test-deployment',
type: 'deployment',
attributes: {
status: 'canceled',
taskGroupSummaries: [
{
name: 'one.two',
desiredCanaries: 2,
},
{
name: 'three.four',
desiredCanaries: 3,
},
],
},
relationships: {
allocations: {
links: {
related: '/v1/deployment/allocations/test-deployment',
},
},
job: {
data: {
id: '["test-job","test-namespace"]',
type: 'job',
},
},
jobForLatest: {
data: {
id: '["test-job","test-namespace"]',
type: 'job',
},
},
},
},
},
},
];

normalizationTestCases.forEach(testCase => {
test(`normalization: ${testCase.name}`, function(assert) {
assert.deepEqual(this.subject().normalize(DeploymentModel, testCase.in), testCase.out);
});
});
Loading