From afefcf6fdb2141df46c93ba23e6b171d5f7b2701 Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Mon, 25 Jul 2022 09:53:16 +0800 Subject: [PATCH] refactor: optimize the way to fetch the list of volumes mounted on the instance Use the skyline extension volumes api with uuid param to fetch the list of the volumes mounted on the instance, instead of fetch all the volumes and filtered by the instance id Change-Id: Ie792a661d3fbf54a0f96c377e4d402e6bd0db323 --- .../Instance/actions/DetachVolume.jsx | 4 +- src/pages/storage/containers/Volume/index.jsx | 8 +--- src/resources/cinder/volume.jsx | 16 ++++++- src/stores/cinder/volume.js | 18 +------- src/stores/nova/instance-volume.js | 45 +++++++------------ 5 files changed, 37 insertions(+), 54 deletions(-) diff --git a/src/pages/compute/containers/Instance/actions/DetachVolume.jsx b/src/pages/compute/containers/Instance/actions/DetachVolume.jsx index 1ec2fb4e..fbbf3732 100644 --- a/src/pages/compute/containers/Instance/actions/DetachVolume.jsx +++ b/src/pages/compute/containers/Instance/actions/DetachVolume.jsx @@ -13,7 +13,7 @@ // limitations under the License. import { inject, observer } from 'mobx-react'; -import { VolumeStore } from 'stores/cinder/volume'; +import { InstanceVolumeStore } from 'stores/nova/instance-volume'; import globalServerStore from 'stores/nova/instance'; import globalRootStore from 'stores/root'; import { ModalAction } from 'containers/Action'; @@ -27,7 +27,7 @@ export class DetachVolume extends ModalAction { init() { this.store = globalServerStore; - this.volumeStore = new VolumeStore(); + this.volumeStore = new InstanceVolumeStore(); this.getVolumes(); } diff --git a/src/pages/storage/containers/Volume/index.jsx b/src/pages/storage/containers/Volume/index.jsx index d08e74ed..0eddfaf1 100644 --- a/src/pages/storage/containers/Volume/index.jsx +++ b/src/pages/storage/containers/Volume/index.jsx @@ -91,14 +91,10 @@ export class Volume extends Base { updateFetchParams = (params) => { if (this.inDetailPage) { - const { match, detail } = this.props; - const { id } = match.params; - const { tenant_id: projectId, name } = detail || {}; + const { id, ...rest } = params; return { - ...params, + ...rest, serverId: id, - serverName: name, - projectId, }; } return params; diff --git a/src/resources/cinder/volume.jsx b/src/resources/cinder/volume.jsx index 08a8a67a..af8552c5 100644 --- a/src/resources/cinder/volume.jsx +++ b/src/resources/cinder/volume.jsx @@ -14,7 +14,7 @@ import React from 'react'; import { yesNoOptions } from 'utils/constants'; -import { toLocalTimeFilter } from 'utils/index'; +import { toLocalTimeFilter, renderFilterMap } from 'utils/index'; import globalProjectStore from 'stores/keystone/project'; import globalVolumeStore from 'stores/cinder/volume'; import { isEmpty } from 'lodash'; @@ -75,6 +75,19 @@ export const isOsDisk = (item) => { return false; }; +export const updateVolume = (volume) => { + return { + ...volume, + disk_tag: isOsDisk(volume) ? 'os_disk' : 'data_disk', + description: volume.description || (volume.origin_data || {}).description, + delete_interval: + volume.metadata && volume.metadata.delete_interval + ? new Date(renderFilterMap.toLocalTime(volume.updated_at)).getTime() + + Number(volume.metadata.delete_interval) * 1000 + : null, + }; +}; + export const isAttachIsoVolume = (item) => { if ( item.bootable === 'true' && @@ -239,7 +252,6 @@ export const getVolumeColumnsList = (self) => { title: t('ID/Name'), dataIndex: 'name', routeName: self.getRouteName('volumeDetail'), - stringify: (name, record) => name || record.id, sortKey: 'name', }, { diff --git a/src/stores/cinder/volume.js b/src/stores/cinder/volume.js index 36374c29..2bacb2c8 100644 --- a/src/stores/cinder/volume.js +++ b/src/stores/cinder/volume.js @@ -13,7 +13,6 @@ // limitations under the License. import { action, observable } from 'mobx'; -import { renderFilterMap } from 'utils/index'; import client from 'client'; import Base from 'stores/base'; import globalVolumeTypeStore from 'stores/cinder/volume-type'; @@ -64,22 +63,9 @@ export class VolumeStore extends Base { return this.skylineClient.extension.volumes(params); } - isOsDisk(item) { - const { isOsDisk } = require('resources/cinder/volume'); - return isOsDisk(item); - } - get mapper() { - return (volume) => ({ - ...volume, - disk_tag: this.isOsDisk(volume) ? 'os_disk' : 'data_disk', - description: volume.description || (volume.origin_data || {}).description, - delete_interval: - volume.metadata && volume.metadata.delete_interval - ? new Date(renderFilterMap.toLocalTime(volume.updated_at)).getTime() + - Number(volume.metadata.delete_interval) * 1000 - : null, - }); + const { updateVolume } = require('resources/cinder/volume'); + return (volume) => updateVolume(volume); } get paramsFunc() { diff --git a/src/stores/nova/instance-volume.js b/src/stores/nova/instance-volume.js index b7899c78..21a94e77 100644 --- a/src/stores/nova/instance-volume.js +++ b/src/stores/nova/instance-volume.js @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { isOsDisk } from 'resources/cinder/volume'; import client from 'client'; import Base from 'stores/base'; +import { groupArray } from 'utils/index'; +import { updateVolume } from 'resources/cinder/volume'; export class InstanceVolumeStore extends Base { get client() { @@ -46,42 +47,30 @@ export class InstanceVolumeStore extends Base { } get mapper() { - return (volume) => ({ - ...volume, - disk_tag: isOsDisk(volume) ? 'os_disk' : 'data_disk', - host: volume['os-vol-host-attr:host'], - }); + return (volume) => updateVolume(volume); } - async listDidFetch(items, allProjects, filters) { + get groupArraySize() { + return 10; + } + + async listDidFetch(items, allProjects) { if (items.length === 0) { return items; } - const { serverName, serverId } = filters; - const { project_id, project_name } = items[0]; + const volumeIds = items.map((it) => it.volumeId); + const idArray = groupArray(volumeIds, this.groupArraySize); const results = await Promise.all( - items.map((it) => { - const { volumeId } = it; - return client.cinder.volumes.show(volumeId); + idArray.map((it) => { + const newParams = { uuid: it, all_projects: allProjects }; + return this.skylineClient.extension.volumes(newParams); }) ); - const volumes = results.map((result) => { - const { volume } = result; - const { attachments = [] } = volume; - const newAttachments = attachments.filter( - (it) => it.server_id === serverId - ); - newAttachments.forEach((it) => { - it.server_name = serverName; - }); - volume.attachments = newAttachments; - return { - ...volume, - project_id, - project_name, - }; + const resultVolumes = []; + results.forEach((result) => { + resultVolumes.push(...result.volumes); }); - return volumes; + return resultVolumes; } }