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
This commit is contained in:
Jingwei.Zhang 2022-07-25 09:53:16 +08:00
parent 2caa340ba6
commit afefcf6fdb
5 changed files with 37 additions and 54 deletions

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { inject, observer } from 'mobx-react'; 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 globalServerStore from 'stores/nova/instance';
import globalRootStore from 'stores/root'; import globalRootStore from 'stores/root';
import { ModalAction } from 'containers/Action'; import { ModalAction } from 'containers/Action';
@ -27,7 +27,7 @@ export class DetachVolume extends ModalAction {
init() { init() {
this.store = globalServerStore; this.store = globalServerStore;
this.volumeStore = new VolumeStore(); this.volumeStore = new InstanceVolumeStore();
this.getVolumes(); this.getVolumes();
} }

View File

@ -91,14 +91,10 @@ export class Volume extends Base {
updateFetchParams = (params) => { updateFetchParams = (params) => {
if (this.inDetailPage) { if (this.inDetailPage) {
const { match, detail } = this.props; const { id, ...rest } = params;
const { id } = match.params;
const { tenant_id: projectId, name } = detail || {};
return { return {
...params, ...rest,
serverId: id, serverId: id,
serverName: name,
projectId,
}; };
} }
return params; return params;

View File

@ -14,7 +14,7 @@
import React from 'react'; import React from 'react';
import { yesNoOptions } from 'utils/constants'; import { yesNoOptions } from 'utils/constants';
import { toLocalTimeFilter } from 'utils/index'; import { toLocalTimeFilter, renderFilterMap } from 'utils/index';
import globalProjectStore from 'stores/keystone/project'; import globalProjectStore from 'stores/keystone/project';
import globalVolumeStore from 'stores/cinder/volume'; import globalVolumeStore from 'stores/cinder/volume';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
@ -75,6 +75,19 @@ export const isOsDisk = (item) => {
return false; 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) => { export const isAttachIsoVolume = (item) => {
if ( if (
item.bootable === 'true' && item.bootable === 'true' &&
@ -239,7 +252,6 @@ export const getVolumeColumnsList = (self) => {
title: t('ID/Name'), title: t('ID/Name'),
dataIndex: 'name', dataIndex: 'name',
routeName: self.getRouteName('volumeDetail'), routeName: self.getRouteName('volumeDetail'),
stringify: (name, record) => name || record.id,
sortKey: 'name', sortKey: 'name',
}, },
{ {

View File

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
import { renderFilterMap } from 'utils/index';
import client from 'client'; import client from 'client';
import Base from 'stores/base'; import Base from 'stores/base';
import globalVolumeTypeStore from 'stores/cinder/volume-type'; import globalVolumeTypeStore from 'stores/cinder/volume-type';
@ -64,22 +63,9 @@ export class VolumeStore extends Base {
return this.skylineClient.extension.volumes(params); return this.skylineClient.extension.volumes(params);
} }
isOsDisk(item) {
const { isOsDisk } = require('resources/cinder/volume');
return isOsDisk(item);
}
get mapper() { get mapper() {
return (volume) => ({ const { updateVolume } = require('resources/cinder/volume');
...volume, return (volume) => updateVolume(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,
});
} }
get paramsFunc() { get paramsFunc() {

View File

@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { isOsDisk } from 'resources/cinder/volume';
import client from 'client'; import client from 'client';
import Base from 'stores/base'; import Base from 'stores/base';
import { groupArray } from 'utils/index';
import { updateVolume } from 'resources/cinder/volume';
export class InstanceVolumeStore extends Base { export class InstanceVolumeStore extends Base {
get client() { get client() {
@ -46,42 +47,30 @@ export class InstanceVolumeStore extends Base {
} }
get mapper() { get mapper() {
return (volume) => ({ return (volume) => updateVolume(volume);
...volume,
disk_tag: isOsDisk(volume) ? 'os_disk' : 'data_disk',
host: volume['os-vol-host-attr:host'],
});
} }
async listDidFetch(items, allProjects, filters) { get groupArraySize() {
return 10;
}
async listDidFetch(items, allProjects) {
if (items.length === 0) { if (items.length === 0) {
return items; return items;
} }
const { serverName, serverId } = filters; const volumeIds = items.map((it) => it.volumeId);
const { project_id, project_name } = items[0]; const idArray = groupArray(volumeIds, this.groupArraySize);
const results = await Promise.all( const results = await Promise.all(
items.map((it) => { idArray.map((it) => {
const { volumeId } = it; const newParams = { uuid: it, all_projects: allProjects };
return client.cinder.volumes.show(volumeId); return this.skylineClient.extension.volumes(newParams);
}) })
); );
const volumes = results.map((result) => { const resultVolumes = [];
const { volume } = result; results.forEach((result) => {
const { attachments = [] } = volume; resultVolumes.push(...result.volumes);
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,
};
}); });
return volumes; return resultVolumes;
} }
} }