Merge "fix: Fix virtual resource about compute"

This commit is contained in:
Zuul 2022-06-07 10:34:01 +00:00 committed by Gerrit Code Review
commit 71809065d8
6 changed files with 122 additions and 120 deletions

View File

@ -83,7 +83,7 @@ const volumeColors = {
export class virtualResourceInfo extends Component {
componentDidMount() {
this.props.store.getVirtualResource();
this.props.store.getVirtualResourceOverview();
}
get card() {

View File

@ -15,7 +15,6 @@
import React, { Component } from 'react';
import { Row, Col, Card, Descriptions, Progress, Avatar } from 'antd';
import { inject, observer } from 'mobx-react';
import globalHypervisorStore from 'stores/nova/hypervisor';
import styles from '../style.less';
export const resourceCircle = [
@ -38,13 +37,8 @@ export const color = {
};
export class ResourceCircle extends Component {
constructor(props) {
super(props);
this.store = globalHypervisorStore;
}
componentDidMount() {
this.store.getOverview();
this.props.store.getVirtualResource();
}
get resourceCircle() {
@ -56,7 +50,7 @@ export class ResourceCircle extends Component {
}
renderCircle = (item, index) => {
const { overview } = this.store;
const { overview } = this.props.store;
const resource = overview[item.resource];
const used = overview[item.used];
@ -114,7 +108,7 @@ export class ResourceCircle extends Component {
};
render() {
const { isLoading } = this.store;
const { isLoading } = this.props.store;
return (
<Card
loading={isLoading}

View File

@ -16,6 +16,8 @@ import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { Row, Col } from 'antd';
import OverviewAdminStore from 'stores/overview-admin';
import globalServerStore from 'stores/nova/server';
import globalHypervisorStore from 'stores/nova/hypervisor';
import styles from './style.less';
import PlatformInfo from './components/PlatformInfo';
import ComputeService from './components/ComputeService';
@ -34,11 +36,11 @@ export class Overview extends Component {
}
renderVirtualResource() {
return <VirtualResource store={this.adminStore} />;
return <VirtualResource store={globalHypervisorStore} />;
}
renderResourceOverview() {
return <ResourceOverview store={this.adminStore} />;
return <ResourceOverview store={globalServerStore} />;
}
renderComputeService() {

View File

@ -139,7 +139,7 @@ export class HypervisorStore extends Base {
}
@action
getOverview = async () => {
getVirtualResource = async () => {
this.isLoading = true;
const hypervisorResult = await this.client.listDetail();
const { hypervisors } = hypervisorResult;

111
src/stores/nova/server.js Normal file
View File

@ -0,0 +1,111 @@
// Copyright 2021 99cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { action, extendObservable } from 'mobx';
import client from 'client';
import Base from 'stores/base';
import globalRootStore from 'stores/root';
export class ServerStore extends Base {
constructor() {
super();
extendObservable(this, {
virtualResource: {},
virtualResourceLoading: true,
});
}
get client() {
return client.nova.servers;
}
@action
async getVirtualResourceOverview() {
this.virtualResourceLoading = true;
const promiseArray = [
this.requestListAllByLimit({ all_tenants: true }, 1000),
this.requestListAllByLimit({ all_tenants: true, status: 'ACTIVE' }, 1000),
this.requestListAllByLimit({ all_tenants: true, status: 'ERROR' }, 1000),
this.requestListAllByLimit(
{ all_tenants: true, status: 'SHUTOFF' },
1000
),
];
if (globalRootStore.checkEndpoint('cinder')) {
const volumeResource = [
client.skyline.extension.volumes({ limit: 10, all_projects: true }),
client.skyline.extension.volumes({
limit: 10,
all_projects: true,
status: 'in-use',
}),
client.skyline.extension.volumes({
limit: 10,
all_projects: true,
status: 'error',
}),
client.skyline.extension.volumes({
limit: 10,
all_projects: true,
status: 'available',
}),
];
promiseArray.push(...volumeResource);
}
const [
allServers,
activeServers,
errorServers,
shutoffServers,
allVolumes,
attachVolumes,
errorVolumes,
availableVolumes,
] = await Promise.all(promiseArray);
const allServersCount = allServers.length;
const activeServersCount = activeServers.length;
const errorServersCount = errorServers.length;
const shutoffServersCount = shutoffServers.length;
const serviceNum = {
all: allServersCount,
active: activeServersCount,
error: errorServersCount,
shutoff: shutoffServersCount,
other:
allServersCount -
(activeServersCount + errorServersCount + shutoffServersCount),
};
this.virtualResource = { serviceNum };
if (globalRootStore.checkEndpoint('cinder')) {
const { count: allVolumesCount } = allVolumes;
const { count: attachVolumesCount } = attachVolumes;
const { count: errorVolumesCount } = errorVolumes;
const { count: availableVolumesCount } = availableVolumes;
const volumeNum = {
all: allVolumesCount,
active: attachVolumesCount,
error: errorVolumesCount,
available: availableVolumesCount,
other:
allVolumesCount -
(attachVolumesCount + errorVolumesCount + availableVolumesCount),
};
this.virtualResource.volumeNum = volumeNum;
}
this.virtualResourceLoading = false;
}
}
const globalServerStore = new ServerStore();
export default globalServerStore;

View File

@ -14,41 +14,21 @@
import { extendObservable, action } from 'mobx';
import client from 'client';
import globalRootStore from 'stores/root';
export default class OverviewStore {
constructor() {
this.reset(true);
}
get initValue() {
return {
extendObservable(this, {
projectInfoLoading: true,
computeServiceLoading: true,
networkServiceLoading: true,
virtualResourceLoading: true,
computeService: [],
networkService: [],
virtualResource: {},
platformNum: {
projectNum: 0,
userNum: 0,
nodeNum: 0,
},
};
}
@action
reset(init) {
const state = this.initValue;
if (init) {
extendObservable(this, state);
} else {
Object.keys(state).forEach((key) => {
this[key] = state[key];
});
}
});
}
@action
@ -71,91 +51,6 @@ export default class OverviewStore {
this.projectInfoLoading = false;
}
@action
async getVirtualResource() {
this.virtualResourceLoading = true;
const promiseArray = [
client.skyline.extension.servers({ limit: 10, all_projects: true }),
client.skyline.extension.servers({
limit: 10,
all_projects: true,
status: 'ACTIVE',
}),
client.skyline.extension.servers({
limit: 10,
all_projects: true,
status: 'ERROR',
}),
client.skyline.extension.servers({
limit: 10,
all_projects: true,
status: 'SHUTOFF',
}),
];
if (globalRootStore.checkEndpoint('cinder')) {
const volumeResource = [
client.skyline.extension.volumes({ limit: 10, all_projects: true }),
client.skyline.extension.volumes({
limit: 10,
all_projects: true,
status: 'in-use',
}),
client.skyline.extension.volumes({
limit: 10,
all_projects: true,
status: 'error',
}),
client.skyline.extension.volumes({
limit: 10,
all_projects: true,
status: 'available',
}),
];
promiseArray.push(...volumeResource);
}
const [
allServers,
activeServers,
errorServers,
shutoffServers,
allVolumes,
attachVolumes,
errorVolumes,
availableVolumes,
] = await Promise.all(promiseArray);
const { count: allServersCount } = allServers;
const { count: activeServersCount } = activeServers;
const { count: errorServersCount } = errorServers;
const { count: shutoffServersCount } = shutoffServers;
const serviceNum = {
all: allServersCount,
active: activeServersCount,
error: errorServersCount,
shutoff: shutoffServersCount,
other:
allServersCount -
(activeServersCount + errorServersCount + shutoffServersCount),
};
this.virtualResource = { serviceNum };
if (globalRootStore.checkEndpoint('cinder')) {
const { count: allVolumesCount } = allVolumes;
const { count: attachVolumesCount } = attachVolumes;
const { count: errorVolumesCount } = errorVolumes;
const { count: availableVolumesCount } = availableVolumes;
const volumeNum = {
all: allVolumesCount,
active: attachVolumesCount,
error: errorVolumesCount,
available: availableVolumesCount,
other:
allVolumesCount -
(attachVolumesCount + errorVolumesCount + availableVolumesCount),
};
this.virtualResource.volumeNum = volumeNum;
}
this.virtualResourceLoading = false;
}
@action
async getComputeService() {
this.computeServiceLoading = true;