From f415a0898b6f1f5cee8aa43259e8aedf07d395aa Mon Sep 17 00:00:00 2001 From: Yoshie Muranaka Date: Mon, 7 Dec 2020 13:04:11 -0800 Subject: Add DumpsStore API calls Ties in API requests to the Dumps page and adds ability to: - Create new System or BMC dump - Delete single or multiple BMC dumps. Uses ClearLog service to delete all and DELETE request for single dump deletion Signed-off-by: Yoshie Muranaka Change-Id: Iae928fa3b8fab00e549c33c0ab914a4b04de0f40 --- src/assets/styles/bmc/custom/_forms.scss | 2 +- src/env/components/Dumps/Dumps.vue | 46 +++++++++-- src/env/components/Dumps/DumpsForm.vue | 38 ++++++++- .../components/Dumps/DumpsModalConfirmation.vue | 75 ++++++++++++++++++ src/env/store/Dumps/DumpsStore.js | 91 +++++++++++++++++++++- src/locales/en-US.json | 25 ++++-- 6 files changed, 259 insertions(+), 18 deletions(-) create mode 100644 src/env/components/Dumps/DumpsModalConfirmation.vue diff --git a/src/assets/styles/bmc/custom/_forms.scss b/src/assets/styles/bmc/custom/_forms.scss index cea5ef50..428a40c2 100644 --- a/src/assets/styles/bmc/custom/_forms.scss +++ b/src/assets/styles/bmc/custom/_forms.scss @@ -51,7 +51,7 @@ .custom-select, .custom-control-label, .form-control { - color: theme-color("dark"); + color: theme-color("dark") !important; font-size: 1rem; } diff --git a/src/env/components/Dumps/Dumps.vue b/src/env/components/Dumps/Dumps.vue index eba90b7a..3bf5579a 100644 --- a/src/env/components/Dumps/Dumps.vue +++ b/src/env/components/Dumps/Dumps.vue @@ -3,14 +3,14 @@ - + - + { @@ -246,7 +249,7 @@ export default { this.filterStartDate = fromDate; this.filterEndDate = toDate; }, - onTableRowAction(action) { + onTableRowAction(action, dump) { if (action === 'delete') { this.$bvModal .msgBoxConfirm(this.$tc('pageDumps.modal.deleteDumpConfirmation'), { @@ -255,7 +258,19 @@ export default { cancelTitle: this.$t('global.action.cancel'), }) .then((deleteConfrimed) => { - if (deleteConfrimed); // delete dump + if (deleteConfrimed) { + this.$store + .dispatch('dumps/deleteDumps', [dump]) + .then((messages) => { + messages.forEach(({ type, message }) => { + if (type === 'success') { + this.successToast(message); + } else if (type === 'error') { + this.errorToast(message); + } + }); + }); + } }); } }, @@ -280,7 +295,26 @@ export default { } ) .then((deleteConfrimed) => { - if (deleteConfrimed); // delete dump + if (deleteConfrimed) { + if (this.selectedRows.length === this.dumps.length) { + this.$store + .dispatch('dumps/deleteAllDumps') + .then((success) => this.successToast(success)) + .catch(({ message }) => this.errorToast(message)); + } else { + this.$store + .dispatch('dumps/deleteDumps', this.selectedRows) + .then((messages) => { + messages.forEach(({ type, message }) => { + if (type === 'success') { + this.successToast(message); + } else if (type === 'error') { + this.errorToast(message); + } + }); + }); + } + } }); } }, diff --git a/src/env/components/Dumps/DumpsForm.vue b/src/env/components/Dumps/DumpsForm.vue index ed81b3a8..9dc8bcb1 100644 --- a/src/env/components/Dumps/DumpsForm.vue +++ b/src/env/components/Dumps/DumpsForm.vue @@ -21,20 +21,28 @@ {{ $t('global.form.required') }} + + {{ $t('pageDumps.form.systemDumpInfo') }} + - {{ $t('pageDumps.form.createNewDump') }} + {{ $t('pageDumps.form.initiateDump') }} + diff --git a/src/env/store/Dumps/DumpsStore.js b/src/env/store/Dumps/DumpsStore.js index 45f446c0..3b91354b 100644 --- a/src/env/store/Dumps/DumpsStore.js +++ b/src/env/store/Dumps/DumpsStore.js @@ -1,4 +1,5 @@ -import api from '@/store/api'; +import api, { getResponseCount } from '@/store/api'; +import i18n from '@/i18n'; const DumpsStore = { namespaced: true, @@ -6,16 +7,17 @@ const DumpsStore = { bmcDumps: [], }, getters: { - allDumps: (state) => state.bmcDumps, + bmcDumps: (state) => state.bmcDumps, }, mutations: { setBmcDumps: (state, dumps) => { state.bmcDumps = dumps.map((dump) => ({ + data: dump.AdditionalDataURI, dateTime: new Date(dump.Created), dumpType: dump.Name, id: dump.Id, + location: dump['@odata.id'], size: dump.AdditionalDataSizeBytes, - data: dump.AdditionalDataURI, })); }, }, @@ -26,6 +28,89 @@ const DumpsStore = { .then(({ data = {} }) => commit('setBmcDumps', data.Members || [])) .catch((error) => console.log(error)); }, + async createBmcDump() { + return await api + .post( + '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData', + { + DiagnosticDataType: 'Manager', + OEMDiagnosticDataType: '', + } + ) + .catch((error) => { + console.log(error); + throw new Error(i18n.t('pageDumps.toast.errorStartBmcDump')); + }); + }, + async createSystemDump() { + return await api + .post( + '/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData', + { + DiagnosticDataType: 'OEM', + OEMDiagnosticDataType: 'System', + } + ) + .catch((error) => { + console.log(error); + throw new Error(i18n.t('pageDumps.toast.errorStartSystemDump')); + }); + }, + async deleteDumps({ dispatch }, dumps) { + const promises = dumps.map(({ location }) => + api.delete(location).catch((error) => { + console.log(error); + return error; + }) + ); + return await api + .all(promises) + .then((response) => { + dispatch('getBmcDumps'); + return response; + }) + .then( + api.spread((...responses) => { + const { successCount, errorCount } = getResponseCount(responses); + const toastMessages = []; + + if (successCount) { + const message = i18n.tc( + 'pageDumps.toast.successDeleteDump', + successCount + ); + toastMessages.push({ type: 'success', message }); + } + + if (errorCount) { + const message = i18n.tc( + 'pageDumps.toast.errorDeleteDump', + errorCount + ); + toastMessages.push({ type: 'error', message }); + } + + return toastMessages; + }) + ); + }, + async deleteAllDumps({ commit, state }) { + const totalDumpCount = state.bmcDumps.length; + return await api + .post( + '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog' + ) + .then(() => { + commit('setBmcDumps', []); + return i18n.tc('pageDumps.toast.successDeleteDump', totalDumpCount); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.tc('pageDumps.toast.errorDeleteDump', totalDumpCount) + ); + }); + }, }, }; diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 1d564ca6..ab9d8238 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -201,17 +201,23 @@ } }, "pageDumps": { - "dumpHistory": "Dump history", - "newDump": "New dump", + "dumpsAvailableOnBmc": "Dumps available on BMC", + "initiateDump": "Initiate dump", "form": { "bmcDump": "BMC dump", - "createNewDump": "Create new dump", + "initiateDump": "Initiate dump", "selectDumpType": "Select dump type", - "systemDump": "System dump (disruptive)" + "systemDump": "System dump (disruptive)", + "systemDumpInfo": "System dumps will be offloaded to the operating system and will not appear in the table below." }, "modal": { "deleteDump": "Delete dump | Delete dumps", - "deleteDumpConfirmation": "Are you sure you want to delete %{count} dump? This action cannot be undone. | Are you sure you want to delete %{count} dumps? This action cannot be undone." + "deleteDumpConfirmation": "Are you sure you want to delete %{count} dump? This action cannot be undone. | Are you sure you want to delete %{count} dumps? This action cannot be undone.", + "initiateSystemDump": "Initiate system dump", + "initiateSystemDumpMessage1": "Are you sure?", + "initiateSystemDumpMessage2": "You will not be able to initiate any other dumps while a system dump is in progress.", + "initiateSystemDumpMessage3": "Initiating a system dump will abnormally terminate all active system partitions.", + "initiateSystemDumpMessage4": "Proceed with dump initiation" }, "table": { "createdBy": "Created by", @@ -222,7 +228,14 @@ "size": "Size" }, "toast": { - "successStartDump": "Successfully started new dump." + "errorDeleteDump": "Error deleting %{count} dump. | Error deleting %{count} dumps.", + "errorStartBmcDump": "Error starting new BMC dump.", + "errorStartSystemDump": "Error starting new System dump.", + "successDeleteDump": "Successfully deleted %{count} dump. | Successfully deleted %{count} dumps.", + "successStartBmcDump": "The dump will take some time to complete. Refresh the application to see the completed dump in the table.", + "successStartBmcDumpTitle": "BMC dump started", + "successStartSystemDump": "The dump will take some time to complete. The dump will be offloaded to the operating system.", + "successStartSystemDumpTitle": "System dump started" } }, "pageEventLogs": { -- cgit v1.2.3