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); |
| 63 | throw new Error(i18n.t('pageDumps.toast.errorStartBmcDump')); |
| 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); |
| 77 | throw new Error(i18n.t('pageDumps.toast.errorStartSystemDump')); |
| 78 | }); |
| 79 | }, |
| 80 | async deleteDumps({ dispatch }, dumps) { |
| 81 | const promises = dumps.map(({ location }) => |
| 82 | api.delete(location).catch((error) => { |
| 83 | console.log(error); |
| 84 | return error; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 85 | }), |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 86 | ); |
| 87 | return await api |
| 88 | .all(promises) |
| 89 | .then((response) => { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 90 | dispatch('getAllDumps'); |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 91 | return response; |
| 92 | }) |
| 93 | .then( |
| 94 | api.spread((...responses) => { |
| 95 | const { successCount, errorCount } = getResponseCount(responses); |
| 96 | const toastMessages = []; |
| 97 | |
| 98 | if (successCount) { |
| 99 | const message = i18n.tc( |
| 100 | 'pageDumps.toast.successDeleteDump', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 101 | successCount, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 102 | ); |
| 103 | toastMessages.push({ type: 'success', message }); |
| 104 | } |
| 105 | |
| 106 | if (errorCount) { |
| 107 | const message = i18n.tc( |
| 108 | 'pageDumps.toast.errorDeleteDump', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 109 | errorCount, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 110 | ); |
| 111 | toastMessages.push({ type: 'error', message }); |
| 112 | } |
| 113 | |
| 114 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 115 | }), |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 116 | ); |
| 117 | }, |
| 118 | async deleteAllDumps({ commit, state }) { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 119 | const totalDumpCount = state.allDumps.length; |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 120 | return await api |
| 121 | .post( |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 122 | `${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.ClearLog`, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 123 | ) |
| 124 | .then(() => { |
Sukanya Pandey | e39b95d | 2021-08-23 18:11:02 +0530 | [diff] [blame] | 125 | commit('setAllDumps', []); |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 126 | return i18n.tc('pageDumps.toast.successDeleteDump', totalDumpCount); |
| 127 | }) |
| 128 | .catch((error) => { |
| 129 | console.log(error); |
| 130 | throw new Error( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 131 | i18n.tc('pageDumps.toast.errorDeleteDump', totalDumpCount), |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 132 | ); |
| 133 | }); |
| 134 | }, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 135 | }, |
| 136 | }; |
| 137 | |
| 138 | export default DumpsStore; |