blob: 328e31643ad9da4e9b58a6198c3c649c7b0f4f50 [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
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 Muranaka22d4d522020-12-03 10:58:35 -080046 return await api
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053047 .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 Muranaka22d4d522020-12-03 10:58:35 -080054 .catch((error) => console.log(error));
55 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080056 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 Tanous81323992024-02-27 11:26:24 -080063 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080064 )
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 Tanous81323992024-02-27 11:26:24 -080077 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -080078 )
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 Tanous81323992024-02-27 11:26:24 -080089 }),
Yoshie Muranakaf415a082020-12-07 13:04:11 -080090 );
91 return await api
92 .all(promises)
93 .then((response) => {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +053094 dispatch('getAllDumps');
Yoshie Muranakaf415a082020-12-07 13:04:11 -080095 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 Tanous81323992024-02-27 11:26:24 -0800105 successCount,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800106 );
107 toastMessages.push({ type: 'success', message });
108 }
109
110 if (errorCount) {
111 const message = i18n.tc(
112 'pageDumps.toast.errorDeleteDump',
Ed Tanous81323992024-02-27 11:26:24 -0800113 errorCount,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800114 );
115 toastMessages.push({ type: 'error', message });
116 }
117
118 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800119 }),
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800120 );
121 },
122 async deleteAllDumps({ commit, state }) {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +0530123 const totalDumpCount = state.allDumps.length;
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800124 return await api
125 .post(
Ed Tanous81323992024-02-27 11:26:24 -0800126 '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog',
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800127 )
128 .then(() => {
Sukanya Pandeye39b95d2021-08-23 18:11:02 +0530129 commit('setAllDumps', []);
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800130 return i18n.tc('pageDumps.toast.successDeleteDump', totalDumpCount);
131 })
132 .catch((error) => {
133 console.log(error);
134 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -0800135 i18n.tc('pageDumps.toast.errorDeleteDump', totalDumpCount),
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800136 );
137 });
138 },
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800139 },
140};
141
142export default DumpsStore;