blob: 100c4aa865609f865a3d3143569fc01198f40f60 [file] [log] [blame]
Yoshie Muranakaf415a082020-12-07 13:04:11 -08001import api, { getResponseCount } from '@/store/api';
2import i18n from '@/i18n';
Yoshie Muranaka22d4d522020-12-03 10:58:35 -08003
4const DumpsStore = {
5 namespaced: true,
6 state: {
Kennethc2c53aa2021-11-30 17:04:58 -06007 allDumps: [],
Yoshie Muranaka22d4d522020-12-03 10:58:35 -08008 },
9 getters: {
Kennethc2c53aa2021-11-30 17:04:58 -060010 allDumps: (state) => state.allDumps,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080011 },
12 mutations: {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053013 setAllDumps: (state, dumps) => {
Kennethc2c53aa2021-11-30 17:04:58 -060014 state.allDumps = dumps.map((dump) => ({
Yoshie Muranakaf415a082020-12-07 13:04:11 -080015 data: dump.AdditionalDataURI,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080016 dateTime: new Date(dump.Created),
17 dumpType: dump.Name,
18 id: dump.Id,
Yoshie Muranakaf415a082020-12-07 13:04:11 -080019 location: dump['@odata.id'],
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080020 size: dump.AdditionalDataSizeBytes,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080021 }));
22 },
23 },
24 actions: {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053025 async getBmcDumpEntries() {
26 return api
Sean Zhang8841b7d2024-06-15 08:42:41 +030027 .get(`${await this.dispatch('global/getBmcPath')}`)
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053028 .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 Zhang8841b7d2024-06-15 08:42:41 +030035 .get(`${await this.dispatch('global/getSystemPath')}`)
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053036 .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 Muranaka22d4d522020-12-03 10:58:35 -080042 return await api
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053043 .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 Muranaka22d4d522020-12-03 10:58:35 -080050 .catch((error) => console.log(error));
51 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080052 async createBmcDump() {
53 return await api
54 .post(
Sean Zhang8841b7d2024-06-15 08:42:41 +030055 `${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.CollectDiagnosticData`,
Yoshie Muranakaf415a082020-12-07 13:04:11 -080056 {
57 DiagnosticDataType: 'Manager',
58 OEMDiagnosticDataType: '',
Ed Tanous81323992024-02-27 11:26:24 -080059 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080060 )
61 .catch((error) => {
62 console.log(error);
Surya Vde23ea22024-07-11 15:19:46 +053063 throw new Error(i18n.global.t('pageDumps.toast.errorStartBmcDump'));
Yoshie Muranakaf415a082020-12-07 13:04:11 -080064 });
65 },
66 async createSystemDump() {
67 return await api
68 .post(
Sean Zhang8841b7d2024-06-15 08:42:41 +030069 `${await this.dispatch('global/getSystemPath')}/LogServices/Dump/Actions/LogService.CollectDiagnosticData`,
Yoshie Muranakaf415a082020-12-07 13:04:11 -080070 {
71 DiagnosticDataType: 'OEM',
72 OEMDiagnosticDataType: 'System',
Ed Tanous81323992024-02-27 11:26:24 -080073 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080074 )
75 .catch((error) => {
76 console.log(error);
Surya Vde23ea22024-07-11 15:19:46 +053077 throw new Error(
78 i18n.global.t('pageDumps.toast.errorStartSystemDump'),
79 );
Yoshie Muranakaf415a082020-12-07 13:04:11 -080080 });
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 Tanous81323992024-02-27 11:26:24 -080087 }),
Yoshie Muranakaf415a082020-12-07 13:04:11 -080088 );
89 return await api
90 .all(promises)
91 .then((response) => {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053092 dispatch('getAllDumps');
Yoshie Muranakaf415a082020-12-07 13:04:11 -080093 return response;
94 })
95 .then(
96 api.spread((...responses) => {
97 const { successCount, errorCount } = getResponseCount(responses);
98 const toastMessages = [];
99
100 if (successCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530101 const message = i18n.global.t(
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800102 'pageDumps.toast.successDeleteDump',
Ed Tanous81323992024-02-27 11:26:24 -0800103 successCount,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800104 );
105 toastMessages.push({ type: 'success', message });
106 }
107
108 if (errorCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530109 const message = i18n.global.t(
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800110 'pageDumps.toast.errorDeleteDump',
Ed Tanous81323992024-02-27 11:26:24 -0800111 errorCount,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800112 );
113 toastMessages.push({ type: 'error', message });
114 }
115
116 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800117 }),
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800118 );
119 },
120 async deleteAllDumps({ commit, state }) {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +0530121 const totalDumpCount = state.allDumps.length;
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800122 return await api
123 .post(
Sean Zhang8841b7d2024-06-15 08:42:41 +0300124 `${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.ClearLog`,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800125 )
126 .then(() => {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +0530127 commit('setAllDumps', []);
Surya Vde23ea22024-07-11 15:19:46 +0530128 return i18n.global.t(
129 'pageDumps.toast.successDeleteDump',
130 totalDumpCount,
131 );
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800132 })
133 .catch((error) => {
134 console.log(error);
135 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +0530136 i18n.global.t('pageDumps.toast.errorDeleteDump', totalDumpCount),
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800137 );
138 });
139 },
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800140 },
141};
142
143export default DumpsStore;