foreman_acd 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -3
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +17 -2
  4. data/app/controllers/foreman_acd/app_definitions_controller.rb +104 -7
  5. data/app/controllers/foreman_acd/app_instances_controller.rb +15 -30
  6. data/app/controllers/foreman_acd/concerns/app_instance_mixins.rb +36 -0
  7. data/app/controllers/ui_acd_controller.rb +38 -1
  8. data/app/lib/actions/foreman_acd/run_configurator.rb +1 -0
  9. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +15 -27
  10. data/app/models/foreman_acd/app_instance.rb +47 -2
  11. data/app/models/foreman_acd/foreman_host.rb +8 -0
  12. data/app/services/foreman_acd/app_deployer.rb +19 -2
  13. data/app/services/foreman_acd/inventory_creator.rb +11 -1
  14. data/app/views/foreman_acd/app_definitions/import.html.erb +20 -1
  15. data/app/views/foreman_acd/app_definitions/index.html.erb +3 -6
  16. data/app/views/foreman_acd/app_instances/index.html.erb +15 -11
  17. data/app/views/foreman_acd/app_instances/report.html.erb +7 -2
  18. data/app/views/ui_acd/host_report.json.rabl +4 -0
  19. data/app/views/ui_acd/report_data.json.rabl +10 -0
  20. data/app/views/ui_acd/validate_hostname.json.rabl +6 -0
  21. data/config/routes.rb +3 -0
  22. data/db/migrate/20210818125913_add_is_existing_host_to_foreman_host.rb +8 -0
  23. data/db/migrate/20210902110645_add_initial_configure_task.rb +8 -0
  24. data/lib/foreman_acd/plugin.rb +6 -6
  25. data/lib/foreman_acd/version.rb +1 -1
  26. data/lib/foreman_acd.rb +27 -9
  27. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  28. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +28 -9
  29. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +6 -0
  30. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +1 -0
  31. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +30 -9
  32. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +3 -0
  33. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +1 -0
  34. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +30 -5
  35. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +1 -1
  36. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +3 -3
  37. data/webpack/components/ApplicationDefinition/index.js +6 -0
  38. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.js +214 -0
  39. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.scss +1 -0
  40. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportActions.js +161 -0
  41. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportConstants.js +6 -0
  42. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportReducer.js +79 -0
  43. data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportSelectors.js +8 -0
  44. data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportConfData_1.fixtures.js +129 -0
  45. data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportReducer.fixtures.js +29 -0
  46. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImport.test.js +20 -0
  47. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportReducer.test.js +43 -0
  48. data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportSelectors.test.js +29 -0
  49. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImport.test.js.snap +62 -0
  50. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportReducer.test.js.snap +362 -0
  51. data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportSelectors.test.js.snap +130 -0
  52. data/webpack/components/ApplicationDefinitionImport/index.js +32 -0
  53. data/webpack/components/ApplicationInstance/ApplicationInstance.js +96 -25
  54. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +112 -6
  55. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +4 -0
  56. data/webpack/components/ApplicationInstance/ApplicationInstanceHelper.js +15 -0
  57. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +71 -30
  58. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +3 -0
  59. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +2 -0
  60. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +1 -0
  61. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +12 -0
  62. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +97 -7
  63. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +271 -0
  64. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +1 -0
  65. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +1 -1
  66. data/webpack/components/ApplicationInstance/helper.js +0 -0
  67. data/webpack/components/ApplicationInstance/index.js +6 -0
  68. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +81 -6
  69. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +35 -1
  70. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +3 -0
  71. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +19 -0
  72. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
  73. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +1 -124
  74. data/webpack/components/ApplicationInstanceReport/index.js +8 -1
  75. data/webpack/components/ExistingHostSelection/ExistingHostSelection.js +104 -0
  76. data/webpack/components/ExistingHostSelection/ExistingHostSelection.scss +15 -0
  77. data/webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js +71 -0
  78. data/webpack/components/ExistingHostSelection/ExistingHostSelectionConstants.js +4 -0
  79. data/webpack/components/ExistingHostSelection/ExistingHostSelectionHelper.js +0 -0
  80. data/webpack/components/ExistingHostSelection/ExistingHostSelectionReducer.js +90 -0
  81. data/webpack/components/ExistingHostSelection/ExistingHostSelectionSelectors.js +8 -0
  82. data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionConfData_1.fixtures.js +191 -0
  83. data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionReducer.fixtures.js +203 -0
  84. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelection.test.js +19 -0
  85. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionReducer.test.js +59 -0
  86. data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionSelectors.test.js +36 -0
  87. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelection.test.js.snap +35 -0
  88. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionReducer.test.js.snap +614 -0
  89. data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionSelectors.test.js.snap +27 -0
  90. data/webpack/components/ExistingHostSelection/components/ServiceSelector.js +48 -0
  91. data/webpack/components/ExistingHostSelection/components/__tests__/ServiceSelector.test.js +35 -0
  92. data/webpack/components/ExistingHostSelection/components/__tests__/__snapshots__/ServiceSelector.test.js.snap +77 -0
  93. data/webpack/components/ExistingHostSelection/index.js +26 -0
  94. data/webpack/components/ParameterSelection/ParameterSelection.js +98 -1
  95. data/webpack/components/ParameterSelection/ParameterSelection.scss +7 -0
  96. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +36 -2
  97. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +2 -0
  98. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +49 -8
  99. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +1 -0
  100. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +2 -0
  101. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +96 -0
  102. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +5 -0
  103. data/webpack/components/ParameterSelection/index.js +2 -1
  104. data/webpack/components/SyncGitRepo/SyncGitRepo.js +2 -10
  105. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +1 -2
  106. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +0 -1
  107. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +1 -0
  108. data/webpack/components/SyncGitRepo/components/FormTextInput.js +1 -1
  109. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +3 -2
  110. data/webpack/components/common/DeleteTableEntry.js +16 -2
  111. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +38 -0
  112. data/webpack/helper.js +5 -0
  113. data/webpack/index.js +5 -0
  114. data/webpack/js-yaml.js +3874 -0
  115. data/webpack/reducer.js +13 -2
  116. metadata +46 -2
