import api from '@/store/api'; import i18n from '@/i18n'; const MemoryStore = { namespaced: true, state: { dimms: [], dimmsLastHour: [], limits: [], }, getters: { dimms: (state) => state.dimms, dimmsLastHour: (state) => state.dimmsLastHour, limits: (state) => state.limits, }, mutations: { setMemoryInfo: (state, data) => { state.dimms = data.map(({ data }) => { const { Id, Status = {}, BaseModuleType, BusWidthBits, CapacityMiB, DataWidthBits, Enabled, OperatingSpeedMhz, PartNumber, SerialNumber, SparePartNumber, Description, MemoryType, MemorySize, Manufacturer, LocationIndicatorActive, Location, } = data; return { id: Id, health: Status.Health, baseModuleType: BaseModuleType, busWidthBits: BusWidthBits, capacityMiB: CapacityMiB, dataWidthBits: DataWidthBits, operatingSpeedMhz: OperatingSpeedMhz, enabled: Enabled, partNumber: PartNumber, serialNumber: SerialNumber, statusState: Status.State, sparePartNumber: SparePartNumber, description: Description, memoryType: MemoryType, memorySize: MemorySize, manufacturer: Manufacturer, identifyLed: LocationIndicatorActive, uri: data['@odata.id'], locationNumber: Location?.PartLocation?.ServiceLabel, }; }); }, setMemoryDynamic: (state, data) => { state.dimms = data; }, setMemoryDynamicLastHour: (state, data) => { state.dimmsLastHour = data; }, setLimits: (state, data) => { state.limits = data; }, }, actions: { async patchLimits({ dispatch }, { warning, critical, groups }) { return await api .patch('/redfish/v1/Chassis/SILA_Baseboard/Thermal', { Temperatures: groups.map((group) => { return { MemberId: group, UpperThresholdNonCritical: warning, }; }), }) .then(async () => { return await api.patch('/redfish/v1/Chassis/SILA_Baseboard/Thermal', { Temperatures: groups.map((group) => { return { MemberId: group, UpperThresholdCritical: critical, }; }), }); }) .catch((error) => { console.log(error); throw new Error(i18n.t('pageMemory.toast.errorLimitUpdate')); }) .finally(() => dispatch('getLimits')); }, async getLimits({ commit }) { return await api .get('/redfish/v1/Chassis/SILA_Baseboard/Thermal') .then(({ data: { Temperatures = [] } }) => { commit('setLimits', Temperatures); }) .catch((error) => console.log(error)); }, async getMemoryDynamic({ commit }, { lastHour }) { let url = null; if (lastHour) { url = '/redfish/v1/TelemetryService/MetricReports/dimm_temp&period=last_hour'; } else { url = '/redfish/v1/TelemetryService/MetricReports/dimm_temp'; } return await api .get(url) .then(({ data: { MetricValues = [] } }) => { if (lastHour) { commit('setMemoryDynamicLastHour', MetricValues); } else { commit('setMemoryDynamic', MetricValues); } }) .catch((error) => console.log(error)); }, async getDimms({ commit }) { return await api .get('/redfish/v1/Systems/system/Memory') .then(({ data: { Members } }) => { const promises = Members.map((item) => api.get(item['@odata.id'])); return api.all(promises); }) .then((response) => commit('setMemoryInfo', response)) .catch((error) => console.log(error)); }, async updateIdentifyLedValue({ dispatch }, led) { const uri = led.uri; const updatedIdentifyLedValue = { LocationIndicatorActive: led.identifyLed, }; return await api.patch(uri, updatedIdentifyLedValue).catch((error) => { dispatch('getDimms'); console.log('error', error); if (led.identifyLed) { throw new Error(i18n.t('pageInventory.toast.errorEnableIdentifyLed')); } else { throw new Error( i18n.t('pageInventory.toast.errorDisableIdentifyLed') ); } }); }, }, }; export default MemoryStore;