From 7d5e7b6f494c16640790734c39ffb2f1ed511358 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Tue, 16 Aug 2022 13:16:28 +0300 Subject: SILABMC-256: patch/get for limits --- .../modules/HardwareStatus/MotherboardStore.js | 30 ++++++++++++++++++++ src/utilities/_sila/metricProperties.js | 9 ++++++ .../_sila/Motherboard/Dynamic/MotherboardTemp.vue | 32 ++++++++++++++++++++-- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/store/modules/HardwareStatus/MotherboardStore.js b/src/store/modules/HardwareStatus/MotherboardStore.js index 09f24498..eecd3bc7 100644 --- a/src/store/modules/HardwareStatus/MotherboardStore.js +++ b/src/store/modules/HardwareStatus/MotherboardStore.js @@ -5,10 +5,12 @@ const MotherboardStore = { state: { motherboard: [], motherboardLastHour: [], + limits: [], }, getters: { motherboard: (state) => state.motherboard, motherboardLastHour: (state) => state.motherboardLastHour, + limits: (state) => state.limits, }, mutations: { setMotherboardDynamic: (state, data) => { @@ -17,8 +19,36 @@ const MotherboardStore = { setMotherboardDynamicLastHour: (state, data) => { state.motherboardLastHour = data; }, + setLimits: (state, data) => { + state.limits = data; + }, }, actions: { + async patchLimits() { + return await api + .get('/redfish/v1/Chassis/SILA_Baseboard/Thermal') + .then(({ data: { Temperatures = [] } }) => + Temperatures.map((temperature) => + api.patch('/redfish/v1/Chassis/SILA_Baseboard/Thermal', { + Temperatures: [ + { + MemberId: temperature.MemberId, + UpperThresholdNonCritical: 7, + }, + ], + }) + ) + ) + .catch((error) => console.log(error)); + }, + 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 getMotherboardDynamic({ commit }, { lastHour }) { let url = null; if (lastHour) { diff --git a/src/utilities/_sila/metricProperties.js b/src/utilities/_sila/metricProperties.js index edc701d6..e435bab2 100644 --- a/src/utilities/_sila/metricProperties.js +++ b/src/utilities/_sila/metricProperties.js @@ -1,3 +1,12 @@ +export function getGroups(data) { + return Object.keys( + data.reduce(function (rv, x) { + (rv[x['Sensor']] = rv[x['Sensor']] || []).push(x); + return rv; + }, {}) + ); +} + export function getItems(data, float = false) { let filteredData = data.filter((metric) => { return metric.Value !== 'nan'; diff --git a/src/views/_sila/Motherboard/Dynamic/MotherboardTemp.vue b/src/views/_sila/Motherboard/Dynamic/MotherboardTemp.vue index 9f8d41cb..fde051e1 100644 --- a/src/views/_sila/Motherboard/Dynamic/MotherboardTemp.vue +++ b/src/views/_sila/Motherboard/Dynamic/MotherboardTemp.vue @@ -72,7 +72,7 @@ import DataFormatterMixin from '@/components/_sila/Mixins/DataFormatterMixin'; import LoadingBarMixin from '@/components/_sila/Mixins/LoadingBarMixin'; import TableFilterMixin from '@/components/_sila/Mixins/TableFilterMixin'; -import { getItems } from '@/utilities/_sila/metricProperties'; +import { getItems, getGroups } from '@/utilities/_sila/metricProperties'; export default { components: { Chart }, @@ -121,10 +121,27 @@ export default { }, computed: { + groups() { + return getGroups(this.filteredSensors); + }, + items() { return getItems(this.filteredSensors); }, + limits() { + return this.$store.getters['motherboard/limits']; + }, + + limit() { + return this.limits.find((limit) => { + return ( + limit?.UpperThresholdNonCritical && + this.groups.includes(limit.MemberId) + ); + })?.UpperThresholdNonCritical; + }, + allSensors() { return this.timeScale === 'hour' ? this.$store.getters['motherboard/motherboardLastHour'] @@ -152,9 +169,16 @@ export default { created() { this.loadData(); + // this.saveLimits(); }, methods: { + saveLimits() { + this.startLoader(); + this.$store + .dispatch('motherboard/patchLimits') + .finally(() => this.endLoader()); + }, loadData() { let payload = { lastHour: false }; if (this.timeScale === 'hour') { @@ -165,8 +189,10 @@ export default { this.$store .dispatch('motherboard/getMotherboardDynamic', payload) .finally(() => { - this.endLoader(); - this.isBusy = false; + this.$store.dispatch('motherboard/getLimits').finally(() => { + this.endLoader(); + this.isBusy = false; + }); }); }, }, -- cgit v1.2.3