@@ -0,0 +1,214 @@
1
+ import React, { useState } from 'react';
2
+ import {
3
+ cloneDeep,
4
+ } from 'lodash';
5
+ import PropTypes from 'prop-types';
6
+ import {
7
+ Icon,
8
+ Button,
9
+ MessageDialog,
10
+ } from 'patternfly-react';
11
+ import * as resolve from 'table-resolver';
12
+ import Select from 'foremanReact/components/common/forms/Select';
13
+ import CommonForm from 'foremanReact/components/common/forms/CommonForm';
14
+ import AddTableEntry from '../common/AddTableEntry';
15
+ import DeleteTableEntry from '../common/DeleteTableEntry';
16
+ import RailsData from '../common/RailsData';
17
+ import { EasyHeaderFormatter } from '../../helper';
18
+ import { translate as __ } from 'foremanReact/common/I18n';
19
+
20
+ import {
21
+ Table,
22
+ FormControl,
23
+ inlineEditFormatterFactory,
24
+ } from 'patternfly-react';
25
+
26
+ class ApplicationDefinitionImport extends React.Component {
27
+
28
+ constructor(props) {
29
+ super(props);
30
+ }
31
+
32
+ onFileChange = event => {
33
+ // Update the state
34
+ this.setState({ selectedFile: event.target.files[0] });
35
+
36
+ };
37
+
38
+ isEditing({rowData}) {
39
+ return (rowData.backup !== undefined);
40
+ }
41
+
42
+ setAnsiblePlaybookServices() {
43
+ this.setState({ansiblePlaybookServices: this.props.ansiblePlaybookServices});
44
+ }
45
+
46
+ componentDidMount() {
47
+ const {
48
+ mode,
49
+ ansiblePlaybookServices,
50
+ hostgroups, } = this.props;
51
+
52
+ const {
53
+ initApplicationDefinitionImport,
54
+ changeEditApplicationDefinitionImportService,
55
+ handleImportAnsiblePlaybook,
56
+ } = this.props;
57
+
58
+ this.headerFormatter = EasyHeaderFormatter;
59
+
60
+ const inlineEditFormatterImpl = {
61
+ renderValue: (value, additionalData) => (
62
+ <td>
63
+ <span className="static">{value}</span>
64
+ </td>
65
+ ),
66
+ renderEditSelect: (value, additionalData, options) => (
67
+ <td className="editing">
68
+ <Select
69
+ value={value.toString()}
70
+ onChange={e => changeEditApplicationDefinitionImportService(e.target.value, additionalData) }
71
+ options={options}
72
+ allowClear
73
+ key="key"
74
+ />
75
+ </td>
76
+ )
77
+ };
78
+
79
+ const inlineEditFormatter = inlineEditFormatterFactory({
80
+ isEditing: additionalData => this.isEditing(additionalData),
81
+ renderValue: (value, additionalData) => {
82
+ let prettyValue = value;
83
+ if (additionalData.property == 'hostgroup') {
84
+ prettyValue = hostgroups[value];
85
+ }
86
+ return inlineEditFormatterImpl.renderValue(prettyValue, additionalData)
87
+ },
88
+ renderEdit: (value, additionalData) => {
89
+ if (additionalData.property == 'hostgroup') {
90
+ if (additionalData.rowData) {
91
+ return inlineEditFormatterImpl.renderEditSelect(value, additionalData, hostgroups);
92
+ }
93
+ return inlineEditFormatterImpl.renderValue(hostgroups[value], additionalData)
94
+ }
95
+ return inlineEditFormatterImpl.renderValue(value, additionalData);
96
+ }
97
+ });
98
+ this.inlineEditFormatter = inlineEditFormatter;
99
+
100
+ initApplicationDefinitionImport(
101
+ ansiblePlaybookServices,
102
+ this.headerFormatter,
103
+ this.inlineEditFormatter,
104
+ );
105
+ };
106
+
107
+ render() {
108
+ const {
109
+ organization,
110
+ location,
111
+ foremanDataUrl,
112
+ mode,} = this.props;
113
+
114
+ const {
115
+ showAlertModal,
116
+ alertModalText,
117
+ alertModalTitle,
118
+ closeAlertModal,
119
+ ansiblePlaybookServices,
120
+ columns,
121
+ handleImportAnsiblePlaybook,
122
+ } = this.props;
123
+ let ansibleServices;
124
+
125
+ return (
126
+ <span>
127
+ {ansibleServices = this.setAnsiblePlaybookServices}
128
+ {ansibleServices}
129
+ <MessageDialog
130
+ show={showAlertModal}
131
+ onHide={closeAlertModal}
132
+ primaryAction={closeAlertModal}
133
+ primaryActionButtonContent={__('OK')}
134
+ primaryActionButtonBsStyle={"danger"}
135
+ icon={<Icon type="pf" name="error-circle-o" />}
136
+ title={alertModalTitle}
137
+ primaryContent={alertModalText}
138
+ />
139
+ <div>
140
+ <CommonForm label="Application Definition file" className="custom-file-upload">
141
+ <input
142
+ type="file"
143
+ onChange={this.onFileChange}
144
+ />
145
+ </CommonForm>
146
+ <CommonForm>
147
+ <Button
148
+ bsStyle="default"
149
+ onClick={e => handleImportAnsiblePlaybook(this.state.selectedFile, e)}
150
+ >
151
+ {__('Import')} </Button>
152
+ </CommonForm>
153
+ </div>
154
+
155
+ {(Object.keys(this.props.ansiblePlaybookServices).length > 0) ? (
156
+ <div className="form-group">
157
+ <Table.PfProvider
158
+ striped
159
+ bordered
160
+ hover
161
+ dataTable
162
+ columns={columns}
163
+ components={{
164
+ body: {
165
+ cell: cellProps => cellProps.children
166
+ }
167
+ }}
168
+ >
169
+ <Table.Header headerRows={resolve.headerRows({ columns })} />
170
+ <Table.Body
171
+ rows={this.props.ansiblePlaybookServices}
172
+ rowKey="id"
173
+ onRow={(rowData, { rowIndex }) => ({
174
+ role: 'row',
175
+ isEditing: () => this.isEditing({ rowData }),
176
+ last: rowIndex === this.props.ansiblePlaybookServices.length - 1
177
+ })}
178
+ />
179
+ </Table.PfProvider>
180
+ </div>) : null }
181
+ <RailsData
182
+ key='applications_definition_import'
183
+ view='app_definition_import'
184
+ parameter='services'
185
+ value={JSON.stringify(this.props.ansiblePlaybookServices)}
186
+ />
187
+ </span>
188
+ )};
189
+ }
190
+
191
+ ApplicationDefinitionImport.defaultProps = {
192
+ error: {},
193
+ showAlertModal: false,
194
+ alertModalText: '',
195
+ alertModalTitle: '',
196
+ editMode: false,
197
+ columns: [],
198
+ ansiblePlaybookServices: {},
199
+ editParamsOfRowId: null,
200
+ }
201
+
202
+ ApplicationDefinitionImport.propTypes = {
203
+ initApplicationDefinitionImport: PropTypes.func,
204
+ editMode: PropTypes.bool.isRequired,
205
+ columns: PropTypes.array,
206
+ showAlertModal: PropTypes.bool,
207
+ alertModalText: PropTypes.string,
208
+ alertModalTitle: PropTypes.string,
209
+ closeAlertModal: PropTypes.func,
210
+ handleImportAnsiblePlaybook: PropTypes.func,
211
+ changeEditApplicationDefinitionImportService: PropTypes.func,
212
+ };
213
+
214
+ export default ApplicationDefinitionImport;
@@ -0,0 +1 @@
1
+ @import '~@theforeman/vendor/scss/variables';
@@ -0,0 +1,161 @@
1
+ import React from 'react';
2
+ import { API, actionTypeGenerator } from 'foremanReact/redux/API';
3
+ import { addToast } from 'foremanReact/redux/actions/toasts';
4
+ import { sprintf, translate as __ } from 'foremanReact/common/I18n';
5
+
6
+
7
+ import {
8
+ setModalOpen,
9
+ setModalClosed,
10
+ } from 'foremanReact/components/ForemanModal/ForemanModalActions';
11
+
12
+ import {
13
+ actionHeaderCellFormatter,
14
+ } from 'patternfly-react';
15
+
16
+ import {
17
+ propsToSnakeCase,
18
+ propsToCamelCase,
19
+ } from 'foremanReact/common/helpers';
20
+
21
+ import {
22
+ APPLICATION_DEFINITION_IMPORT_INIT,
23
+ APPLICATION_DEFINITION_IMPORT_CLOSE_ALERT_MODAL,
24
+ APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE,
25
+ APPLICATION_DEFINITION_IMPORT_FILE_REQUEST,
26
+ APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS,
27
+ APPLICATION_DEFINITION_IMPORT_FILE_FAILURE,
28
+ } from './ApplicationDefinitionImportConstants';
29
+
30
+
31
+ export const initApplicationDefinitionImport = (
32
+ ansiblePlaybookServices,
33
+ headerFormatter,
34
+ inlineEditFormatter,
35
+ ) => dispatch => {
36
+ const initialState = {};
37
+
38
+ initialState.columns = [
39
+ {
40
+ property: 'name',
41
+ header: {
42
+ label: 'Service name',
43
+ formatters: [headerFormatter],
44
+ props: {
45
+ index: 0,
46
+ style: {
47
+ width: '20%'
48
+ }
49
+ },
50
+ },
51
+ cell: {
52
+ props: {
53
+ index: 0,
54
+ },
55
+ formatters: [inlineEditFormatter]
56
+ }
57
+ },
58
+ {
59
+ property: 'hostgroup',
60
+ header: {
61
+ label: 'Hostgroup',
62
+ formatters: [headerFormatter],
63
+ props: {
64
+ index: 1,
65
+ style: {
66
+ width: '20%'
67
+ }
68
+ },
69
+ },
70
+ cell: {
71
+ props: {
72
+ index: 1,
73
+ },
74
+ formatters: [inlineEditFormatter]
75
+ }
76
+ }
77
+ ];
78
+
79
+ initialState.ansiblePlaybookServices = ansiblePlaybookServices;
80
+
81
+ dispatch({
82
+ type: APPLICATION_DEFINITION_IMPORT_INIT,
83
+ payload: initialState,
84
+ });
85
+ };
86
+
87
+
88
+ const errorHandler = (msg, err) => {
89
+ const error = {
90
+ errorMsg: __('Failed to fetch data from server.'),
91
+ statusText: err,
92
+ };
93
+ return { type: msg, payload: { error } };
94
+ };
95
+
96
+ export const closeAlertModal = () => ({
97
+ type: APPLICATION_DEFINITION_IMPORT_CLOSE_ALERT_MODAL,
98
+ payload: {}
99
+ });
100
+
101
+ export const changeEditApplicationDefinitionImportService = (value, additionalData) => ({
102
+ type: APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE,
103
+ payload: {
104
+ value,
105
+ ...additionalData,
106
+ },
107
+ });
108
+
109
+
110
+ export const handleImportAnsiblePlaybook = (
111
+ file, e,) => async dispatch => {
112
+ e.preventDefault();
113
+ dispatch({
114
+ type: APPLICATION_DEFINITION_IMPORT_FILE_REQUEST,
115
+ payload: {
116
+ app_definition_file: file,
117
+ }});
118
+ try {
119
+ const formData = new FormData();
120
+
121
+ // Update the formData object
122
+ formData.append(
123
+ "app_definition_file",
124
+ file,
125
+ file.name
126
+ );
127
+ const { data } = await API.post(
128
+ '/acd/app_definitions/handle_file_upload', formData);
129
+ dispatch(
130
+ addToast({
131
+ type: 'success',
132
+ message: sprintf(
133
+ __('Sucessfully synced imported app template')
134
+ ),
135
+ key: APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS,
136
+ })
137
+ );
138
+ return dispatch({
139
+ type: APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS,
140
+ payload: {
141
+ ansiblePlaybookServices: data,
142
+ },
143
+ response: data,
144
+ });
145
+ } catch (error) {
146
+ dispatch(
147
+ addToast({
148
+ type: 'error',
149
+ message: sprintf(__('Error occurred while importing app template: %s'), error.response.data.message),
150
+ key: APPLICATION_DEFINITION_IMPORT_FILE_FAILURE,
151
+ })
152
+ );
153
+ return dispatch({
154
+ type: APPLICATION_DEFINITION_IMPORT_FILE_FAILURE,
155
+ payload: {
156
+ error: error,
157
+ },
158
+ response: error,
159
+ });
160
+ }
161
+ };
@@ -0,0 +1,6 @@
1
+ export const APPLICATION_DEFINITION_IMPORT_INIT = 'INIT_APPLICATION_DEFINITION_IMPORT_INIT';
2
+ export const APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE = 'APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE';
3
+ export const APPLICATION_DEFINITION_IMPORT_FILE_FAILURE = 'APPLICATION_DEFINITION_IMPORT_FILE_FAILURE';
4
+ export const APPLICATION_DEFINITION_IMPORT_FILE_REQUEST = 'APPLICATION_DEFINITION_IMPORT_FILE_REQUEST';
5
+ export const APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS = 'APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS';
6
+ export const APPLICATION_DEFINITION_IMPORT_CLOSE_ALERT_MODAL = 'APPLICATION_DEFINITION_IMPORT_CLOSE_ALERT_MODAL';
@@ -0,0 +1,79 @@
1
+ import Immutable from 'seamless-immutable';
2
+
3
+ import {
4
+ cloneDeep,
5
+ findIndex,
6
+ findLastIndex,
7
+ } from 'lodash';
8
+
9
+ import { translate as __ } from 'foremanReact/common/I18n';
10
+
11
+ import {
12
+ APPLICATION_DEFINITION_IMPORT_INIT,
13
+ APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE,
14
+ APPLICATION_DEFINITION_IMPORT_FILE_FAILURE,
15
+ APPLICATION_DEFINITION_IMPORT_FILE_REQUEST,
16
+ APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS,
17
+ APPLICATION_DEFINITION_IMPORT_CLOSE_ALERT_MODAL,
18
+ } from './ApplicationDefinitionImportConstants';
19
+
20
+ export const initialState = Immutable({
21
+ name: false,
22
+ error: { errorMsg: '', status: '', statusText: '' },
23
+ });
24
+
25
+ const applicationDefinitionImportConf = (state = initialState, action) => {
26
+ const { payload } = action;
27
+
28
+ switch (action.type) {
29
+ case APPLICATION_DEFINITION_IMPORT_INIT: {
30
+ return state.merge(payload);
31
+ }
32
+
33
+ case APPLICATION_DEFINITION_IMPORT_CLOSE_ALERT_MODAL: {
34
+ return state.merge({
35
+ showAlertModal: false,
36
+ alertModalTitle: '',
37
+ alertModalText: '',
38
+ });
39
+ }
40
+
41
+ case APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE: {
42
+ const services = cloneDeep(state.ansiblePlaybookServices);
43
+ const index = findIndex(services, { id: payload.rowData.id });
44
+
45
+ services[index][payload.property] = payload.value;
46
+
47
+ return state.set('ansiblePlaybookServices', services);
48
+ }
49
+
50
+ case APPLICATION_DEFINITION_IMPORT_FILE_FAILURE: {
51
+ return state.merge({ error: payload.error, loading: false });
52
+ }
53
+ case APPLICATION_DEFINITION_IMPORT_FILE_REQUEST: {
54
+ return state.set('loading', true);
55
+ }
56
+ case APPLICATION_DEFINITION_IMPORT_FILE_SUCCESS: {
57
+ let newState = {};
58
+ let ansibleServices = [];
59
+ const ansiblePlaybookServices = payload.ansiblePlaybookServices['ansible_services'];
60
+
61
+ for (var ind in ansiblePlaybookServices) {
62
+ const value = ansiblePlaybookServices[ind];
63
+ const newRow = { id: value['id'], name: value['value'], hostgroup: '' };
64
+ newRow.backup = cloneDeep(newRow);
65
+ ansibleServices.push(newRow);
66
+ }
67
+
68
+ newState = {
69
+ ansiblePlaybookServices: ansibleServices,
70
+ };
71
+
72
+ return state.merge(newState);
73
+ }
74
+ default:
75
+ return state;
76
+ }
77
+ };
78
+
79
+ export default applicationDefinitionImportConf;
@@ -0,0 +1,8 @@
1
+ const applicationDefinitionImportConf = state => state.foremanAcd.applicationDefinitionImportConf;
2
+
3
+ export const selectEditMode = state => applicationDefinitionImportConf(state).editMode;
4
+ export const selectColumns = state => applicationDefinitionImportConf(state).columns;
5
+ export const selectAnsiblePlaybookServices = state => applicationDefinitionImportConf(state).ansiblePlaybookServices;
6
+ export const selectShowAlertModal = state => applicationDefinitionImportConf(state).showAlertModal;
7
+ export const selectAlertModalText = state => applicationDefinitionImportConf(state).alertModalText;
8
+ export const selectAlertModalTitle = state => applicationDefinitionImportConf(state).alertModalTitle;
@@ -0,0 +1,129 @@
1
+ export const applicationDefinitionImportConfData_1 = {
2
+ name: false,
3
+ error: {
4
+ errorMsg: '',
5
+ status: '',
6
+ statusText: ''
7
+ },
8
+ columns: [
9
+ {
10
+ property: 'name',
11
+ header: {
12
+ label: 'Service name',
13
+ formatters: [
14
+ null
15
+ ],
16
+ props: {
17
+ index: 3,
18
+ style: {
19
+ width: '20%'
20
+ }
21
+ }
22
+ },
23
+ cell: {
24
+ formatters: [
25
+ null
26
+ ]
27
+ }
28
+ },
29
+ {
30
+ property: 'hostgroup',
31
+ header: {
32
+ label: 'Hostgroup',
33
+ formatters: [
34
+ null
35
+ ],
36
+ props: {
37
+ index: 2,
38
+ style: {
39
+ width: '20%'
40
+ }
41
+ }
42
+ },
43
+ cell: {
44
+ formatters: [
45
+ null
46
+ ]
47
+ }
48
+ }
49
+ ],
50
+ ansiblePlaybookServices: [
51
+ {
52
+ id: 1,
53
+ name: 'web',
54
+ description: '',
55
+ hostgroup: '1',
56
+ ansibleGroup: 'webservers',
57
+ minCount: '2',
58
+ maxCount: '',
59
+ foremanParameters: [
60
+ {
61
+ id: 1,
62
+ locked: false,
63
+ name: 'CP',
64
+ description: '',
65
+ type: 'computeprofile',
66
+ value: '1'
67
+ },
68
+ {
69
+ id: 2,
70
+ locked: true,
71
+ name: 'LE',
72
+ description: '',
73
+ type: 'lifecycleenv',
74
+ value: '1'
75
+ }
76
+ ],
77
+ ansibleParameters: [
78
+ {
79
+ id: 0,
80
+ name: 'dummy_var',
81
+ value: '0'
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ id: 2,
87
+ name: 'db',
88
+ description: '',
89
+ hostgroup: '1',
90
+ ansibleGroup: 'dbservers',
91
+ minCount: '1',
92
+ maxCount: '',
93
+ foremanParameters: [],
94
+ ansibleParameters: [
95
+ {
96
+ id: 0,
97
+ name: 'mysqlservice',
98
+ value: 'mysqld'
99
+ },
100
+ {
101
+ id: 1,
102
+ name: 'mysql_port',
103
+ value: '3306',
104
+ locked: true
105
+ },
106
+ {
107
+ id: 2,
108
+ name: 'dbuser',
109
+ value: 'webapp'
110
+ },
111
+ {
112
+ id: 3,
113
+ name: 'dbname',
114
+ value: 'ANSAP01'
115
+ },
116
+ {
117
+ id: 4,
118
+ name: 'upassword',
119
+ value: 'Bond@007'
120
+ },
121
+ {
122
+ id: 5,
123
+ name: 'masterpassword',
124
+ value: 'MySQL@007'
125
+ }
126
+ ]
127
+ }
128
+ ]
129
+ }
@@ -0,0 +1,29 @@
1
+ import Immutable from 'seamless-immutable';
2
+ import {
3
+ cloneDeep,
4
+ findIndex,
5
+ findLastIndex,
6
+ } from 'lodash';
7
+
8
+ import {
9
+ applicationDefinitionImportConfData_1,
10
+ } from '../__fixtures__/applicationDefinitionImportConfData_1.fixtures';
11
+
12
+ export const successState = Immutable(applicationDefinitionImportConfData_1);
13
+
14
+ const EDIT_ROW_ID = 2;
15
+
16
+ const editClone = applicationDefinitionImportConfData_1;
17
+ const editIndex = findIndex(editClone.ansiblePlaybookServices, { id: EDIT_ROW_ID })
18
+ editClone["ansiblePlaybookServices"][editIndex].backup = cloneDeep(editClone["ansiblePlaybookServices"][editIndex]);
19
+ export const editState = Immutable(editClone);
20
+
21
+ // Payload Data
22
+ export const initApplicationDefinitionImportPayload = applicationDefinitionImportConfData_1;
23
+ export const changeEditServicePayload = {
24
+ value: "helloworld",
25
+ property: "name",
26
+ rowData: {
27
+ id: EDIT_ROW_ID,
28
+ }
29
+ };
@@ -0,0 +1,20 @@
1
+ import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
2
+
3
+ import ApplicationDefinitionImport from '../ApplicationDefinitionImport';
4
+
5
+ const noop = () => {};
6
+
7
+ const fixtures = {
8
+ 'should render application definition import': {
9
+ location: "Default Location",
10
+ organization: "Default Organization",
11
+ hostgroups: [],
12
+ ansiblePlaybookServices: [],
13
+ initApplicationDefinitionImport: noop,
14
+ addApplicationDefinitionImportService: noop,
15
+ closeAlertModal: noop,
16
+ },
17
+ };
18
+
19
+ describe('ApplicationDefinitionImport', () =>
20
+ testComponentSnapshotsWithFixtures(ApplicationDefinitionImport, fixtures));
@@ -0,0 +1,43 @@
1
+ import { testReducerSnapshotWithFixtures } from 'react-redux-test-utils';
2
+ import reducer, { initialState } from '../ApplicationDefinitionImportReducer';
3
+
4
+ import {
5
+ successState,
6
+ editState,
7
+ initApplicationDefinitionImportPayload,
8
+ changeEditServicePayload,
9
+ } from '../__fixtures__/applicationDefinitionImportReducer.fixtures';
10
+
11
+ import {
12
+ APPLICATION_DEFINITION_IMPORT_INIT,
13
+ APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE,
14
+ APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CANCEL,
15
+ } from '../ApplicationDefinitionImportConstants';
16
+
17
+ const fixtures = {
18
+ 'should return initial state': {
19
+ state: initialState,
20
+ action: {
21
+ type: undefined,
22
+ payload: {},
23
+ },
24
+ },
25
+
26
+ 'should initialize component': {
27
+ state: initialState,
28
+ action: {
29
+ type: APPLICATION_DEFINITION_IMPORT_INIT,
30
+ payload: initApplicationDefinitionImportPayload,
31
+ },
32
+ },
33
+ 'should change edit service': {
34
+ state: editState,
35
+ action: {
36
+ type: APPLICATION_DEFINITION_IMPORT_SERVICE_EDIT_CHANGE,
37
+ payload: changeEditServicePayload,
38
+ },
39
+ },
40
+ };
41
+
42
+ describe('ApplicationDefinitionImportReducer', () =>
43
+ testReducerSnapshotWithFixtures(reducer, fixtures));