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,11 @@
1
+ @import '~@theforeman/vendor/scss/variables';
2
+
3
+ .service-counter {
4
+ position: absolute;
5
+ right: 200px;
6
+ top: 220px;
7
+ }
8
+
9
+ .service-counter-title {
10
+ font-size: 14px;
11
+ }
@@ -0,0 +1,247 @@
1
+ import React from 'react';
2
+ import api from 'foremanReact/API';
3
+ import {
4
+ setModalOpen,
5
+ setModalClosed,
6
+ } from 'foremanReact/components/ForemanModal/ForemanModalActions';
7
+
8
+ import {
9
+ actionHeaderCellFormatter,
10
+ } from 'patternfly-react';
11
+
12
+ import {
13
+ propsToSnakeCase,
14
+ propsToCamelCase,
15
+ } from 'foremanReact/common/helpers';
16
+
17
+ import {
18
+ APPLICATION_INSTANCE_INIT,
19
+ APPLICATION_INSTANCE_HOST_DELETE,
20
+ APPLICATION_INSTANCE_HOST_ADD,
21
+ APPLICATION_INSTANCE_HOST_EDIT_ACTIVATE,
22
+ APPLICATION_INSTANCE_HOST_EDIT_CONFIRM,
23
+ APPLICATION_INSTANCE_HOST_EDIT_CHANGE,
24
+ APPLICATION_INSTANCE_HOST_EDIT_CANCEL,
25
+ APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
26
+ APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
27
+ APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN,
28
+ APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE,
29
+ APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_REQUEST,
30
+ APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_SUCCESS,
31
+ APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_FAILURE,
32
+ APPLICATION_INSTANCE_CHANGE_PARAMETER_SELECTION_MODE,
33
+ } from './ApplicationInstanceConstants';
34
+
35
+ export const initApplicationInstance = (
36
+ appDefinition,
37
+ hosts,
38
+ ansibleVarsAll,
39
+ headerFormatter,
40
+ inlineEditFormatter,
41
+ inlineEditButtonsFormatter,
42
+ ) => dispatch => {
43
+ const initialState = {};
44
+
45
+ initialState.columns = [
46
+ {
47
+ property: 'hostname',
48
+ header: {
49
+ label: 'Hostname',
50
+ formatters: [headerFormatter],
51
+ props: {
52
+ index: 0,
53
+ style: {
54
+ width: '30%'
55
+ }
56
+ },
57
+ },
58
+ cell: {
59
+ formatters: [inlineEditFormatter]
60
+ }
61
+ },
62
+ {
63
+ property: 'description',
64
+ header: {
65
+ label: 'Description',
66
+ formatters: [headerFormatter],
67
+ props: {
68
+ index: 1,
69
+ style: {
70
+ width: '30%'
71
+ }
72
+ },
73
+ },
74
+ cell: {
75
+ formatters: [inlineEditFormatter]
76
+ }
77
+ },
78
+ {
79
+ property: 'service',
80
+ header: {
81
+ label: 'Service',
82
+ formatters: [headerFormatter],
83
+ props: {
84
+ index: 2,
85
+ style: {
86
+ width: '20%'
87
+ }
88
+ },
89
+ },
90
+ cell: {
91
+ formatters: [inlineEditFormatter]
92
+ }
93
+ },
94
+ {
95
+ property: 'actions',
96
+ header: {
97
+ label: 'Actions',
98
+ formatters: [actionHeaderCellFormatter],
99
+ props: {
100
+ index: 4,
101
+ style: {
102
+ width: '20%'
103
+ }
104
+ },
105
+ },
106
+ cell: {
107
+ formatters: [inlineEditButtonsFormatter]
108
+ }
109
+ }
110
+ ];
111
+
112
+ initialState.appDefinition = appDefinition;
113
+ initialState.hosts = hosts;
114
+ initialState.ansibleVarsAll = ansibleVarsAll;
115
+
116
+ dispatch({
117
+ type: APPLICATION_INSTANCE_INIT,
118
+ payload: initialState,
119
+ });
120
+ };
121
+
122
+ const errorHandler = (msg, err) => {
123
+ const error = {
124
+ errorMsg: 'Failed to fetch data from server.',
125
+ statusText: err,
126
+ };
127
+ return { type: msg, payload: { error } };
128
+ };
129
+
130
+ export const loadApplicationDefinition = (
131
+ applicationDefinitionId,
132
+ additionalData,
133
+ ) => dispatch => {
134
+ dispatch({ type: APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_REQUEST });
135
+
136
+ const realUrl = additionalData.url.replace("__id__", applicationDefinitionId);
137
+
138
+ return api
139
+ .get(realUrl, {}, {})
140
+ .then(({ data }) =>
141
+ dispatch({
142
+ type: APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_SUCCESS,
143
+ payload: data,
144
+ })
145
+ )
146
+ .catch(error => dispatch(errorHandler(APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_FAILURE, error)));
147
+ };
148
+
149
+ export const addApplicationInstanceHost = (additionalData) => ({
150
+ type: APPLICATION_INSTANCE_HOST_ADD,
151
+ payload: {
152
+ ...additionalData,
153
+ },
154
+ });
155
+
156
+ export const deleteApplicationInstanceHost = (additionalData) => ({
157
+ type: APPLICATION_INSTANCE_HOST_DELETE,
158
+ payload: {
159
+ ...additionalData,
160
+ },
161
+ });
162
+
163
+ export const activateEditApplicationInstanceHost = (additionalData) => ({
164
+ type: APPLICATION_INSTANCE_HOST_EDIT_ACTIVATE,
165
+ payload: {
166
+ ...additionalData,
167
+ },
168
+ });
169
+
170
+ export const confirmEditApplicationInstanceHost = (rowData) => ({
171
+ type: APPLICATION_INSTANCE_HOST_EDIT_CONFIRM,
172
+ payload: {
173
+ ...rowData,
174
+ },
175
+ });
176
+
177
+ export const cancelEditApplicationInstanceHost = (rowData) => ({
178
+ type: APPLICATION_INSTANCE_HOST_EDIT_CANCEL,
179
+ payload: {
180
+ ...rowData,
181
+ },
182
+ });
183
+
184
+ export const changeEditApplicationInstanceHost = (value, additionalData) => ({
185
+ type: APPLICATION_INSTANCE_HOST_EDIT_CHANGE,
186
+ payload: {
187
+ value,
188
+ ...additionalData,
189
+ },
190
+ });
191
+
192
+ export const openForemanParameterSelectionModal = (additionalData) => dispatch => {
193
+ dispatch({
194
+ type: APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
195
+ payload: {
196
+ ...additionalData,
197
+ }
198
+ });
199
+ dispatch(
200
+ setModalOpen({ id: 'AppInstanceForemanParamSelection' })
201
+ );
202
+ }
203
+
204
+ export const closeForemanParameterSelectionModal = (additionalData) => dispatch => {
205
+ dispatch({
206
+ type: APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
207
+ payload: {
208
+ ...additionalData,
209
+ }
210
+ });
211
+
212
+ dispatch(
213
+ setModalClosed({ id: 'AppInstanceForemanParamSelection' })
214
+ );
215
+ }
216
+
217
+ export const openAnsibleParameterSelectionModal = (additionalData) => dispatch => {
218
+ dispatch({
219
+ type: APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN,
220
+ payload: {
221
+ ...additionalData,
222
+ }
223
+ });
224
+ dispatch(
225
+ setModalOpen({ id: 'AppInstanceAnsibleParamSelection' })
226
+ );
227
+ }
228
+
229
+ export const closeAnsibleParameterSelectionModal = (additionalData) => dispatch => {
230
+ dispatch({
231
+ type: APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE,
232
+ payload: {
233
+ ...additionalData,
234
+ }
235
+ });
236
+
237
+ dispatch(
238
+ setModalClosed({ id: 'AppInstanceAnsibleParamSelection' })
239
+ );
240
+ }
241
+
242
+ export const changeParameterSelectionMode = (additionalData) => ({
243
+ type: APPLICATION_INSTANCE_CHANGE_PARAMETER_SELECTION_MODE,
244
+ payload: {
245
+ ...additionalData,
246
+ },
247
+ })
@@ -0,0 +1,15 @@
1
+ export const APPLICATION_INSTANCE_INIT = 'APPLICATION_INSTANCE_INIT';
2
+ export const APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_REQUEST = 'APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_REQUEST';
3
+ export const APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_SUCCESS = 'APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_SUCCESS';
4
+ export const APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_FAILURE = 'APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_FAILURE';
5
+ export const APPLICATION_INSTANCE_HOST_DELETE = 'APPLICATION_INSTANCE_HOST_DELETE';
6
+ export const APPLICATION_INSTANCE_HOST_ADD = 'APPLICATION_INSTANCE_HOST_ADD';
7
+ export const APPLICATION_INSTANCE_HOST_EDIT_ACTIVATE = 'APPLICATION_INSTANCE_HOST_EDIT_ACTIVATE';
8
+ export const APPLICATION_INSTANCE_HOST_EDIT_CONFIRM = 'APPLICATION_INSTANCE_HOST_EDIT_CONFIRM';
9
+ export const APPLICATION_INSTANCE_HOST_EDIT_CHANGE = 'APPLICATION_INSTANCE_HOST_EDIT_CHANGE';
10
+ export const APPLICATION_INSTANCE_HOST_EDIT_CANCEL = 'APPLICATION_INSTANCE_HOST_EDIT_CANCEL';
11
+ export const APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN = 'APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN';
12
+ export const APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE = 'APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE';
13
+ export const APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN = 'APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN';
14
+ export const APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE = 'APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE';
15
+ export const APPLICATION_INSTANCE_CHANGE_PARAMETER_SELECTION_MODE = 'APPLICATION_INSTANCE_CHANGE_PARAMETER_SELECTION_MODE';
@@ -0,0 +1,309 @@
1
+ import Immutable from 'seamless-immutable';
2
+
3
+ import {
4
+ cloneDeep,
5
+ findIndex,
6
+ findLastIndex,
7
+ } from 'lodash';
8
+
9
+ import {
10
+ APPLICATION_INSTANCE_INIT,
11
+ APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_FAILURE,
12
+ APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_REQUEST,
13
+ APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_SUCCESS,
14
+ APPLICATION_INSTANCE_HOST_DELETE,
15
+ APPLICATION_INSTANCE_HOST_ADD,
16
+ APPLICATION_INSTANCE_HOST_EDIT_ACTIVATE,
17
+ APPLICATION_INSTANCE_HOST_EDIT_CONFIRM,
18
+ APPLICATION_INSTANCE_HOST_EDIT_CHANGE,
19
+ APPLICATION_INSTANCE_HOST_EDIT_CANCEL,
20
+ APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN,
21
+ APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE,
22
+ APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN,
23
+ APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE,
24
+ APPLICATION_INSTANCE_CHANGE_PARAMETER_SELECTION_MODE,
25
+ } from './ApplicationInstanceConstants';
26
+
27
+ import {
28
+ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
29
+ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
30
+ } from '../ParameterSelection/ParameterSelectionConstants';
31
+
32
+ export const initialState = Immutable({
33
+ name: false,
34
+ error: { errorMsg: '', status: '', statusText: '' },
35
+ });
36
+
37
+ const applicationInstanceConf = (state = initialState, action) => {
38
+ const { payload } = action;
39
+
40
+ switch (action.type) {
41
+ case APPLICATION_INSTANCE_INIT: {
42
+ return state.merge(payload);
43
+ }
44
+ case APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_FAILURE: {
45
+ return state.merge({ error: payload.error, loading: false });
46
+ }
47
+ case APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_REQUEST: {
48
+ return state.set('loading', true);
49
+ }
50
+ case APPLICATION_INSTANCE_LOAD_APPLICATION_DEFINITION_SUCCESS: {
51
+ let newState = {};
52
+ const services = JSON.parse(payload.app_definition.services);
53
+
54
+ // initialize all services count with 0
55
+ services.map(serv => {
56
+ serv['currentCount'] = 0;
57
+ })
58
+
59
+ // Update count
60
+ if (state.hosts !== undefined) {
61
+ state.hosts.map((host, index) => {
62
+ const hostServiceId = Number(host.service);
63
+ const service = services.find(serv => serv['id'] == hostServiceId);
64
+ service['currentCount'] += 1;
65
+ });
66
+ }
67
+
68
+ newState = {
69
+ appDefinition: payload.app_definition,
70
+ services: services,
71
+ loading: false,
72
+ };
73
+
74
+ // Initialize ansibleVarsAll if there is no data available in app instance
75
+ if (state.ansibleVarsAll.length <= 0) {
76
+ newState['ansibleVarsAll'] = JSON.parse(payload.app_definition.ansible_vars_all);
77
+ }
78
+
79
+ return state.merge(newState);
80
+ }
81
+ case APPLICATION_INSTANCE_HOST_ADD: {
82
+ let hosts = [];
83
+ let index = 1;
84
+
85
+ if ('hosts' in state && state.hosts !== undefined && state.hosts.length > 0) {
86
+ hosts = cloneDeep(state.hosts);
87
+ index = Math.max(...hosts.map(e => e.id)) + 1;
88
+ }
89
+
90
+ const newRow = {id: index, hostname: "", description: '', service: '', foremanParameters: [], ansibleParameters: [], newEntry: true };
91
+ newRow.backup = cloneDeep(newRow)
92
+ hosts.push(newRow);
93
+
94
+ return state.merge({
95
+ editMode: true,
96
+ hosts: hosts
97
+ });
98
+ }
99
+ case APPLICATION_INSTANCE_HOST_DELETE: {
100
+ const services = cloneDeep(state.services);
101
+ const host = state.hosts.find(v => v.id == payload.rowData.id);
102
+ const hostServiceId = Number(host.service);
103
+ const hosts = state.hosts.filter(v => v.id !== host.id);
104
+
105
+ // Update count
106
+ const service = services.find(serv => serv['id'] == hostServiceId);
107
+ service['currentCount'] -= 1;
108
+
109
+ return state.merge({
110
+ hosts: hosts,
111
+ services: services,
112
+ })
113
+ }
114
+ case APPLICATION_INSTANCE_HOST_EDIT_ACTIVATE: {
115
+ const hosts = cloneDeep(state.hosts);
116
+ const index = findIndex(hosts, { id: payload.rowData.id });
117
+
118
+ hosts[index].backup = cloneDeep(hosts[index]);
119
+
120
+ return state.merge({
121
+ editMode: true,
122
+ hosts: hosts
123
+ });
124
+ }
125
+ case APPLICATION_INSTANCE_HOST_EDIT_CONFIRM: {
126
+ const hosts = cloneDeep(state.hosts);
127
+ const index = findIndex(hosts, { id: payload.rowData.id });
128
+ const services = cloneDeep(state.services);
129
+
130
+ const thisHost = hosts[index];
131
+
132
+ if (thisHost.hostname == '') {
133
+ window.alert("Every host needs to have a valid name");
134
+ return state;
135
+ }
136
+
137
+ // hostnames are lower case
138
+ thisHost.hostname = thisHost.hostname.toLowerCase();
139
+
140
+ const hostnameRegex = /^[0-9a-z]([0-9a-z\-]{0,61}[0-9a-z])$/;
141
+
142
+ if (thisHost.hostname.match(hostnameRegex) == undefined) {
143
+ window.alert("The hostname uses not allowed characters. See https://en.wikipedia.org/wiki/Hostname#Syntax for more details.")
144
+ return state;
145
+ }
146
+
147
+ if (thisHost.service == '') {
148
+ window.alert("Every host needs to be assigned to a service.");
149
+ return state;
150
+ }
151
+
152
+ if (state.hosts.filter(v => v.hostname === thisHost.hostname && v.id != thisHost.id).length > 0) {
153
+ window.alert("Host name already used in this Application Instance. Please make sure that every host name is unique.");
154
+ return state;
155
+ }
156
+
157
+ // Initialize the new Instance with the parameters of the Application Definition.
158
+ if (thisHost.newEntry === true) {
159
+ const selectedService = state.services.filter(entry => entry.id == payload.rowData.service)[0];
160
+ hosts[index].foremanParameters = selectedService.foremanParameters;
161
+ hosts[index].ansibleParameters = selectedService.ansibleParameters;
162
+
163
+ const hostServiceId = Number(thisHost.service);
164
+ const service = services.find(serv => serv['id'] == hostServiceId);
165
+ if ('currentCount' in service) {
166
+ service['currentCount'] += 1;
167
+ } else {
168
+ service['currentCount'] = 1;
169
+ }
170
+ }
171
+
172
+ delete hosts[index].backup;
173
+ delete hosts[index].newEntry;
174
+
175
+ return state.merge({
176
+ editMode: false,
177
+ services: services,
178
+ hosts: hosts
179
+ });
180
+ }
181
+ case APPLICATION_INSTANCE_HOST_EDIT_CHANGE: {
182
+ const hosts = cloneDeep(state.hosts);
183
+ const index = findIndex(hosts, { id: payload.rowData.id });
184
+
185
+ hosts[index][payload.property] = payload.value;
186
+
187
+ return state.set('hosts', hosts);
188
+ }
189
+ case APPLICATION_INSTANCE_HOST_EDIT_CANCEL: {
190
+ const hosts = cloneDeep(state.hosts);
191
+ const index = findIndex(hosts, { id: payload.rowData.id });
192
+
193
+ hosts[index] = cloneDeep(hosts[index].backup);
194
+ delete hosts[index].backup;
195
+
196
+ if (hosts[index].newEntry === true) {
197
+ hosts.splice(index, 1);
198
+ }
199
+
200
+ return state.merge({
201
+ editMode: false,
202
+ hosts: hosts
203
+ });
204
+ }
205
+ case APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_OPEN: {
206
+ let parametersData = {};
207
+
208
+ const selectedService = state.services.filter(entry => entry.id == payload.rowData.service)[0];
209
+
210
+ parametersData.paramDefinition = {
211
+ id: selectedService.id,
212
+ name: selectedService.name,
213
+ dataId: selectedService.hostgroup,
214
+ hostId: payload.rowData.id,
215
+ // TODO: is this really correct? Guess it shoud be dataId and we should get rid of them
216
+ //hostgroup_id: selectedService.hostgroup,
217
+ };
218
+ parametersData.type = PARAMETER_SELECTION_PARAM_TYPE_FOREMAN;
219
+ parametersData.parameters = payload.rowData.foremanParameters;
220
+ parametersData.useDefaultValue = false;
221
+ parametersData.allowRowAdjustment = false;
222
+ parametersData.allowNameAdjustment = false;
223
+ parametersData.allowDescriptionAdjustment = false;
224
+
225
+ return state.merge({
226
+ parametersData: parametersData,
227
+ });
228
+ }
229
+ case APPLICATION_INSTANCE_FOREMAN_PARAMETER_SELECTION_MODAL_CLOSE: {
230
+ if (payload.mode == 'save') {
231
+ const hosts = cloneDeep(state.hosts);
232
+ const index = findIndex(hosts, { id: state.parametersData.paramDefinition.hostId });
233
+ hosts[index].foremanParameters = cloneDeep(payload.parameterSelection);
234
+
235
+ return state.merge({
236
+ parametersData: null,
237
+ hosts: hosts
238
+ });
239
+ } else {
240
+ return state.merge({
241
+ parametersData: null,
242
+ });
243
+ }
244
+ }
245
+ case APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_OPEN: {
246
+ let parametersData = {};
247
+
248
+ if ((payload.hasOwnProperty('isAllGroup')) && (payload.isAllGroup == true)) {
249
+ parametersData.parameters = state.ansibleVarsAll;
250
+ parametersData.paramDefinition = {
251
+ isAllGroup: true,
252
+ }
253
+ } else {
254
+ const selectedService = state.services.filter(entry => entry.id == payload.rowData.service)[0];
255
+
256
+ parametersData.paramDefinition = {
257
+ id: selectedService.id,
258
+ name: selectedService.name,
259
+ hostId: payload.rowData.id,
260
+ // TODO: is this really correct? Guess it shoud be dataId and we should get rid of them
261
+ //hostgroup_id: selectedService.hostgroup,
262
+ };
263
+ parametersData.parameters = payload.rowData.ansibleParameters;
264
+ }
265
+
266
+ parametersData.type = PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE;
267
+ parametersData.useDefaultValue = false;
268
+ parametersData.allowRowAdjustment = false;
269
+ parametersData.allowNameAdjustment = false;
270
+ parametersData.allowDescriptionAdjustment = false;
271
+
272
+ return state.merge({
273
+ parametersData: parametersData,
274
+ });
275
+ }
276
+ case APPLICATION_INSTANCE_ANSIBLE_PARAMETER_SELECTION_MODAL_CLOSE: {
277
+ let newState = {};
278
+ if (payload.mode == 'save') {
279
+ if ((state.parametersData.paramDefinition.hasOwnProperty('isAllGroup')) && (state.parametersData.paramDefinition.isAllGroup == true)) {
280
+ newState = {
281
+ parametersData: null,
282
+ ansibleVarsAll: cloneDeep(payload.parameterSelection),
283
+ };
284
+ } else {
285
+ const hosts = cloneDeep(state.hosts);
286
+ const index = findIndex(hosts, { id: state.parametersData.paramDefinition.hostId });
287
+ hosts[index].ansibleParameters = cloneDeep(payload.parameterSelection);
288
+
289
+ newState = {
290
+ parametersData: null,
291
+ hosts: hosts
292
+ };
293
+ }
294
+ } else {
295
+ newState = {
296
+ parametersData: null,
297
+ };
298
+ }
299
+ return state.merge(newState);
300
+ }
301
+ case APPLICATION_INSTANCE_CHANGE_PARAMETER_SELECTION_MODE: {
302
+ return state.merge({ paramEditMode: payload.mode });
303
+ }
304
+ default:
305
+ return state;
306
+ }
307
+ };
308
+
309
+ export default applicationInstanceConf;