From 7b203f1e8bb941ee01c417104ddfe825e001b795 Mon Sep 17 00:00:00 2001 From: Mengling Ding Date: Tue, 10 Dec 2024 15:47:59 -0600 Subject: [PATCH] feat: implement api bladesGetResourceStatus in webui --- .../Appliance/ComposeMemoryButton.vue | 2 +- webui/src/components/Appliance/Memory.vue | 4 +-- .../components/Stores/BladeResourceStore.ts | 31 ++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/webui/src/components/Appliance/ComposeMemoryButton.vue b/webui/src/components/Appliance/ComposeMemoryButton.vue index aee07d58..22659767 100644 --- a/webui/src/components/Appliance/ComposeMemoryButton.vue +++ b/webui/src/components/Appliance/ComposeMemoryButton.vue @@ -363,7 +363,7 @@ export default { const bladeResourceStore = useBladeResourceStore(); const bladePortStore = useBladePortStore(); - await bladeResourceStore.fetchMemoryResources( + await bladeResourceStore.updateMemoryResourcesStatus( this.associatedApplianceId, this.bladeId ); diff --git a/webui/src/components/Appliance/Memory.vue b/webui/src/components/Appliance/Memory.vue index 62d7c327..eea7f31e 100644 --- a/webui/src/components/Appliance/Memory.vue +++ b/webui/src/components/Appliance/Memory.vue @@ -434,7 +434,7 @@ export default { this.selectedMemoryRegion.memoryApplianceId, this.selectedMemoryRegion.memoryBladeId ); - await bladeResourceStore.fetchMemoryResources( + await bladeResourceStore.updateMemoryResourcesStatus( this.selectedMemoryRegion.memoryApplianceId, this.selectedMemoryRegion.memoryBladeId ); @@ -477,7 +477,7 @@ export default { const bladeResourceStore = useBladeResourceStore(); const bladePortStore = useBladePortStore(); - await bladeResourceStore.fetchMemoryResources( + await bladeResourceStore.updateMemoryResourcesStatus( this.selectedMemoryRegion.memoryApplianceId, this.selectedMemoryRegion.memoryBladeId ); diff --git a/webui/src/components/Stores/BladeResourceStore.ts b/webui/src/components/Stores/BladeResourceStore.ts index 1ca89377..d490b6b8 100644 --- a/webui/src/components/Stores/BladeResourceStore.ts +++ b/webui/src/components/Stores/BladeResourceStore.ts @@ -21,7 +21,7 @@ export const useBladeResourceStore = defineStore('bladeResource', { applianceId, bladeId ); - + const resourcesCount = response.data.memberCount; for (let i = 0; i < resourcesCount; i++) { // Extract the id for each resources @@ -47,5 +47,34 @@ export const useBladeResourceStore = defineStore('bladeResource', { console.error("Error fetching resources:", error); } }, + + async updateMemoryResourcesStatus(applianceId: string, bladeId: string) { + try { + const defaultApi = new DefaultApi(undefined, API_BASE_PATH); + const updatedResource = await defaultApi.bladesGetResourceStatus( + applianceId, + bladeId, + ); + + if (updatedResource) { + // Create a map to quick look up the updatedResource + const resourceMap = new Map(); + updatedResource.data.resourceStatuses.forEach((resource) => { + resourceMap.set(resource.id, resource.compositionStatus.compositionState); + }); + + // Update the status in memoryResources based on the resource map + this.memoryResources.forEach(resource => { + if (resourceMap.has(resource.id)) { + resource.compositionStatus.compositionState = resourceMap.get(resource.id) + "" + } + }); + } + + } catch (error) { + console.error("Error updating resources:", error); + } + + }, } }) \ No newline at end of file