foreman_acd 0.0.6 → 0.6.0

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