foreman_acd 0.0.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
  3. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +54 -0
  4. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
  5. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
  6. data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +35 -4
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +43 -87
  9. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
  10. data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
  11. data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
  12. data/app/controllers/ui_acd_controller.rb +11 -4
  13. data/app/models/foreman_acd/ansible_playbook.rb +50 -0
  14. data/app/models/foreman_acd/app_definition.rb +2 -1
  15. data/app/models/foreman_acd/app_instance.rb +7 -0
  16. data/app/services/foreman_acd/app_configurator.rb +70 -0
  17. data/app/services/foreman_acd/app_deployer.rb +143 -0
  18. data/app/services/foreman_acd/inventory_creator.rb +67 -0
  19. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
  20. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -0
  21. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  22. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  23. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +3 -0
  24. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
  25. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
  26. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
  27. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
  28. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
  29. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
  30. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
  31. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
  32. data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
  33. data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
  34. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  35. data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
  36. data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
  37. data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
  38. data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
  39. data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
  40. data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -0
  41. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  42. data/app/views/ui_acd/app.json.rabl +6 -2
  43. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  44. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  45. data/config/routes.rb +31 -1
  46. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  47. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  48. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  49. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  50. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +5 -0
  51. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
  52. data/db/seeds.d/75-job_templates.rb +8 -0
  53. data/lib/foreman_acd/engine.rb +3 -0
  54. data/lib/foreman_acd/plugin.rb +72 -4
  55. data/lib/foreman_acd/version.rb +1 -1
  56. data/package.json +2 -1
  57. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +376 -0
  58. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  59. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
  60. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
  61. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  62. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
  63. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
  64. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  65. data/webpack/components/ApplicationDefinition/index.js +33 -0
  66. data/webpack/components/ApplicationInstance/ApplicationInstance.js +412 -0
  67. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  68. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
  69. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
  70. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
  71. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -0
  72. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  73. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  74. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  75. data/webpack/components/ApplicationInstance/index.js +35 -0
  76. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
  77. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
  78. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
  79. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
  82. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  83. data/webpack/components/ApplicationInstanceReport/index.js +27 -0
  84. data/webpack/components/ParameterSelection/ParameterSelection.js +96 -183
  85. data/webpack/components/ParameterSelection/ParameterSelection.scss +10 -3
  86. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +72 -104
  87. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +14 -19
  88. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  89. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +100 -83
  90. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  91. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  92. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  93. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  94. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  95. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  96. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  97. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  98. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  99. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  100. data/webpack/components/ParameterSelection/index.js +6 -8
  101. data/webpack/components/common/AddTableEntry.js +30 -0
  102. data/webpack/components/common/DeleteTableEntry.js +39 -0
  103. data/webpack/components/common/ExtSelect.js +43 -0
  104. data/webpack/components/common/RailsData.js +27 -0
  105. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  106. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  107. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  108. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  109. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  110. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  111. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  112. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  113. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  114. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  115. data/webpack/helper.js +20 -0
  116. data/webpack/index.js +6 -0
  117. data/webpack/reducer.js +43 -3
  118. metadata +85 -39
