Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 1 | import api, { getResponseCount } from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 3 | |
| 4 | const DumpsStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
Kenneth | c2c53aa | 2021-11-30 17:04:58 -0600 | [diff] [blame] | 7 | allDumps: [], |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 8 | }, |
| 9 | getters: { |
Kenneth | c2c53aa | 2021-11-30 17:04:58 -0600 | [diff] [blame] | 10 | allDumps: (state) => state.allDumps, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 11 | }, |
| 12 | mutations: { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 13 | setAllDumps: (state, dumps) => { |
Kenneth | c2c53aa | 2021-11-30 17:04:58 -0600 | [diff] [blame] | 14 | state.allDumps = dumps.map((dump) => ({ |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 15 | data: dump.AdditionalDataURI, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 16 | dateTime: new Date(dump.Created), |
| 17 | dumpType: dump.Name, |
| 18 | id: dump.Id, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 19 | location: dump['@odata.id'], |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 20 | size: dump.AdditionalDataSizeBytes, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 21 | })); |
| 22 | }, |
| 23 | }, |
| 24 | actions: { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 25 | async getBmcDumpEntries() { |
| 26 | return api |
| 27 | .get('/redfish/v1/') |
| 28 | .then((response) => api.get(response.data.Managers['@odata.id'])) |
| 29 | .then((response) => api.get(`${response.data['@odata.id']}/bmc`)) |
| 30 | .then((response) => api.get(response.data.LogServices['@odata.id'])) |
| 31 | .then((response) => api.get(`${response.data['@odata.id']}/Dump`)) |
| 32 | .then((response) => api.get(response.data.Entries['@odata.id'])) |
| 33 | .catch((error) => console.log(error)); |
| 34 | }, |
| 35 | async getSystemDumpEntries() { |
| 36 | return api |
| 37 | .get('/redfish/v1/') |
| 38 | .then((response) => api.get(response.data.Systems['@odata.id'])) |
| 39 | .then((response) => api.get(`${response.data['@odata.id']}/system`)) |
| 40 | .then((response) => api.get(response.data.LogServices['@odata.id'])) |
| 41 | .then((response) => api.get(`${response.data['@odata.id']}/Dump`)) |
| 42 | .then((response) => api.get(response.data.Entries['@odata.id'])) |
| 43 | .catch((error) => console.log(error)); |
| 44 | }, |
| 45 | async getAllDumps({ commit, dispatch }) { |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 46 | return await api |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 47 | .all([dispatch('getBmcDumpEntries'), dispatch('getSystemDumpEntries')]) |
| 48 | .then((response) => { |
| 49 | const bmcDumpEntries = response[0].data?.Members || []; |
| 50 | const systemDumpEntries = response[1].data?.Members || []; |
| 51 | const allDumps = [...bmcDumpEntries, ...systemDumpEntries]; |
| 52 | commit('setAllDumps', allDumps); |
| 53 | }) |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 54 | .catch((error) => console.log(error)); |
| 55 | }, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 56 | async createBmcDump() { |
| 57 | return await api |
| 58 | .post( |
| 59 | '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData', |
| 60 | { |
| 61 | DiagnosticDataType: 'Manager', |
| 62 | OEMDiagnosticDataType: '', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 63 | }, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 64 | ) |
| 65 | .catch((error) => { |
| 66 | console.log(error); |
| 67 | throw new Error(i18n.t('pageDumps.toast.errorStartBmcDump')); |
| 68 | }); |
| 69 | }, |
| 70 | async createSystemDump() { |
| 71 | return await api |
| 72 | .post( |
| 73 | '/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData', |
| 74 | { |
| 75 | DiagnosticDataType: 'OEM', |
| 76 | OEMDiagnosticDataType: 'System', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 77 | }, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 78 | ) |
| 79 | .catch((error) => { |
| 80 | console.log(error); |
| 81 | throw new Error(i18n.t('pageDumps.toast.errorStartSystemDump')); |
| 82 | }); |
| 83 | }, |
| 84 | async deleteDumps({ dispatch }, dumps) { |
| 85 | const promises = dumps.map(({ location }) => |
| 86 | api.delete(location).catch((error) => { |
| 87 | console.log(error); |
| 88 | return error; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 89 | }), |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 90 | ); |
| 91 | return await api |
| 92 | .all(promises) |
| 93 | .then((response) => { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 94 | dispatch('getAllDumps'); |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 95 | return response; |
| 96 | }) |
| 97 | .then( |
| 98 | api.spread((...responses) => { |
| 99 | const { successCount, errorCount } = getResponseCount(responses); |
| 100 | const toastMessages = []; |
| 101 | |
| 102 | if (successCount) { |
| 103 | const message = i18n.tc( |
| 104 | 'pageDumps.toast.successDeleteDump', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 105 | successCount, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 106 | ); |
| 107 | toastMessages.push({ type: 'success', message }); |
| 108 | } |
| 109 | |
| 110 | if (errorCount) { |
| 111 | const message = i18n.tc( |
| 112 | 'pageDumps.toast.errorDeleteDump', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 113 | errorCount, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 114 | ); |
| 115 | toastMessages.push({ type: 'error', message }); |
| 116 | } |
| 117 | |
| 118 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 119 | }), |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 120 | ); |
| 121 | }, |
| 122 | async deleteAllDumps({ commit, state }) { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 123 | const totalDumpCount = state.allDumps.length; |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 124 | return await api |
| 125 | .post( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 126 | '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog', |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 127 | ) |
| 128 | .then(() => { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 129 | commit('setAllDumps', []); |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 130 | return i18n.tc('pageDumps.toast.successDeleteDump', totalDumpCount); |
| 131 | }) |
| 132 | .catch((error) => { |
| 133 | console.log(error); |
| 134 | throw new Error( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 135 | i18n.tc('pageDumps.toast.errorDeleteDump', totalDumpCount), |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 136 | ); |
| 137 | }); |
| 138 | }, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 139 | }, |
| 140 | }; |
| 141 | |
| 142 | export default DumpsStore; |