Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Added disks count to inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudbehl committed Apr 9, 2019
1 parent 5c9a1a2 commit 7f8e9dd
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/Dashboard/Inventory/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { getHostStatus, HOST_STATUS_ALL_ERROR, HOST_STATUS_ALL_WARN } from '../.
import { getPvStatus, PV_STATUS_ALL_ERROR, PV_STATUS_ALL_PROGRESS } from '../../../utils/status/pv';

// same as InventoryItemStatus props
const STATUS_RESULT_OK = 'ok';
const STATUS_RESULT_WARN = 'warn';
const STATUS_RESULT_ERROR = 'error';
const STATUS_RESULT_IN_PROGRESS = 'inProgress';
export const STATUS_RESULT_OK = 'ok';
export const STATUS_RESULT_WARN = 'warn';
export const STATUS_RESULT_ERROR = 'error';
export const STATUS_RESULT_IN_PROGRESS = 'inProgress';

const mapStatuses = (entities, mapEntityToStatusResult) => {
const result = {
Expand Down
6 changes: 5 additions & 1 deletion src/components/StorageOverview/Inventory/Inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ import {
} from '../../Dashboard/DashboardCard';
import { StorageOverviewContext } from '../StorageOverviewContext';
import { mapNodesToProps, mapPvcsToProps, mapPvsToProps } from '../../Dashboard/Inventory/utils';
import diskStatsToProps from './diskInventoryUtils';
import { InventoryRow } from '../../Dashboard/Inventory/InventoryRow';

const InventoryBody = ({ nodes, pvs, pvcs }) => (
const InventoryBody = ({ nodes, pvs, pvcs, diskStats }) => (
<React.Fragment>
<InventoryRow title="Nodes" {...mapNodesToProps(nodes)} />
<InventoryRow title="Disks" {...diskStatsToProps(diskStats)} />
<InventoryRow title="PVs" {...mapPvsToProps(pvs)} />
<InventoryRow title="PVCs" {...mapPvcsToProps(pvcs)} />
</React.Fragment>
);

InventoryBody.defaultProps = {
nodes: undefined,
diskStats: undefined,
pvs: undefined,
pvcs: undefined,
};

InventoryBody.propTypes = {
nodes: PropTypes.array,
diskStats: PropTypes.object,
pvs: PropTypes.array,
pvcs: PropTypes.array,
};
Expand Down
24 changes: 24 additions & 0 deletions src/components/StorageOverview/Inventory/diskInventoryUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { get } from 'lodash';

import { getCapacityStats } from '../../../selectors';
import { STATUS_RESULT_OK, STATUS_RESULT_ERROR } from '../../Dashboard/Inventory/utils';

const diskStatsToProps = disks => {
const result = {
[STATUS_RESULT_OK]: 0,
[STATUS_RESULT_ERROR]: 0,
count: null,
};

const cephOsdUpCount = getCapacityStats(get(disks, 'cephOsdUp'));
const cephOsdDownCount = getCapacityStats(get(disks, 'cephOsdDown'));

if (cephOsdUpCount || cephOsdDownCount) {
result[STATUS_RESULT_OK] = cephOsdUpCount;
result[STATUS_RESULT_ERROR] = cephOsdDownCount;
result.count = cephOsdUpCount + cephOsdDownCount;
}
return result;
};

export default diskStatsToProps;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inventory } from '../Inventory';
import { nodes, pvcs, pvs } from '../../fixtures/StorageOverview.fixture';
import { nodes, pvcs, pvs, diskStats } from '../../fixtures/StorageOverview.fixture';

export default [
{
Expand All @@ -8,6 +8,7 @@ export default [
nodes,
pvcs,
pvs,
diskStats,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,46 @@ exports[`<Inventory /> renders correctly 1`] = `
</div>
</div>
</div>
<div
class="kubevirt-inventory__row"
id="inventory-disks"
>
<div
class="kubevirt-inventory__row-title"
>
7 Disks
</div>
<div
class="kubevirt-inventory__row-status"
>
<div
class="kubevirt-inventory__row-status-item"
>
<span
aria-hidden="true"
class="fa fa-exclamation-circle fa-2x kubevirt-inventory__row-status-item-icon--error"
/>
<span
class="kubevirt-inventory__row-status-item-text"
>
2
</span>
</div>
<div
class="kubevirt-inventory__row-status-item"
>
<span
aria-hidden="true"
class="fa fa-check-circle fa-2x kubevirt-inventory__row-status-item-icon--ok"
/>
<span
class="kubevirt-inventory__row-status-item-text"
>
5
</span>
</div>
</div>
</div>
<div
class="kubevirt-inventory__row"
id="inventory-pvs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { StorageOverviewContext } from '../StorageOverviewContext';
import { localhostNode } from '../../../tests/mocks/node';
import { persistentVolumeClaims } from '../../../tests/mocks/persistentVolumeClaim';
import { persistentVolumes } from '../../../tests/mocks/persistentVolume';
import { osdDisksCount } from '../../../tests/mocks/disks';

export const nodes = [localhostNode];
export const pvcs = persistentVolumeClaims;
export const pvs = persistentVolumes;
export const diskStats = osdDisksCount;

const StorageOverview = props => (
<StorageOverviewContext.Provider value={props}>
Expand All @@ -29,6 +31,7 @@ export default [
nodes,
pvcs,
pvs,
diskStats,
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,46 @@ exports[`<StorageOverview /> renders correctly with Provider 1`] = `
</div>
</div>
</div>
<div
class="kubevirt-inventory__row"
id="inventory-disks"
>
<div
class="kubevirt-inventory__row-title"
>
7 Disks
</div>
<div
class="kubevirt-inventory__row-status"
>
<div
class="kubevirt-inventory__row-status-item"
>
<span
aria-hidden="true"
class="fa fa-exclamation-circle fa-2x kubevirt-inventory__row-status-item-icon--error"
/>
<span
class="kubevirt-inventory__row-status-item-text"
>
2
</span>
</div>
<div
class="kubevirt-inventory__row-status-item"
>
<span
aria-hidden="true"
class="fa fa-check-circle fa-2x kubevirt-inventory__row-status-item-icon--ok"
/>
<span
class="kubevirt-inventory__row-status-item-text"
>
5
</span>
</div>
</div>
</div>
<div
class="kubevirt-inventory__row"
id="inventory-pvs"
Expand Down
26 changes: 26 additions & 0 deletions src/tests/mocks/disks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const osdDisksCount = {
cephOsdUp: {
status: 'success',
data: {
resultType: 'vector',
result: [
{
metric: {},
value: [123, '5'],
},
],
},
},
cephOsdDown: {
status: 'success',
data: {
resultType: 'vector',
result: [
{
metric: {},
value: [123, '2'],
},
],
},
},
};

0 comments on commit 7f8e9dd

Please sign in to comment.