@@ -0,0 +1 @@
1
+ @import '~@theforeman/vendor/scss/variables';
@@ -0,0 +1,295 @@
1
+ import React from 'react';
2
+ import api from 'foremanReact/API';
3
+
4
+ import {
5
+ setModalOpen,
6
+ setModalClosed,
7
+ } from 'foremanReact/components/ForemanModal/ForemanModalActions';
8
+
9
+ import {
10
+ actionHeaderCellFormatter,
11
+ } from 'patternfly-react';
12
+
13
+ import {
14
+ propsToSnakeCase,
15
+ propsToCamelCase,
16
+ } from 'foremanReact/common/helpers';
17
+
18
+ import {
19
+ APPLICATION_DEFINITION_INIT,
20
+ APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_REQUEST,
21
+ APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_SUCCESS,
22
+ APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_FAILURE,
23
+ APPLICATION_DEFINITION_SERVICE_DELETE,
24
+ APPLICATION_DEFINITION_SERVICE_ADD,
25
+ APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE,
26
+ APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM,
27
+ APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE,
28
+ APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL,
29
+ APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
30
+ APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
31
+ APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN,
32
+ APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE,
33
+ } from './ApplicationDefinitionConstants';
34
+
35
+ import {
36
+ transformAnsiblePlaybook,
37
+ } from './ApplicationDefinitionHelper';
38
+
39
+ export const initApplicationDefinition = (
40
+ ansiblePlaybook,
41
+ services,
42
+ ansibleVarsAll,
43
+ headerFormatter,
44
+ inlineEditFormatter,
45
+ inlineEditButtonsFormatter,
46
+ ) => dispatch => {
47
+ const initialState = {};
48
+
49
+ initialState.columns = [
50
+ {
51
+ property: 'name',
52
+ header: {
53
+ label: 'Name',
54
+ formatters: [headerFormatter],
55
+ props: {
56
+ index: 0,
57
+ style: {
58
+ width: '20%'
59
+ }
60
+ },
61
+ },
62
+ cell: {
63
+ formatters: [inlineEditFormatter]
64
+ }
65
+ },
66
+ {
67
+ property: 'description',
68
+ header: {
69
+ label: 'Description',
70
+ formatters: [headerFormatter],
71
+ props: {
72
+ index: 1,
73
+ style: {
74
+ width: '20%'
75
+ }
76
+ },
77
+ },
78
+ cell: {
79
+ formatters: [inlineEditFormatter]
80
+ }
81
+ },
82
+ {
83
+ property: 'hostgroup',
84
+ header: {
85
+ label: 'Hostgroup',
86
+ formatters: [headerFormatter],
87
+ props: {
88
+ index: 2,
89
+ style: {
90
+ width: '20%'
91
+ }
92
+ },
93
+ },
94
+ cell: {
95
+ formatters: [inlineEditFormatter]
96
+ }
97
+ },
98
+ {
99
+ property: 'ansibleGroup',
100
+ header: {
101
+ label: 'Ansible Group',
102
+ formatters: [headerFormatter],
103
+ props: {
104
+ index: 3,
105
+ style: {
106
+ width: '20%'
107
+ }
108
+ },
109
+ },
110
+ cell: {
111
+ formatters: [inlineEditFormatter]
112
+ }
113
+ },
114
+ {
115
+ property: 'minCount',
116
+ header: {
117
+ label: 'min count',
118
+ formatters: [headerFormatter],
119
+ props: {
120
+ index: 4,
121
+ style: {
122
+ width: '10%'
123
+ }
124
+ },
125
+ },
126
+ cell: {
127
+ formatters: [inlineEditFormatter]
128
+ }
129
+ },
130
+ {
131
+ property: 'maxCount',
132
+ header: {
133
+ label: 'max count',
134
+ formatters: [headerFormatter],
135
+ props: {
136
+ index: 5,
137
+ style: {
138
+ width: '10%'
139
+ }
140
+ },
141
+ },
142
+ cell: {
143
+ formatters: [inlineEditFormatter]
144
+ }
145
+ },
146
+ {
147
+ property: 'actions',
148
+ header: {
149
+ label: 'Actions',
150
+ formatters: [actionHeaderCellFormatter],
151
+ props: {
152
+ index: 6,
153
+ style: {
154
+ width: '20%'
155
+ }
156
+ },
157
+ },
158
+ cell: {
159
+ formatters: [inlineEditButtonsFormatter]
160
+ }
161
+ }
162
+ ];
163
+
164
+ if (ansiblePlaybook !== undefined) {
165
+ initialState.ansiblePlaybook = transformAnsiblePlaybook(ansiblePlaybook);
166
+ }
167
+ initialState.services = services;
168
+ initialState.ansibleVarsAll = ansibleVarsAll;
169
+
170
+ dispatch({
171
+ type: APPLICATION_DEFINITION_INIT,
172
+ payload: initialState,
173
+ });
174
+ };
175
+
176
+ const errorHandler = (msg, err) => {
177
+ const error = {
178
+ errorMsg: 'Failed to fetch data from server.',
179
+ statusText: err,
180
+ };
181
+ return { type: msg, payload: { error } };
182
+ };
183
+
184
+ export const loadAnsibleData = (
185
+ ansiblePlaybookId,
186
+ additionalData
187
+ ) => dispatch => {
188
+ dispatch({ type: APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_REQUEST });
189
+
190
+ const baseUrl = additionalData.url;
191
+ const realUrl = baseUrl.replace("__id__", ansiblePlaybookId);
192
+
193
+ return api
194
+ .get(realUrl, {}, {})
195
+ .then(({ data }) =>
196
+ dispatch({
197
+ type: APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_SUCCESS,
198
+ payload: { ...data }
199
+ })
200
+ )
201
+ .catch(error => dispatch(errorHandler(APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_FAILURE, error)));
202
+ };
203
+
204
+ export const addApplicationDefinitionService = (additionalData) => ({
205
+ type: APPLICATION_DEFINITION_SERVICE_ADD,
206
+ payload: {
207
+ ...additionalData,
208
+ },
209
+ });
210
+
211
+ export const deleteApplicationDefinitionService = (additionalData) => ({
212
+ type: APPLICATION_DEFINITION_SERVICE_DELETE,
213
+ payload: {
214
+ ...additionalData,
215
+ },
216
+ });
217
+
218
+ export const activateEditApplicationDefinitionService = (additionalData) => ({
219
+ type: APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE,
220
+ payload: {
221
+ ...additionalData,
222
+ },
223
+ });
224
+
225
+ export const confirmEditApplicationDefinitionService = (rowData) => ({
226
+ type: APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM,
227
+ payload: {
228
+ ...rowData,
229
+ },
230
+ });
231
+
232
+ export const cancelEditApplicationDefinitionService = (rowData) => ({
233
+ type: APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL,
234
+ payload: {
235
+ ...rowData,
236
+ },
237
+ });
238
+
239
+ export const changeEditApplicationDefinitionService = (value, additionalData) => ({
240
+ type: APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE,
241
+ payload: {
242
+ value,
243
+ ...additionalData,
244
+ },
245
+ });
246
+
247
+ export const openForemanParameterSelectionModal = (additionalData) => dispatch => {
248
+ dispatch({
249
+ type: APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
250
+ payload: {
251
+ ...additionalData,
252
+ }
253
+ });
254
+ dispatch(
255
+ setModalOpen({ id: 'AppDefinitionForemanParamSelection' })
256
+ );
257
+ }
258
+
259
+ export const closeForemanParameterSelectionModal = (additionalData) => dispatch => {
260
+ dispatch({
261
+ type: APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
262
+ payload: {
263
+ ...additionalData,
264
+ }
265
+ });
266
+
267
+ dispatch(
268
+ setModalClosed({ id: 'AppDefinitionForemanParamSelection' })
269
+ );
270
+ }
271
+
272
+ export const openAnsibleParameterSelectionModal = (additionalData) => dispatch => {
273
+ dispatch({
274
+ type: APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN,
275
+ payload: {
276
+ ...additionalData,
277
+ }
278
+ });
279
+ dispatch(
280
+ setModalOpen({ id: 'AppDefinitionAnsibleParamSelection' })
281
+ );
282
+ }
283
+
284
+ export const closeAnsibleParameterSelectionModal = (additionalData) => dispatch => {
285
+ dispatch({
286
+ type: APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE,
287
+ payload: {
288
+ ...additionalData,
289
+ }
290
+ });
291
+
292
+ dispatch(
293
+ setModalClosed({ id: 'AppDefinitionAnsibleParamSelection' })
294
+ );
295
+ }
@@ -0,0 +1,14 @@
1
+ export const APPLICATION_DEFINITION_INIT = 'INIT_APPLICATION_DEFINITION_INIT';
2
+ export const APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_REQUEST = 'APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_REQUEST';
3
+ export const APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_SUCCESS = 'APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_SUCCESS';
4
+ export const APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_FAILURE = 'APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_FAILURE';
5
+ export const APPLICATION_DEFINITION_SERVICE_DELETE = 'APPLICATION_DEFINITION_SERVICE_DELETE';
6
+ export const APPLICATION_DEFINITION_SERVICE_ADD = 'APPLICATION_DEFINITION_SERVICE_ADD';
7
+ export const APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE = 'APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE';
8
+ export const APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM = 'APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM';
9
+ export const APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE = 'APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE';
10
+ export const APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL = 'APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL';
11
+ export const APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN = 'APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN';
12
+ export const APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE = 'APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE';
13
+ export const APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN = 'APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN';
14
+ export const APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE = 'APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE';
@@ -0,0 +1,26 @@
1
+ export function transformAnsiblePlaybook(playbook) {
2
+
3
+ const ansiblePlaybook = new Object;
4
+ ansiblePlaybook.id = playbook.id;
5
+ ansiblePlaybook.name = playbook.name;
6
+ ansiblePlaybook.groups = {};
7
+
8
+ if (playbook.hasOwnProperty('groups')) {
9
+ Object.entries(playbook.groups).forEach(([group_name,group_vars]) => {
10
+ ansiblePlaybook.groups[group_name] = [];
11
+
12
+ let id=0;
13
+ Object.entries(group_vars).forEach(([var_name,var_value]) => {
14
+ let entry = {
15
+ id: id,
16
+ name: var_name,
17
+ value: var_value
18
+ }
19
+ ansiblePlaybook.groups[group_name].push(entry);
20
+ id += 1;
21
+ });
22
+ });
23
+ }
24
+
25
+ return ansiblePlaybook;
26
+ }
@@ -0,0 +1,243 @@
1
+ import Immutable from 'seamless-immutable';
2
+
3
+ import {
4
+ cloneDeep,
5
+ findIndex,
6
+ findLastIndex,
7
+ } from 'lodash';
8
+
9
+ import {
10
+ APPLICATION_DEFINITION_INIT,
11
+ APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_REQUEST,
12
+ APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_SUCCESS,
13
+ APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_FAILURE,
14
+ APPLICATION_DEFINITION_SERVICE_DELETE,
15
+ APPLICATION_DEFINITION_SERVICE_ADD,
16
+ APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE,
17
+ APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM,
18
+ APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE,
19
+ APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL,
20
+ APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
21
+ APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
22
+ APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN,
23
+ APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE,
24
+ } from './ApplicationDefinitionConstants';
25
+
26
+ import {
27
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
28
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
29
+ } from '../ParameterSelection/ParameterSelectionConstants';
30
+
31
+ import {
32
+ transformAnsiblePlaybook,
33
+ } from './ApplicationDefinitionHelper';
34
+
35
+ export const initialState = Immutable({
36
+ name: false,
37
+ error: { errorMsg: '', status: '', statusText: '' },
38
+ });
39
+
40
+ const applicationDefinitionConf = (state = initialState, action) => {
41
+ const { payload } = action;
42
+
43
+ switch (action.type) {
44
+ case APPLICATION_DEFINITION_INIT: {
45
+ return state.merge(payload);
46
+ }
47
+
48
+ case APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_FAILURE: {
49
+ return state.merge({ error: payload.error, loading: false });
50
+ }
51
+ case APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_REQUEST: {
52
+ return state.set('loading', true);
53
+ }
54
+ case APPLICATION_DEFINITION_LOAD_ANSIBLE_DATA_SUCCESS: {
55
+ let newState = {};
56
+ let allVars = [];
57
+
58
+ const ansiblePlaybook = transformAnsiblePlaybook(payload);
59
+
60
+ if (ansiblePlaybook.hasOwnProperty('groups')) {
61
+ allVars = ansiblePlaybook.groups['all']
62
+ }
63
+
64
+ newState = {
65
+ ansiblePlaybook: ansiblePlaybook,
66
+ ansibleVarsAll: allVars
67
+ }
68
+
69
+ return state.merge(newState);
70
+ }
71
+ case APPLICATION_DEFINITION_SERVICE_ADD: {
72
+ let services = [];
73
+ let index = 1;
74
+
75
+ if ('services' in state && state.services !== undefined && state.services.length > 0) {
76
+ services = cloneDeep(state.services);
77
+ index = Math.max(...services.map(e => e.id)) + 1;
78
+ }
79
+
80
+ const newRow = { id: index, name: "", description: '', hostgroup: '',
81
+ ansibleGroup: '', minCount: '', maxCount: '',
82
+ foremanParameters: [], ansibleParameters: [], newEntry: true };
83
+ newRow.backup = cloneDeep(newRow)
84
+ services.push(newRow);
85
+
86
+ return state.merge({
87
+ editMode: true,
88
+ services: services
89
+ });
90
+ }
91
+ case APPLICATION_DEFINITION_SERVICE_DELETE: {
92
+ const services = state.services.filter(v => v.id !== payload.rowData.id);
93
+ return state.merge({
94
+ services: services,
95
+ })
96
+ }
97
+ case APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE: {
98
+ const services = cloneDeep(state.services);
99
+ const index = findIndex(services, { id: payload.rowData.id });
100
+
101
+ services[index].backup = cloneDeep(services[index]);
102
+
103
+ return state.merge({
104
+ editMode: true,
105
+ services: services
106
+ });
107
+ }
108
+ case APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM: {
109
+ const services = cloneDeep(state.services);
110
+ const index = findIndex(services, { id: payload.rowData.id });
111
+
112
+ delete services[index].backup;
113
+ delete services[index].newEntry;
114
+
115
+ let ansibleParameters = [];
116
+ const selectedGroup = services[index].ansibleGroup;
117
+
118
+ if (selectedGroup) {
119
+ services[index].ansibleParameters = state.ansiblePlaybook.groups[selectedGroup];
120
+ }
121
+
122
+ return state.merge({
123
+ editMode: false,
124
+ services: services,
125
+ });
126
+ }
127
+ case APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE: {
128
+ const services = cloneDeep(state.services);
129
+ const index = findIndex(services, { id: payload.rowData.id });
130
+
131
+ services[index][payload.property] = payload.value;
132
+
133
+ return state.set('services', services);
134
+ }
135
+ case APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL: {
136
+ const services = cloneDeep(state.services);
137
+ const index = findIndex(services, { id: payload.rowData.id });
138
+
139
+ services[index] = cloneDeep(services[index].backup);
140
+ delete services[index].backup;
141
+
142
+ if (services[index].newEntry === true) {
143
+ services.splice(index, 1);
144
+ }
145
+
146
+ return state.merge({
147
+ editMode: false,
148
+ services: services
149
+ });
150
+ }
151
+ case APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN: {
152
+ let parametersData = {};
153
+
154
+ parametersData.paramDefinition = {
155
+ id: payload.rowData.id,
156
+ name: payload.rowData.name,
157
+ dataId: payload.rowData.hostgroup
158
+ }
159
+
160
+ parametersData.type = PARAMETER_SELECTION_PARAM_TYPE_FOREMAN;
161
+ parametersData.parameters = payload.rowData.foremanParameters;
162
+ parametersData.useDefaultValue = true;
163
+ parametersData.allowRowAdjustment = true;
164
+ parametersData.allowNameAdjustment = true;
165
+ parametersData.allowDescriptionAdjustment = true;
166
+
167
+ return state.merge({
168
+ parametersData: parametersData,
169
+ });
170
+ }
171
+ case APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE: {
172
+ if (payload.mode == 'save') {
173
+ const services = cloneDeep(state.services);
174
+ const index = findIndex(services, { id: state.parametersData.paramDefinition.id });
175
+ services[index].foremanParameters = cloneDeep(payload.parameterSelection);
176
+
177
+ return state.merge({
178
+ parametersData: null,
179
+ services: services,
180
+ });
181
+ } else {
182
+ return state.merge({
183
+ parametersData: null,
184
+ });
185
+ }
186
+ }
187
+ case APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN: {
188
+ let parametersData = {};
189
+
190
+ if ((payload.hasOwnProperty('isAllGroup')) && (payload.isAllGroup == true)) {
191
+ parametersData.parameters = state.ansibleVarsAll;
192
+ parametersData.paramDefinition = {
193
+ isAllGroup: true,
194
+ }
195
+ } else {
196
+ parametersData.parameters = payload.rowData.ansibleParameters;
197
+ parametersData.paramDefinition = {
198
+ id: payload.rowData.id,
199
+ name: payload.rowData.name,
200
+ }
201
+ }
202
+
203
+ parametersData.type = PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE;
204
+ parametersData.useDefaultValue = false;
205
+ parametersData.allowRowAdjustment = true;
206
+ parametersData.allowNameAdjustment = true;
207
+ parametersData.allowDescriptionAdjustment = true;
208
+
209
+ return state.merge({
210
+ parametersData: parametersData,
211
+ });
212
+ }
213
+ case APPLICATION_DEFINITION_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE: {
214
+ let newState = {};
215
+ if (payload.mode == 'save') {
216
+ if ((state.parametersData.paramDefinition.hasOwnProperty('isAllGroup')) && (state.parametersData.paramDefinition.isAllGroup == true)) {
217
+ newState = {
218
+ parametersData: null,
219
+ ansibleVarsAll: cloneDeep(payload.parameterSelection),
220
+ };
221
+ } else {
222
+ const services = cloneDeep(state.services);
223
+ const index = findIndex(services, { id: state.parametersData.paramDefinition.id });
224
+ services[index].ansibleParameters = cloneDeep(payload.parameterSelection);
225
+
226
+ newState = {
227
+ parametersData: null,
228
+ services: services,
229
+ };
230
+ }
231
+ } else {
232
+ newState = {
233
+ parametersData: null,
234
+ };
235
+ }
236
+ return state.merge(newState);
237
+ }
238
+ default:
239
+ return state;
240
+ }
241
+ };
242
+
243
+ export default applicationDefinitionConf;