Skip to content

Commit fc7455c

Browse files
Merge pull request #4994 from hashicorp/b-ui-dots-in-tasks
UI: Bugs around dots in task/task-group/driver names
2 parents bba8b4e + 8909046 commit fc7455c

12 files changed

+703
-15
lines changed

ui/app/serializers/allocation.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export default ApplicationSerializer.extend({
1313
normalize(typeHash, hash) {
1414
// Transform the map-based TaskStates object into an array-based
1515
// TaskState fragment list
16-
hash.TaskStates = Object.keys(get(hash, 'TaskStates') || {}).map(key => {
17-
const state = get(hash, `TaskStates.${key}`);
16+
const states = hash.TaskStates || {};
17+
hash.TaskStates = Object.keys(states).map(key => {
18+
const state = states[key] || {};
1819
const summary = { Name: key };
1920
Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
2021
summary.Resources = hash.TaskResources && hash.TaskResources[key];

ui/app/serializers/deployment.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({
99

1010
normalize(typeHash, hash) {
1111
if (hash) {
12-
hash.TaskGroupSummaries = Object.keys(get(hash, 'TaskGroups') || {}).map(key => {
13-
const deploymentStats = get(hash, `TaskGroups.${key}`);
12+
const taskGroups = hash.TaskGroups || {};
13+
hash.TaskGroupSummaries = Object.keys(taskGroups).map(key => {
14+
const deploymentStats = taskGroups[key];
1415
return assign({ Name: key }, deploymentStats);
1516
});
1617

ui/app/serializers/evaluation.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ export default ApplicationSerializer.extend({
77
system: service(),
88

99
normalize(typeHash, hash) {
10-
hash.FailedTGAllocs = Object.keys(hash.FailedTGAllocs || {}).map(key => {
11-
return assign({ Name: key }, get(hash, `FailedTGAllocs.${key}`) || {});
10+
const failures = hash.FailedTGAllocs || {};
11+
hash.FailedTGAllocs = Object.keys(failures).map(key => {
12+
const propertiesForKey = failures[key] || {};
13+
return assign({ Name: key }, propertiesForKey);
1214
});
1315

1416
hash.PlainJobId = hash.JobID;

ui/app/serializers/job-plan.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { get } from '@ember/object';
21
import { assign } from '@ember/polyfills';
32
import ApplicationSerializer from './application';
43

54
export default ApplicationSerializer.extend({
65
normalize(typeHash, hash) {
7-
hash.FailedTGAllocs = Object.keys(hash.FailedTGAllocs || {}).map(key => {
8-
return assign({ Name: key }, get(hash, `FailedTGAllocs.${key}`) || {});
6+
const failures = hash.FailedTGAllocs || {};
7+
hash.FailedTGAllocs = Object.keys(failures).map(key => {
8+
return assign({ Name: key }, failures[key] || {});
99
});
1010
return this._super(...arguments);
1111
},

ui/app/serializers/job-summary.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export default ApplicationSerializer.extend({
99
hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']);
1010
hash.JobID = hash.ID;
1111

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

1617
Object.keys(allocStats).forEach(

ui/app/serializers/node.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { get } from '@ember/object';
21
import { assign } from '@ember/polyfills';
32
import { inject as service } from '@ember/service';
43
import ApplicationSerializer from './application';
@@ -13,8 +12,9 @@ export default ApplicationSerializer.extend({
1312

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

2020
return this._super(modelClass, hash);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { test } from 'ember-qunit';
2+
import AllocationModel from 'nomad-ui/models/allocation';
3+
import moduleForSerializer from '../../helpers/module-for-serializer';
4+
5+
moduleForSerializer('allocation', 'Unit | Serializer | Allocation', {
6+
needs: [
7+
'service:token',
8+
'service:system',
9+
'serializer:allocation',
10+
'transform:fragment',
11+
'transform:fragment-array',
12+
'model:job',
13+
'model:node',
14+
'model:namespace',
15+
'model:evaluation',
16+
'model:allocation',
17+
'model:resources',
18+
'model:task-state',
19+
'model:reschedule-event',
20+
],
21+
});
22+
23+
const sampleDate = new Date('2018-12-12T00:00:00');
24+
const normalizationTestCases = [
25+
{
26+
name: 'Normal',
27+
in: {
28+
ID: 'test-allocation',
29+
JobID: 'test-summary',
30+
Name: 'test-summary[1]',
31+
Namespace: 'test-namespace',
32+
TaskGroup: 'test-group',
33+
CreateTime: +sampleDate * 1000000,
34+
ModifyTime: +sampleDate * 1000000,
35+
TaskStates: {
36+
testTask: {
37+
State: 'running',
38+
Failed: false,
39+
},
40+
},
41+
},
42+
out: {
43+
data: {
44+
id: 'test-allocation',
45+
type: 'allocation',
46+
attributes: {
47+
taskGroupName: 'test-group',
48+
name: 'test-summary[1]',
49+
modifyTime: sampleDate,
50+
createTime: sampleDate,
51+
states: [
52+
{
53+
name: 'testTask',
54+
state: 'running',
55+
failed: false,
56+
},
57+
],
58+
},
59+
relationships: {
60+
followUpEvaluation: {
61+
data: null,
62+
},
63+
nextAllocation: {
64+
data: null,
65+
},
66+
previousAllocation: {
67+
data: null,
68+
},
69+
job: {
70+
data: {
71+
id: '["test-summary","test-namespace"]',
72+
type: 'job',
73+
},
74+
},
75+
},
76+
},
77+
},
78+
},
79+
80+
{
81+
name: 'Dots in task names',
82+
in: {
83+
ID: 'test-allocation',
84+
JobID: 'test-summary',
85+
Name: 'test-summary[1]',
86+
Namespace: 'test-namespace',
87+
TaskGroup: 'test-group',
88+
CreateTime: +sampleDate * 1000000,
89+
ModifyTime: +sampleDate * 1000000,
90+
TaskStates: {
91+
'one.two': {
92+
State: 'running',
93+
Failed: false,
94+
},
95+
'three.four': {
96+
State: 'pending',
97+
Failed: true,
98+
},
99+
},
100+
},
101+
out: {
102+
data: {
103+
id: 'test-allocation',
104+
type: 'allocation',
105+
attributes: {
106+
taskGroupName: 'test-group',
107+
name: 'test-summary[1]',
108+
modifyTime: sampleDate,
109+
createTime: sampleDate,
110+
states: [
111+
{
112+
name: 'one.two',
113+
state: 'running',
114+
failed: false,
115+
},
116+
{
117+
name: 'three.four',
118+
state: 'pending',
119+
failed: true,
120+
},
121+
],
122+
},
123+
relationships: {
124+
followUpEvaluation: {
125+
data: null,
126+
},
127+
nextAllocation: {
128+
data: null,
129+
},
130+
previousAllocation: {
131+
data: null,
132+
},
133+
job: {
134+
data: {
135+
id: '["test-summary","test-namespace"]',
136+
type: 'job',
137+
},
138+
},
139+
},
140+
},
141+
},
142+
},
143+
];
144+
145+
normalizationTestCases.forEach(testCase => {
146+
test(`normalization: ${testCase.name}`, function(assert) {
147+
assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out);
148+
});
149+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { test } from 'ember-qunit';
2+
import DeploymentModel from 'nomad-ui/models/deployment';
3+
import moduleForSerializer from '../../helpers/module-for-serializer';
4+
5+
moduleForSerializer('deployment', 'Unit | Serializer | Deployment', {
6+
needs: [
7+
'adapter:application',
8+
'serializer:deployment',
9+
'service:system',
10+
'service:token',
11+
'transform:fragment-array',
12+
'model:allocation',
13+
'model:job',
14+
'model:task-group-deployment-summary',
15+
],
16+
});
17+
18+
const normalizationTestCases = [
19+
{
20+
name: 'Normal',
21+
in: {
22+
ID: 'test-deployment',
23+
JobID: 'test-job',
24+
Namespace: 'test-namespace',
25+
Status: 'canceled',
26+
TaskGroups: {
27+
taskGroup: {
28+
DesiredCanaries: 2,
29+
},
30+
},
31+
},
32+
out: {
33+
data: {
34+
id: 'test-deployment',
35+
type: 'deployment',
36+
attributes: {
37+
status: 'canceled',
38+
taskGroupSummaries: [
39+
{
40+
name: 'taskGroup',
41+
desiredCanaries: 2,
42+
},
43+
],
44+
},
45+
relationships: {
46+
allocations: {
47+
links: {
48+
related: '/v1/deployment/allocations/test-deployment',
49+
},
50+
},
51+
job: {
52+
data: {
53+
id: '["test-job","test-namespace"]',
54+
type: 'job',
55+
},
56+
},
57+
jobForLatest: {
58+
data: {
59+
id: '["test-job","test-namespace"]',
60+
type: 'job',
61+
},
62+
},
63+
},
64+
},
65+
},
66+
},
67+
68+
{
69+
name: 'Dots in task group names',
70+
in: {
71+
ID: 'test-deployment',
72+
JobID: 'test-job',
73+
Namespace: 'test-namespace',
74+
Status: 'canceled',
75+
TaskGroups: {
76+
'one.two': {
77+
DesiredCanaries: 2,
78+
},
79+
'three.four': {
80+
DesiredCanaries: 3,
81+
},
82+
},
83+
},
84+
out: {
85+
data: {
86+
id: 'test-deployment',
87+
type: 'deployment',
88+
attributes: {
89+
status: 'canceled',
90+
taskGroupSummaries: [
91+
{
92+
name: 'one.two',
93+
desiredCanaries: 2,
94+
},
95+
{
96+
name: 'three.four',
97+
desiredCanaries: 3,
98+
},
99+
],
100+
},
101+
relationships: {
102+
allocations: {
103+
links: {
104+
related: '/v1/deployment/allocations/test-deployment',
105+
},
106+
},
107+
job: {
108+
data: {
109+
id: '["test-job","test-namespace"]',
110+
type: 'job',
111+
},
112+
},
113+
jobForLatest: {
114+
data: {
115+
id: '["test-job","test-namespace"]',
116+
type: 'job',
117+
},
118+
},
119+
},
120+
},
121+
},
122+
},
123+
];
124+
125+
normalizationTestCases.forEach(testCase => {
126+
test(`normalization: ${testCase.name}`, function(assert) {
127+
assert.deepEqual(this.subject().normalize(DeploymentModel, testCase.in), testCase.out);
128+
});
129+
});

0 commit comments

Comments
 (0)