Merge "refactor: optimize the way to fetch the list of volumes mounted on the instance"

This commit is contained in:
Zuul 2022-07-25 07:44:58 +00:00 committed by Gerrit Code Review
commit 1be5f3509b
5 changed files with 37 additions and 54 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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',
},
{

View File

@ -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() {

View File

@ -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;
const resultVolumes = [];
results.forEach((result) => {
resultVolumes.push(...result.volumes);
});
volume.attachments = newAttachments;
return {
...volume,
project_id,
project_name,
};
});
return volumes;
return resultVolumes;
}
}