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,10 @@
1
+ const applicationInstanceConf = state => state.foremanAcd.applicationInstanceConf;
2
+
3
+ export const selectEditMode = state => applicationInstanceConf(state).editMode;
4
+ export const selectAppDefinition = state => applicationInstanceConf(state).appDefinition;
5
+ export const selectHosts = state => applicationInstanceConf(state).hosts;
6
+ export const selectColumns = state => applicationInstanceConf(state).columns;
7
+ export const selectServices = state => applicationInstanceConf(state).services;
8
+ export const selectParametersData = state => applicationInstanceConf(state).parametersData;
9
+ export const selectAnsibleVarsAll = state => applicationInstanceConf(state).ansibleVarsAll;
10
+ export const selectParamEditMode = state => applicationInstanceConf(state).paramEditMode;
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ExtSelect from '../../common/ExtSelect';
4
+ import RailsData from '../../common/RailsData'
5
+
6
+ const AppDefinitionSelector= ({
7
+ label,
8
+ hidden,
9
+ editable,
10
+ viewText,
11
+ selectValue,
12
+ onChange,
13
+ options,
14
+ additionalData,
15
+ }) =>{
16
+ return (
17
+ <div className="form-group">
18
+ <label className="col-md-2 control-label">{label}</label>
19
+ <div className="col-md-4">
20
+ <ExtSelect
21
+ editable={editable}
22
+ viewText={viewText}
23
+ selectValue={selectValue}
24
+ onChange={onChange}
25
+ options={options}
26
+ additionalData={additionalData}
27
+ />
28
+ <RailsData
29
+ key='app_instance_id'
30
+ view='app_instance'
31
+ parameter='app_definition_id'
32
+ value={selectValue}
33
+ />
34
+ </div>
35
+ </div>
36
+ );
37
+ };
38
+
39
+ AppDefinitionSelector.propTypes = {
40
+ label: PropTypes.string.isRequired,
41
+ editable: PropTypes.bool.isRequired,
42
+ viewText: PropTypes.string,
43
+ selectValue: PropTypes.string,
44
+ onChange: PropTypes.func.isRequired,
45
+ options: PropTypes.object,
46
+ additionalData: PropTypes.object,
47
+ };
48
+
49
+ export default AppDefinitionSelector;
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ const Service= ({
5
+ name,
6
+ currentCount,
7
+ minCount,
8
+ maxCount,
9
+ }) =>{
10
+ return (
11
+ <div>
12
+ <label>{name}:</label> {currentCount} ({__("Min/Max")}: {minCount}/{maxCount})
13
+ </div>
14
+ );
15
+ };
16
+
17
+ Service.defaultProps = {
18
+ minCount: 0,
19
+ maxCount: 0,
20
+ currentCount: 0,
21
+ };
22
+
23
+ Service.propTypes = {
24
+ name: PropTypes.string.isRequired,
25
+ minCount: PropTypes.number.isRequired,
26
+ maxCount: PropTypes.number.isRequired,
27
+ currentCount: PropTypes.number.isRequired,
28
+ };
29
+
30
+ export default Service;
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Service from './Service';
4
+ import { arrayToObjectObj } from '../../../helper';
5
+ import { cloneDeep } from 'lodash';
6
+
7
+ const ServiceCounter= ({
8
+ title,
9
+ serviceList,
10
+ }) =>{
11
+ if (serviceList == undefined || serviceList.length == 0) {
12
+ return null;
13
+ }
14
+ const services = cloneDeep(arrayToObjectObj(serviceList, "id"));
15
+
16
+ return (
17
+ <div>
18
+ <label class="service-counter-title">{title}</label>
19
+ {Object.keys(services).map(key => (
20
+ <Service
21
+ key={services[key].id}
22
+ name={services[key].name}
23
+ currentCount={services[key].currentCount}
24
+ minCount={Number(services[key].minCount)}
25
+ maxCount={Number(services[key].maxCount)}
26
+ />)
27
+ )}
28
+ </div>
29
+ );
30
+ };
31
+
32
+ ServiceCounter.propTypes = {
33
+ title: PropTypes.string.isRequired,
34
+ serviceList: PropTypes.array,
35
+ };
36
+
37
+ export default ServiceCounter;
@@ -0,0 +1,37 @@
1
+ import { bindActionCreators } from 'redux';
2
+ import { connect } from 'react-redux';
3
+
4
+ import './ApplicationInstance.scss';
5
+ import ApplicationInstance from './ApplicationInstance';
6
+ import * as ApplicationInstanceActions from './ApplicationInstanceActions';
7
+
8
+ import {
9
+ selectEditMode,
10
+ selectAppDefinition,
11
+ selectHosts,
12
+ selectServices,
13
+ selectColumns,
14
+ selectParametersData,
15
+ selectAnsibleVarsAll,
16
+ selectParamEditMode,
17
+ } from './ApplicationInstanceSelectors';
18
+
19
+ const mapStateToProps = state => ({
20
+ editMode: selectEditMode(state),
21
+ appDefinition: selectAppDefinition(state),
22
+ hosts: selectHosts(state),
23
+ services: selectServices(state),
24
+ columns: selectColumns(state),
25
+ parametersData: selectParametersData(state),
26
+ ansibleVarsAll: selectAnsibleVarsAll(state),
27
+ paramEditMode: selectParamEditMode(state),
28
+ });
29
+
30
+ const mapDispatchToProps = dispatch =>
31
+ bindActionCreators(ApplicationInstanceActions, dispatch);
32
+
33
+ export default connect(
34
+ mapStateToProps,
35
+ mapDispatchToProps
36
+ )(ApplicationInstance);
37
+
@@ -0,0 +1,148 @@
1
+ import React, { useState } from 'react'
2
+ import PropTypes from 'prop-types';
3
+
4
+ import {
5
+ VerticalTabs,
6
+ } from 'patternfly-react-extensions';
7
+
8
+ import {
9
+ translate as __
10
+ } from 'foremanReact/common/I18n';
11
+
12
+ import PowerStatus from 'foremanReact/components/hosts/powerStatus';
13
+ import ReportViewer from './components/ReportViewer';
14
+
15
+ class ApplicationInstanceReport extends React.Component {
16
+
17
+ constructor(props) {
18
+ super(props);
19
+ }
20
+
21
+ componentDidMount() {
22
+ const {
23
+ data: { hosts, mode },
24
+ initApplicationInstanceReport,
25
+ setActiveHost,
26
+ } = this.props;
27
+
28
+ initApplicationInstanceReport(hosts);
29
+ };
30
+
31
+ isActive(id) {
32
+ return (this.props.activeHostId === id);
33
+ }
34
+
35
+ collectLastReportData(hosts) {
36
+ const {
37
+ setActiveHost,
38
+ } = this.props;
39
+
40
+ const tabs = []
41
+ for (const [index, value] of hosts.entries()) {
42
+ tabs.push(
43
+ <VerticalTabs.Tab
44
+ id={index}
45
+ key={"vt_tab_"+index}
46
+ title={ value.name }
47
+ wrapStyle='nowrap'
48
+ onActivate={() => setActiveHost(index)}
49
+ active={this.isActive(index)}
50
+ />
51
+ );
52
+ }
53
+
54
+ return tabs;
55
+ }
56
+
57
+ lastReportStatus(host) {
58
+ if (!host['id']) {
59
+ return (
60
+ <div>
61
+ <span>Host: { host['name'] }</span>
62
+ <span>&nbsp;|&nbsp;</span>
63
+ <span>State: { __('not build') }</span>
64
+ <span>&nbsp;|&nbsp;</span>
65
+ <span>Power Status: { __('unknown') }</span>
66
+ </div>
67
+ )
68
+ } else {
69
+ return (
70
+ <div>
71
+ <span>Host: <a href={ host['hostUrl'] }>{ host['name'] }</a></span>
72
+ <span>&nbsp;|&nbsp;</span>
73
+ <span>State: { host['build'] == true ? "in Build" : "Deployed" }</span>
74
+ <span>&nbsp;|&nbsp;</span>
75
+ <span>Power Status: <PowerStatus key={ "power_status_"+ host['id'] } data={{ id: host['id'], url: host['powerStatusUrl'] }} /></span>
76
+ </div>
77
+ )
78
+ }
79
+ }
80
+
81
+ render() {
82
+ const {
83
+ data: { hosts, mode, appInstanceName, deployTaskUrl, configureJobUrl },
84
+ activeHostId,
85
+ } = this.props;
86
+
87
+ let tabs = [];
88
+ let reportStatus = undefined;
89
+ let report = undefined;
90
+
91
+ tabs = this.collectLastReportData(hosts);
92
+ reportStatus = this.lastReportStatus(hosts[activeHostId]);
93
+
94
+ if (hosts[activeHostId]['progress_report']) {
95
+ report = hosts[activeHostId]['progress_report'];
96
+ }
97
+
98
+ return (
99
+ <span>
100
+ <div className="deploy_status">
101
+ <div>
102
+ <div className="deploy_status_head">Deployment task</div>
103
+ <div className="deploy_status_content"><a href={ deployTaskUrl } >Last deployment task</a></div>
104
+ </div>
105
+ <div>
106
+ <div className="deploy_status_head">Configuration job</div>
107
+ <div className="deploy_status_content"><a href={ configureJobUrl }>Configuration jobs</a></div>
108
+ </div>
109
+ </div>
110
+ <div className="deploy_report_hosts">
111
+ Hosts
112
+ <VerticalTabs id="vertical_tabs">
113
+ {tabs}
114
+ </VerticalTabs>
115
+ </div>
116
+ <div className="deploy_report_status">
117
+ {reportStatus}
118
+ </div>
119
+ <div className="deploy_report_tasks">
120
+ <ReportViewer report={report} />
121
+ </div>
122
+ </span>
123
+ )};
124
+ }
125
+
126
+ ApplicationInstanceReport.defaultProps = {
127
+ error: {},
128
+ appInstanceName: '',
129
+ deployTaskUrl: '',
130
+ configureJobUrl: '',
131
+ hosts: [],
132
+ report: [],
133
+ activeHostId: 0,
134
+ }
135
+
136
+ ApplicationInstanceReport.propTypes = {
137
+ initApplicationInstanceReport: PropTypes.func,
138
+ appInstanceName: PropTypes.string,
139
+ deployTaskUrl: PropTypes.string,
140
+ configureJobUrl: PropTypes.string,
141
+ hosts: PropTypes.array,
142
+ report: PropTypes.array,
143
+ setActiveHost: PropTypes.func,
144
+ activeHostId: PropTypes.number,
145
+
146
+ };
147
+
148
+ export default ApplicationInstanceReport;
@@ -0,0 +1,44 @@
1
+ @import '~@theforeman/vendor/scss/variables';
2
+
3
+ .deploy_status {
4
+ padding-bottom: 80px;
5
+ }
6
+
7
+ .deploy_status_head {
8
+ float:left;
9
+ width:25%;
10
+ height:10%;
11
+ }
12
+
13
+ .deploy_status_content {
14
+ float:left;
15
+ width:75%;
16
+ height:10%;
17
+ }
18
+
19
+ .deploy_report_hosts {
20
+ float:left;
21
+ width:25%;
22
+ height:100%;
23
+ }
24
+
25
+ .deploy_report_tasks {
26
+ float:left;
27
+ width:75%;
28
+ min-height: 300px;
29
+ background-color: #ecf9fe;
30
+ padding: 10px;
31
+ border: 1px solid #3dbff3;
32
+ }
33
+
34
+ ul.vertical-tabs-pf {
35
+ list-style-type: none;
36
+ }
37
+
38
+ .vertical-tabs-pf-tab.active {
39
+ background-color: $dropdown-link-hover-bg;
40
+ }
41
+
42
+ .vertical-tabs-pf-tab {
43
+ background-color: white;
44
+ }
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import api from 'foremanReact/API';
3
+
4
+ import {
5
+ actionHeaderCellFormatter,
6
+ } from 'patternfly-react';
7
+
8
+ import {
9
+ propsToSnakeCase,
10
+ propsToCamelCase,
11
+ } from 'foremanReact/common/helpers';
12
+
13
+ import {
14
+ APPLICATION_INSTANCE_REPORT_INIT,
15
+ APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST,
16
+ } from './ApplicationInstanceReportConstants';
17
+
18
+ export const initApplicationInstanceReport = (
19
+ hosts,
20
+ ) => dispatch => {
21
+ const initialState = {};
22
+
23
+ initialState.hosts = hosts;
24
+
25
+ dispatch({
26
+ type: APPLICATION_INSTANCE_REPORT_INIT,
27
+ payload: initialState,
28
+ });
29
+ };
30
+
31
+ const errorHandler = (msg, err) => {
32
+ const error = {
33
+ errorMsg: 'Failed to fetch data from server.',
34
+ statusText: err,
35
+ };
36
+ return { type: msg, payload: { error } };
37
+ };
38
+
39
+ export const setActiveHost = (id) => ({
40
+ type: APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST,
41
+ payload: { activeHostId: id },
42
+ });
@@ -0,0 +1,2 @@
1
+ export const APPLICATION_INSTANCE_REPORT_INIT = 'APPLICATION_INSTANCE_REPORT_INIT';
2
+ export const APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST = 'APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST';
@@ -0,0 +1,38 @@
1
+ import Immutable from 'seamless-immutable';
2
+
3
+ import {
4
+ cloneDeep,
5
+ findIndex,
6
+ findLastIndex,
7
+ } from 'lodash';
8
+
9
+ import {
10
+ APPLICATION_INSTANCE_REPORT_INIT,
11
+ APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST,
12
+ } from './ApplicationInstanceReportConstants';
13
+
14
+ export const initialState = Immutable({
15
+ name: false,
16
+ error: { errorMsg: '', status: '', statusText: '' },
17
+ });
18
+
19
+ const applicationInstanceReport = (state = initialState, action) => {
20
+ const { payload } = action;
21
+
22
+ switch (action.type) {
23
+ case APPLICATION_INSTANCE_REPORT_INIT: {
24
+ return state.merge(payload);
25
+ }
26
+ case APPLICATION_INSTANCE_REPORT_SET_ACTIVE_HOST: {
27
+ return state.merge({
28
+ loading: true,
29
+ activeHostId: payload.activeHostId,
30
+ })
31
+ }
32
+ default: {
33
+ return state;
34
+ }
35
+ }
36
+ };
37
+
38
+ export default applicationInstanceReport;