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