foreman_acd 0.2.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -56
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +199 -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 +1 -0
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +19 -10
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +111 -137
  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 +62 -0
  13. data/app/controllers/ui_acd_controller.rb +20 -3
  14. data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +47 -0
  15. data/app/lib/actions/foreman_acd/run_configurator.rb +44 -0
  16. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
  17. data/app/models/foreman_acd/acd_provider.rb +36 -0
  18. data/app/models/foreman_acd/ansible_playbook.rb +68 -0
  19. data/app/models/foreman_acd/app_definition.rb +25 -0
  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/acd_proxy_proxy_selector.rb +17 -0
  24. data/app/services/foreman_acd/app_configurator.rb +98 -0
  25. data/app/services/foreman_acd/app_deployer.rb +157 -0
  26. data/app/services/foreman_acd/inventory_creator.rb +68 -0
  27. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +64 -0
  28. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
  29. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  30. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  31. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
  32. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
  33. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
  34. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
  35. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
  36. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
  37. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
  38. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
  39. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
  40. data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -12
  41. data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
  42. data/app/views/foreman_acd/app_definitions/index.html.erb +4 -4
  43. data/app/views/foreman_acd/app_instances/_form.html.erb +11 -9
  44. data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
  45. data/app/views/foreman_acd/app_instances/index.html.erb +89 -10
  46. data/app/views/foreman_acd/app_instances/report.html.erb +6 -3
  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 +32 -2
  53. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  54. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  55. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
  56. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
  57. data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
  58. data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
  59. data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
  60. data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
  61. data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
  62. data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
  63. data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
  64. data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
  65. data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.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.rb +12 -0
  69. data/lib/foreman_acd/engine.rb +43 -3
  70. data/lib/foreman_acd/plugin.rb +88 -22
  71. data/lib/foreman_acd/version.rb +1 -1
  72. data/lib/tasks/foreman_acd_tasks.rake +0 -12
  73. data/locale/en/foreman_acd.edit.po +326 -0
  74. data/locale/en/foreman_acd.po +232 -2
  75. data/locale/en/foreman_acd.po.time_stamp +0 -0
  76. data/locale/foreman_acd.pot +343 -8
  77. data/package.json +9 -9
  78. data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
  79. data/test/controllers/app_instances_controller_test.rb +8 -3
  80. data/test/controllers/ui_acd_controller_test.rb +22 -6
  81. data/test/factories/foreman_acd_factories.rb +18 -4
  82. data/test/models/acd_provider_test.rb +37 -0
  83. data/test/models/ansible_playbook_test.rb +11 -0
  84. data/test/models/app_definition_test.rb +1 -1
  85. data/test/models/app_instance_test.rb +2 -0
  86. data/test/models/concerns/host_extensions_test.rb +26 -0
  87. data/test/models/foreman_host_test.rb +12 -0
  88. data/webpack/__mocks__/foremanReact/API.js +2 -0
  89. data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
  90. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  91. data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
  92. data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
  93. data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
  94. data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
  95. data/webpack/__snapshots__/helper.test.js.snap +14 -0
  96. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +159 -29
  97. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +106 -14
  98. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +8 -2
  99. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  100. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +143 -21
  101. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +3 -0
  102. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
  103. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
  104. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +25 -0
  105. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
  106. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +41 -0
  107. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +200 -0
  108. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
  109. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +299 -0
  110. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +50 -0
  111. data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
  112. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
  113. data/webpack/components/ApplicationDefinition/index.js +6 -0
  114. data/webpack/components/ApplicationInstance/ApplicationInstance.js +151 -44
  115. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +47 -10
  116. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +5 -2
  117. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +114 -28
  118. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +3 -1
  119. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
  120. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +78 -0
  121. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +23 -0
  122. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +119 -0
  123. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +44 -0
  124. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +209 -0
  125. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2719 -0
  126. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +276 -0
  127. data/webpack/components/ApplicationInstance/components/Service.js +1 -1
  128. data/webpack/components/ApplicationInstance/index.js +4 -0
  129. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +53 -60
  130. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +17 -0
  131. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +7 -51
  132. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -4
  133. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +4 -18
  134. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +0 -1
  135. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
  136. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
  137. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
  138. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
  139. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
  140. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +130 -0
  141. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
  142. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
  143. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +1 -1
  144. data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
  145. data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
  146. data/webpack/components/ApplicationInstanceReport/index.js +0 -2
  147. data/webpack/components/ParameterSelection/ParameterSelection.js +85 -50
  148. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +68 -62
  149. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +6 -3
  150. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +0 -32
  151. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +47 -35
  152. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -2
  153. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +116 -84
  154. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
  155. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
  156. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +31 -25
  157. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  158. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +2 -126
  159. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1483 -872
  160. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +117 -79
  161. data/webpack/components/ParameterSelection/index.js +4 -4
  162. data/webpack/components/SyncGitRepo/SyncGitRepo.js +210 -0
  163. data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
  164. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +124 -0
  165. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +9 -0
  166. data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
  167. data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
  168. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
  169. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
  170. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
  171. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
  172. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
  173. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +30 -0
  174. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
  175. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
  176. data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
  177. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +46 -0
  178. data/webpack/components/SyncGitRepo/index.js +28 -0
  179. data/webpack/components/common/DeleteTableEntry.js +3 -3
  180. data/webpack/components/common/EditTableEntry.js +50 -0
  181. data/webpack/components/common/ExtTextInput.js +43 -0
  182. data/webpack/components/common/LockTableEntry.js +60 -0
  183. data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
  184. data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
  185. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +2 -2
  186. data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
  187. data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
  188. data/webpack/helper.js +15 -1
  189. data/webpack/helper.test.js +37 -0
  190. data/webpack/index.js +2 -0
  191. data/webpack/reducer.js +18 -11
  192. metadata +184 -10
  193. data/app/views/foreman_acd/app_instances/deploy.html.erb +0 -19
  194. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
  195. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -17,18 +17,30 @@ import {
17
17
 
18
18
  import {
19
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,
20
23
  APPLICATION_DEFINITION_SERVICE_DELETE,
21
24
  APPLICATION_DEFINITION_SERVICE_ADD,
22
25
  APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE,
23
26
  APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM,
24
27
  APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE,
25
28
  APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL,
26
- APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_OPEN,
27
- APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE,
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,
28
34
  } from './ApplicationDefinitionConstants';
29
35
 
36
+ import {
37
+ transformAnsiblePlaybook,
38
+ } from './ApplicationDefinitionHelper';
39
+
30
40
  export const initApplicationDefinition = (
41
+ ansiblePlaybook,
31
42
  services,
43
+ ansibleVarsAll,
32
44
  headerFormatter,
33
45
  inlineEditFormatter,
34
46
  inlineEditButtonsFormatter,
@@ -44,7 +56,7 @@ export const initApplicationDefinition = (
44
56
  props: {
45
57
  index: 0,
46
58
  style: {
47
- width: '20%'
59
+ width: '15%'
48
60
  }
49
61
  },
50
62
  },
@@ -60,7 +72,7 @@ export const initApplicationDefinition = (
60
72
  props: {
61
73
  index: 1,
62
74
  style: {
63
- width: '20%'
75
+ width: '10%'
64
76
  }
65
77
  },
66
78
  },
@@ -84,13 +96,29 @@ export const initApplicationDefinition = (
84
96
  formatters: [inlineEditFormatter]
85
97
  }
86
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
+ },
87
115
  {
88
116
  property: 'minCount',
89
117
  header: {
90
118
  label: 'min count',
91
119
  formatters: [headerFormatter],
92
120
  props: {
93
- index: 3,
121
+ index: 4,
94
122
  style: {
95
123
  width: '10%'
96
124
  }
@@ -106,7 +134,7 @@ export const initApplicationDefinition = (
106
134
  label: 'max count',
107
135
  formatters: [headerFormatter],
108
136
  props: {
109
- index: 3,
137
+ index: 5,
110
138
  style: {
111
139
  width: '10%'
112
140
  }
@@ -122,9 +150,9 @@ export const initApplicationDefinition = (
122
150
  label: 'Actions',
123
151
  formatters: [actionHeaderCellFormatter],
124
152
  props: {
125
- index: 4,
153
+ index: 6,
126
154
  style: {
127
- width: '20%'
155
+ width: '15%'
128
156
  }
129
157
  },
130
158
  },
@@ -134,7 +162,11 @@ export const initApplicationDefinition = (
134
162
  }
135
163
  ];
136
164
 
165
+ if (ansiblePlaybook !== undefined) {
166
+ initialState.ansiblePlaybook = transformAnsiblePlaybook(ansiblePlaybook);
167
+ }
137
168
  initialState.services = services;
169
+ initialState.ansibleVarsAll = ansibleVarsAll;
138
170
 
139
171
  dispatch({
140
172
  type: APPLICATION_DEFINITION_INIT,
@@ -142,6 +174,34 @@ export const initApplicationDefinition = (
142
174
  });
143
175
  };
144
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
+
145
205
  export const addApplicationDefinitionService = (additionalData) => ({
146
206
  type: APPLICATION_DEFINITION_SERVICE_ADD,
147
207
  payload: {
@@ -185,27 +245,59 @@ export const changeEditApplicationDefinitionService = (value, additionalData) =>
185
245
  },
186
246
  });
187
247
 
188
- export const openParameterSelectionModal = (additionalData) => dispatch => {
248
+ export const openForemanParameterSelectionModal = (additionalData) => dispatch => {
189
249
  dispatch({
190
- type: APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_OPEN,
250
+ type: APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
191
251
  payload: {
192
252
  ...additionalData,
193
253
  }
194
254
  });
195
255
  dispatch(
196
- setModalOpen({ id: 'AppDefinitionParamSelection' })
256
+ setModalOpen({ id: 'AppDefinitionForemanParamSelection' })
197
257
  );
198
258
  }
199
259
 
200
- export const closeParameterSelectionModal = (additionalData) => dispatch => {
260
+ export const closeForemanParameterSelectionModal = (additionalData) => dispatch => {
201
261
  dispatch({
202
- type: APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE,
262
+ type: APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
203
263
  payload: {
204
264
  ...additionalData,
205
265
  }
206
266
  });
207
267
 
208
268
  dispatch(
209
- setModalClosed({ id: 'AppDefinitionParamSelection' })
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' })
210
282
  );
211
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
+ })
@@ -1,9 +1,15 @@
1
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';
2
5
  export const APPLICATION_DEFINITION_SERVICE_DELETE = 'APPLICATION_DEFINITION_SERVICE_DELETE';
3
6
  export const APPLICATION_DEFINITION_SERVICE_ADD = 'APPLICATION_DEFINITION_SERVICE_ADD';
4
7
  export const APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE = 'APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE';
5
8
  export const APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM = 'APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM';
6
9
  export const APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE = 'APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE';
7
10
  export const APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL = 'APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL';
8
- export const APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_OPEN = 'APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_OPEN';
9
- export const APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE = 'APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE';
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
+ }
@@ -8,16 +8,31 @@ import {
8
8
 
9
9
  import {
10
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,
11
14
  APPLICATION_DEFINITION_SERVICE_DELETE,
12
15
  APPLICATION_DEFINITION_SERVICE_ADD,
13
16
  APPLICATION_DEFINITION_SERVICE_EDIT_ACTIVATE,
14
17
  APPLICATION_DEFINITION_SERVICE_EDIT_CONFIRM,
15
18
  APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE,
16
19
  APPLICATION_DEFINITION_SERVICE_EDIT_CANCEL,
17
- APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_OPEN,
18
- APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE,
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,
19
25
  } from './ApplicationDefinitionConstants';
20
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
+
21
36
  export const initialState = Immutable({
22
37
  name: false,
23
38
  error: { errorMsg: '', status: '', statusText: '' },
@@ -30,6 +45,30 @@ const applicationDefinitionConf = (state = initialState, action) => {
30
45
  case APPLICATION_DEFINITION_INIT: {
31
46
  return state.merge(payload);
32
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
+ }
33
72
  case APPLICATION_DEFINITION_SERVICE_ADD: {
34
73
  let services = [];
35
74
  let index = 1;
@@ -39,7 +78,9 @@ const applicationDefinitionConf = (state = initialState, action) => {
39
78
  index = Math.max(...services.map(e => e.id)) + 1;
40
79
  }
41
80
 
42
- const newRow = {id: index, name: "", description: '', hostgroup: '', minCount: '', maxCount: '', parameters: [], newEntry: true };
81
+ const newRow = { id: index, name: "", description: '', hostgroup: '',
82
+ ansibleGroup: '', minCount: '', maxCount: '',
83
+ foremanParameters: [], ansibleParameters: [], newEntry: true };
43
84
  newRow.backup = cloneDeep(newRow)
44
85
  services.push(newRow);
45
86
 
@@ -69,12 +110,41 @@ const applicationDefinitionConf = (state = initialState, action) => {
69
110
  const services = cloneDeep(state.services);
70
111
  const index = findIndex(services, { id: payload.rowData.id });
71
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
+
72
135
  delete services[index].backup;
73
136
  delete services[index].newEntry;
74
137
 
138
+ let ansibleParameters = [];
139
+ const selectedGroup = services[index].ansibleGroup;
140
+
141
+ if (selectedGroup) {
142
+ services[index].ansibleParameters = state.ansiblePlaybook.groups[selectedGroup];
143
+ }
144
+
75
145
  return state.merge({
76
146
  editMode: false,
77
- services: services
147
+ services: services,
78
148
  });
79
149
  }
80
150
  case APPLICATION_DEFINITION_SERVICE_EDIT_CHANGE: {
@@ -101,33 +171,31 @@ const applicationDefinitionConf = (state = initialState, action) => {
101
171
  services: services
102
172
  });
103
173
  }
104
- case APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_OPEN: {
174
+ case APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN: {
105
175
  let parametersData = {};
106
176
 
107
- if (payload && payload.rowData) {
108
- parametersData.serviceDefinition = {
109
- id: payload.rowData.id,
110
- name: payload.rowData.name,
111
- hostgroup_id: payload.rowData.hostgroup
112
- }
113
- parametersData.parameters = payload.rowData.parameters;
114
-
115
- if (parametersData.parameters.length > 0) {
116
- parametersData.mode = 'editDefinition';
117
- } else {
118
- parametersData.mode = 'newDefinition';
119
- }
177
+ parametersData.paramDefinition = {
178
+ id: payload.rowData.id,
179
+ name: payload.rowData.name,
180
+ dataId: payload.rowData.hostgroup
120
181
  }
121
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
+
122
190
  return state.merge({
123
191
  parametersData: parametersData,
124
192
  });
125
193
  }
126
- case APPLICATION_DEFINITION_PARAMETER_SELECTION_MODAL_CLOSE: {
194
+ case APPLICATION_DEFINITION_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE: {
127
195
  if (payload.mode == 'save') {
128
196
  const services = cloneDeep(state.services);
129
- const index = findIndex(services, { id: state.parametersData.serviceDefinition.id });
130
- services[index].parameters = cloneDeep(payload.serviceParameterSelection);
197
+ const index = findIndex(services, { id: state.parametersData.paramDefinition.id });
198
+ services[index].foremanParameters = cloneDeep(payload.parameterSelection);
131
199
 
132
200
  return state.merge({
133
201
  parametersData: null,
@@ -139,6 +207,60 @@ const applicationDefinitionConf = (state = initialState, action) => {
139
207
  });
140
208
  }
141
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
+ }
142
264
  default:
143
265
  return state;
144
266
  }