blob: 9391e571871cdb710a6438e9a0743c86203ea197 [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);
63 throw new Error(i18n.t('pageDumps.toast.errorStartBmcDump'));
64 });
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);
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 Tanous81323992024-02-27 11:26:24 -080085 }),
Yoshie Muranakaf415a082020-12-07 13:04:11 -080086 );
87 return await api
88 .all(promises)
89 .then((response) => {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053090 dispatch('getAllDumps');
Yoshie Muranakaf415a082020-12-07 13:04:11 -080091 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 Tanous81323992024-02-27 11:26:24 -0800101 successCount,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800102 );
103 toastMessages.push({ type: 'success', message });
104 }
105
106 if (errorCount) {
107 const message = i18n.tc(
108 'pageDumps.toast.errorDeleteDump',
Ed Tanous81323992024-02-27 11:26:24 -0800109 errorCount,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800110 );
111 toastMessages.push({ type: 'error', message });
112 }
113
114 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800115 }),
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800116 );
117 },
118 async deleteAllDumps({ commit, state }) {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +0530119 const totalDumpCount = state.allDumps.length;
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800120 return await api
121 .post(
Sean Zhang8841b7d2024-06-15 08:42:41 +0300122 `${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.ClearLog`,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800123 )
124 .then(() => {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +0530125 commit('setAllDumps', []);
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800126 return i18n.tc('pageDumps.toast.successDeleteDump', totalDumpCount);
127 })
128 .catch((error) => {
129 console.log(error);
130 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -0800131 i18n.tc('pageDumps.toast.errorDeleteDump', totalDumpCount),
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800132 );
133 });
134 },
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800135 },
136};
137
138export default DumpsStore;