fix(striker-ui): replace all /cgi-bin urls

main
Tsu-ba-me 2 years ago
parent 837dc3028d
commit 9e9a81a5ce
  1. 3
      striker-ui/components/AnvilDrawer.tsx
  2. 26
      striker-ui/components/Anvils/SelectedAnvil.tsx
  3. 5
      striker-ui/components/Anvils/index.tsx
  4. 6
      striker-ui/components/CPU.tsx
  5. 93
      striker-ui/components/FileSystem/FileSystems.tsx
  6. 87
      striker-ui/components/FileSystem/FileSystemsHost.tsx
  7. 3
      striker-ui/components/FileSystem/index.tsx
  8. 21
      striker-ui/components/Header.tsx
  9. 35
      striker-ui/components/Hosts/AnvilHost.tsx
  10. 12
      striker-ui/components/Hosts/index.tsx
  11. 44
      striker-ui/components/Memory.tsx
  12. 7
      striker-ui/components/Network/Network.tsx
  13. 45
      striker-ui/components/Servers.tsx
  14. 17
      striker-ui/components/SharedStorage/SharedStorage.tsx
  15. 51
      striker-ui/components/SharedStorage/SharedStorageHost.tsx
  16. 53
      striker-ui/components/Storage.tsx
  17. 3
      striker-ui/pages/anvil/index.tsx
  18. 88
      striker-ui/types/APIAnvil.d.ts
  19. 5
      striker-ui/types/AnvilCPU.d.ts
  20. 16
      striker-ui/types/AnvilFileSystems.d.ts
  21. 8
      striker-ui/types/AnvilList.d.ts
  22. 6
      striker-ui/types/AnvilMemory.d.ts
  23. 45
      striker-ui/types/AnvilNetwork.d.ts
  24. 18
      striker-ui/types/AnvilServers.d.ts
  25. 10
      striker-ui/types/AnvilSharedStorage.d.ts
  26. 13
      striker-ui/types/AnvilStatus.d.ts
  27. 21
      striker-ui/types/ProcessNetworkFunction.d.ts

@ -5,6 +5,7 @@ import { Dispatch, SetStateAction } from 'react';
import { BodyText, HeaderText } from './Text';
import { ICONS, ICON_SIZE } from '../lib/consts/ICONS';
import { DIVIDER, GREY } from '../lib/consts/DEFAULT_THEME';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
const PREFIX = 'AnvilDrawer';
@ -77,7 +78,7 @@ const AnvilDrawer = ({ open, setOpen }: DrawerProps): JSX.Element => (
href={
icon.uri.search(/^https?:/) !== -1
? icon.uri
: `${process.env.NEXT_PUBLIC_API_URL}${icon.uri}`
: `${API_BASE_URL}${icon.uri}`
}
>
<Box display="flex" flexDirection="row" width="100%">

@ -1,12 +1,13 @@
import { Box, styled, Switch } from '@mui/material';
import { useContext } from 'react';
import Box from '@mui/material/Box';
import Switch from '@mui/material/Switch';
import { styled } from '@mui/material/styles';
import { HeaderText } from '../Text';
import anvilState from '../../lib/consts/ANVILS';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { AnvilContext } from '../AnvilContext';
import Decorator, { Colours } from '../Decorator';
import putFetch from '../../lib/fetchers/putFetch';
import { HeaderText } from '../Text';
const PREFIX = 'SelectedAnvil';
@ -69,12 +70,17 @@ const SelectedAnvil = ({ list }: { list: AnvilListItem[] }): JSX.Element => {
<Box p={1}>
<Switch
checked={isAnvilOn(list[index])}
onChange={() =>
putFetch(`${process.env.NEXT_PUBLIC_API_URL}/set_power`, {
anvil_uuid: list[index].anvil_uuid,
is_on: !isAnvilOn(list[index]),
})
}
onChange={() => {
const { [index]: litem } = list;
const { anvil_uuid: auuid } = litem;
putFetch(
`${API_BASE_URL}/command/${
isAnvilOn(litem) ? 'stop-an' : 'start-an'
}/${auuid}`,
{},
);
}}
/>
</Box>
</>

@ -4,13 +4,16 @@ import SelectedAnvil from './SelectedAnvil';
import AnvilList from './AnvilList';
import sortAnvils from './sortAnvils';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
const Anvils = ({ list }: { list: AnvilList | undefined }): JSX.Element => {
const anvils: AnvilListItem[] = [];
list?.anvils.forEach((anvil: AnvilListItem) => {
const { anvil_uuid } = anvil;
const { data } = periodicFetch<AnvilStatus>(
`${process.env.NEXT_PUBLIC_API_URL}/get_status?anvil_uuid=${anvil.anvil_uuid}`,
`${API_BASE_URL}/anvil/${anvil_uuid}`,
);
anvils.push({
...anvil,

@ -1,5 +1,7 @@
import { useContext, useMemo } from 'react';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
import { AnvilContext } from './AnvilContext';
import FlexBox from './FlexBox';
import { Panel, PanelHeader } from './Panels';
@ -11,9 +13,7 @@ const CPU = (): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { data: { allocated = 0, cores = 0, threads = 0 } = {}, isLoading } =
periodicFetch<AnvilCPU>(
`${process.env.NEXT_PUBLIC_API_URL}/get_cpu?anvil_uuid=${uuid}`,
);
periodicFetch<AnvilCPU>(`${API_BASE_URL}/anvil/${uuid}/cpu`);
const contentAreaElement = useMemo(
() =>

@ -1,93 +0,0 @@
import { useContext } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { BodyText, HeaderText } from '../Text';
import { Panel, InnerPanel, InnerPanelHeader } from '../Panels';
import SharedStorageHost from './FileSystemsHost';
import periodicFetch from '../../lib/fetchers/periodicFetch';
import { AnvilContext } from '../AnvilContext';
import Spinner from '../Spinner';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
const PREFIX = 'SharedStorage';
const classes = {
header: `${PREFIX}-header`,
root: `${PREFIX}-root`,
};
const StyledDiv = styled('div')(({ theme }) => ({
[`& .${classes.header}`]: {
paddingTop: '.1em',
paddingRight: '.7em',
},
[`& .${classes.root}`]: {
overflow: 'auto',
height: '78vh',
paddingLeft: '.3em',
[theme.breakpoints.down(LARGE_MOBILE_BREAKPOINT)]: {
height: '100%',
},
},
}));
const SharedStorage = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { data, isLoading } = periodicFetch<{
file_systems: AnvilFileSystem[];
}>(
`${process.env.NEXT_PUBLIC_API_URL}/get_shared_storage?anvil_uuid=${uuid}`,
);
return (
<Panel>
<StyledDiv>
<HeaderText text="Shared Storage" />
{!isLoading ? (
<Box className={classes.root}>
{data?.file_systems &&
data.file_systems.map(
(fs: AnvilFileSystem): JSX.Element => (
<InnerPanel key={fs.mount_point}>
<InnerPanelHeader>
<Box
display="flex"
width="100%"
className={classes.header}
>
<Box>
<BodyText text={fs.mount_point} />
</Box>
</Box>
</InnerPanelHeader>
{fs?.hosts &&
fs.hosts.map(
(
host: AnvilFileSystemHost,
index: number,
): JSX.Element => (
<SharedStorageHost
host={{
...host,
...anvil[
anvil.findIndex((a) => a.anvil_uuid === uuid)
].hosts[index],
}}
key={fs.hosts[index].free}
/>
),
)}
</InnerPanel>
),
)}
</Box>
) : (
<Spinner />
)}
</StyledDiv>
</Panel>
);
};
export default SharedStorage;

@ -1,87 +0,0 @@
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import * as prettyBytes from 'pretty-bytes';
import { AllocationBar } from '../Bars';
import { BodyText } from '../Text';
import Decorator from '../Decorator';
const PREFIX = 'SharedStorageHost';
const classes = {
fs: `${PREFIX}-fs`,
bar: `${PREFIX}-bar`,
decoratorBox: `${PREFIX}-decoratorBox`,
};
const StyledDiv = styled('div')(() => ({
[`& .${classes.fs}`]: {
paddingLeft: '.7em',
paddingRight: '.7em',
paddingTop: '1.2em',
},
[`& .${classes.bar}`]: {
paddingLeft: '.7em',
paddingRight: '.7em',
},
[`& .${classes.decoratorBox}`]: {
paddingRight: '.3em',
},
}));
const SharedStorageHost = ({
host,
}: {
host: AnvilFileSystemHost;
}): JSX.Element => (
<StyledDiv>
<Box display="flex" width="100%" className={classes.fs}>
<Box flexGrow={1}>
<BodyText text={host.host_name || 'Not Available'} />
</Box>
<Box className={classes.decoratorBox}>
<Decorator colour={host.is_mounted ? 'ok' : 'error'} />
</Box>
<Box>
<BodyText text={host.is_mounted ? 'Mounted' : 'Not Mounted'} />
</Box>
</Box>
{host.is_mounted && (
<>
<Box display="flex" width="100%" className={classes.fs}>
<Box flexGrow={1}>
<BodyText
text={`Used: ${prettyBytes.default(host.total - host.free, {
binary: true,
})}`}
/>
</Box>
<Box>
<BodyText
text={`Free: ${prettyBytes.default(host.free, {
binary: true,
})}`}
/>
</Box>
</Box>
<Box display="flex" width="100%" className={classes.bar}>
<Box flexGrow={1}>
<AllocationBar
allocated={((host.total - host.free) / host.total) * 100}
/>
</Box>
</Box>
<Box display="flex" justifyContent="center" width="100%">
<BodyText
text={`Total Storage: ${prettyBytes.default(host.total, {
binary: true,
})}`}
/>
</Box>
</>
)}
</StyledDiv>
);
export default SharedStorageHost;

@ -1,3 +0,0 @@
import SharedStorage from './FileSystems';
export default SharedStorage;

@ -3,7 +3,6 @@ import { AppBar, Box, Button, IconButton, styled } from '@mui/material';
import { useRef, useState } from 'react';
import { BORDER_RADIUS, OLD_ICON, RED } from '../lib/consts/DEFAULT_THEME';
import { ICONS, ICON_SIZE } from '../lib/consts/ICONS';
import AnvilDrawer from './AnvilDrawer';
import FlexBox from './FlexBox';
@ -90,26 +89,6 @@ const Header = (): JSX.Element => {
<IconWithIndicator icon={AssignmentIcon} ref={jobIconRef} />
</IconButton>
</Box>
{ICONS.map(
(icon): JSX.Element => (
<a
key={icon.uri}
href={
icon.uri.search(/^https?:/) !== -1
? icon.uri
: `${process.env.NEXT_PUBLIC_API_URL}${icon.uri}`
}
>
<img
alt=""
key="icon"
src={icon.image}
{...ICON_SIZE}
className={classes.icons}
/>
</a>
),
)}
</FlexBox>
</Box>
</StyledAppBar>

@ -1,13 +1,14 @@
import { Box, Switch } from '@mui/material';
import { styled } from '@mui/material/styles';
import { InnerPanel, InnerPanelHeader } from '../Panels';
import { ProgressBar } from '../Bars';
import { BodyText } from '../Text';
import Decorator, { Colours } from '../Decorator';
import { Box, styled, Switch } from '@mui/material';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
import HOST_STATUS from '../../lib/consts/NODES';
import { ProgressBar } from '../Bars';
import Decorator, { Colours } from '../Decorator';
import { InnerPanel, InnerPanelHeader } from '../Panels';
import putFetch from '../../lib/fetchers/putFetch';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
import { BodyText } from '../Text';
const PREFIX = 'AnvilHost';
@ -111,11 +112,12 @@ const AnvilHost = ({
checked={host.state === 'online'}
onChange={() =>
putFetch(
`${process.env.NEXT_PUBLIC_API_URL}/set_power`,
{
host_uuid: host.host_uuid,
is_on: !(host.state === 'online'),
},
`${API_BASE_URL}/command/${
host.state === 'online'
? 'stop-subnode'
: 'start-subnode'
}/${host.host_uuid}`,
{},
)
}
/>
@ -129,11 +131,10 @@ const AnvilHost = ({
disabled={!(host.state === 'online')}
onChange={() =>
putFetch(
`${process.env.NEXT_PUBLIC_API_URL}/set_membership`,
{
host_uuid: host.host_uuid,
is_member: !(host.state === 'online'),
},
`${API_BASE_URL}/command/${
host.state === 'online' ? 'leave-an' : 'join-an'
}/${host.host_uuid}`,
{},
)
}
/>

@ -1,17 +1,19 @@
import { useContext } from 'react';
import { Panel } from '../Panels';
import { HeaderText } from '../Text';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { AnvilContext } from '../AnvilContext';
import AnvilHost from './AnvilHost';
import hostsSanitizer from '../../lib/sanitizers/hostsSanitizer';
import { Panel } from '../Panels';
import periodicFetch from '../../lib/fetchers/periodicFetch';
import { AnvilContext } from '../AnvilContext';
import { HeaderText } from '../Text';
import Spinner from '../Spinner';
import hostsSanitizer from '../../lib/sanitizers/hostsSanitizer';
const Hosts = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { data, isLoading } = periodicFetch<AnvilStatus>(
`${process.env.NEXT_PUBLIC_API_URL}/get_status?anvil_uuid=${uuid}`,
`${API_BASE_URL}/anvil/${uuid}`,
);
const anvilIndex = anvil.findIndex((a) => a.anvil_uuid === uuid);

@ -1,9 +1,11 @@
import { Box } from '@mui/material';
import * as prettyBytes from 'pretty-bytes';
import { useContext } from 'react';
import { useContext, useMemo } from 'react';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
import { AnvilContext } from './AnvilContext';
import { AllocationBar } from './Bars';
import { toBinaryByte } from '../lib/format_data_size_wrappers';
import { Panel, PanelHeader } from './Panels';
import periodicFetch from '../lib/fetchers/periodicFetch';
import Spinner from './Spinner';
@ -12,10 +14,14 @@ import { HeaderText, BodyText } from './Text';
const Memory = (): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { data: { allocated = 0, reserved = 0, total = 0 } = {}, isLoading } =
periodicFetch<AnvilMemory>(
`${process.env.NEXT_PUBLIC_API_URL}/get_memory?anvil_uuid=${uuid}`,
);
const {
data: { allocated = '0', reserved = '0', total = '0' } = {},
isLoading,
} = periodicFetch<AnvilMemory>(`${API_BASE_URL}/anvil/${uuid}/memory`);
const nAllocated = useMemo(() => BigInt(allocated), [allocated]);
const nReserved = useMemo(() => BigInt(reserved), [reserved]);
const nTotal = useMemo(() => BigInt(total), [total]);
return (
<Panel>
@ -26,32 +32,26 @@ const Memory = (): JSX.Element => {
<>
<Box display="flex" width="100%">
<Box flexGrow={1}>
<BodyText
text={`Allocated: ${prettyBytes.default(allocated, {
binary: true,
})}`}
/>
<BodyText text={`Allocated: ${toBinaryByte(nAllocated)}`} />
</Box>
<Box>
<BodyText
text={`Free: ${prettyBytes.default(total - allocated, {
binary: true,
})}`}
/>
<BodyText text={`Free: ${toBinaryByte(nTotal - nAllocated)}`} />
</Box>
</Box>
<Box display="flex" width="100%">
<Box flexGrow={1}>
<AllocationBar allocated={(allocated / total) * 100} />
<AllocationBar
allocated={Number(
((nAllocated + nReserved) * BigInt(100)) / nTotal,
)}
/>
</Box>
</Box>
<Box display="flex" justifyContent="center" width="100%">
<BodyText
text={`Total: ${prettyBytes.default(total, {
binary: true,
})} | Reserved: ${prettyBytes.default(reserved, {
binary: true,
})}`}
text={`Total: ${toBinaryByte(nTotal)} | Reserved: ${toBinaryByte(
nReserved,
)}`}
/>
</Box>
</>

@ -1,6 +1,7 @@
import { Box, Divider, styled } from '@mui/material';
import { useContext } from 'react';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import {
DIVIDER,
LARGE_MOBILE_BREAKPOINT,
@ -13,7 +14,6 @@ import periodicFetch from '../../lib/fetchers/periodicFetch';
import processNetworkData from './processNetwork';
import Spinner from '../Spinner';
import { HeaderText, BodyText } from '../Text';
import useProtect from '../../hooks/useProtect';
import useProtectedState from '../../hooks/useProtectedState';
const PREFIX = 'Network';
@ -71,14 +71,13 @@ const selectDecorator = (state: string): Colours => {
const Network = (): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { protect } = useProtect();
const [processed, setProcessed] = useProtectedState<
ProcessedNetwork | undefined
>(undefined, protect);
>(undefined);
const { isLoading } = periodicFetch<AnvilNetwork>(
`${process.env.NEXT_PUBLIC_API_URL}/get_networks?anvil_uuid=${uuid}`,
`${API_BASE_URL}/anvil/${uuid}/network`,
{
onSuccess: (data) => {
setProcessed(processNetworkData(data));

@ -41,6 +41,7 @@ import { BodyText, HeaderText } from './Text';
import hostsSanitizer from '../lib/sanitizers/hostsSanitizer';
import periodicFetch from '../lib/fetchers/periodicFetch';
import putFetch from '../lib/fetchers/putFetch';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
const PREFIX = 'Servers';
@ -172,22 +173,21 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const buttonLabels = useRef<ButtonLabels[]>([]);
const { data: { servers = [] } = {}, isLoading } =
periodicFetch<AnvilServers>(
`${process.env.NEXT_PUBLIC_API_URL}/get_servers?anvil_uuid=${uuid}`,
const { data: servers = [], isLoading } = periodicFetch<AnvilServers>(
`${API_BASE_URL}/server?anvilUUIDs=${uuid}`,
);
const setButtons = (filtered: AnvilServer[]) => {
buttonLabels.current = [];
if (
filtered.filter((item: AnvilServer) => item.server_state === 'running')
filtered.filter((item: AnvilServer) => item.serverState === 'running')
.length
) {
buttonLabels.current.push('off');
}
if (
filtered.filter((item: AnvilServer) => item.server_state === 'shut off')
filtered.filter((item: AnvilServer) => item.serverState === 'shut off')
.length
) {
buttonLabels.current.push('on');
@ -201,9 +201,13 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const handlePower = (label: ButtonLabels) => {
setAnchorEl(null);
if (selected.length) {
putFetch(`${process.env.NEXT_PUBLIC_API_URL}/set_power`, {
server_uuid_list: selected,
is_on: label === 'on',
selected.forEach((serverUuid) => {
putFetch(
`${API_BASE_URL}/command/${
label === 'on' ? 'start-server' : 'stop-server'
}/${serverUuid}`,
{},
);
});
}
};
@ -215,7 +219,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
else selected.splice(index, 1);
const filtered = servers.filter(
(server: AnvilServer) => selected.indexOf(server.server_uuid) !== -1,
(server: AnvilServer) => selected.indexOf(server.serverUUID) !== -1,
);
setButtons(filtered);
setSelected([...selected]);
@ -285,7 +289,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
setButtons(servers);
setSelected(
servers.map(
(server: AnvilServer) => server.server_uuid,
(server: AnvilServer) => server.serverUUID,
),
);
} else {
@ -311,10 +315,10 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
<ListItem
button
className={classes.button}
key={server.server_uuid}
key={server.serverUUID}
component={showCheckbox ? 'div' : 'a'}
href={`/server?uuid=${server.server_uuid}&server_name=${server.server_name}`}
onClick={() => handleChange(server.server_uuid)}
href={`/server?uuid=${server.serverUUID}&server_name=${server.serverName}`}
onClick={() => handleChange(server.serverUUID)}
>
<Box display="flex" flexDirection="row" width="100%">
{showCheckbox && (
@ -324,7 +328,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
color="secondary"
checked={
selected.find(
(s) => s === server.server_uuid,
(s) => s === server.serverUUID,
) !== undefined
}
/>
@ -332,21 +336,21 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
)}
<Box p={1}>
<Decorator
colour={selectDecorator(server.server_state)}
colour={selectDecorator(server.serverState)}
/>
</Box>
<Box p={1} flexGrow={1}>
<BodyText text={server.server_name} />
<BodyText text={server.serverName} />
<BodyText
text={
serverState.get(server.server_state) ||
serverState.get(server.serverState) ||
'Not Available'
}
/>
</Box>
<Box display="flex" className={classes.hostsBox}>
{server.server_state !== 'shut off' &&
server.server_state !== 'crashed' &&
{server.serverState !== 'shut off' &&
server.serverState !== 'crashed' &&
filteredHosts.map(
(
host: AnvilStatusHost,
@ -361,8 +365,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
<BodyText
text={host.host_name}
selected={
server.server_host_uuid ===
host.host_uuid
server.serverHostUUID === host.host_uuid
}
/>
</Box>

@ -1,14 +1,15 @@
import { Box, styled } from '@mui/material';
import { useContext } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { BodyText, HeaderText } from '../Text';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
import { AnvilContext } from '../AnvilContext';
import { Panel, InnerPanel, InnerPanelHeader } from '../Panels';
import SharedStorageHost from './SharedStorageHost';
import periodicFetch from '../../lib/fetchers/periodicFetch';
import { AnvilContext } from '../AnvilContext';
import SharedStorageHost from './SharedStorageHost';
import Spinner from '../Spinner';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
import { BodyText, HeaderText } from '../Text';
const PREFIX = 'SharedStorage';
@ -30,9 +31,11 @@ const StyledDiv = styled('div')(({ theme }) => ({
const SharedStorage = (): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { data, isLoading } = periodicFetch<AnvilSharedStorage>(
`${process.env.NEXT_PUBLIC_API_URL}/get_shared_storage?anvil_uuid=${uuid}`,
`${API_BASE_URL}/anvil/${uuid}/store`,
);
return (
<Panel>
<StyledDiv>

@ -1,7 +1,8 @@
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import * as prettyBytes from 'pretty-bytes';
import { Box, styled } from '@mui/material';
import { useMemo } from 'react';
import { AllocationBar } from '../Bars';
import { toBinaryByte } from '../../lib/format_data_size_wrappers';
import { BodyText } from '../Text';
const PREFIX = 'SharedStorageHost';
@ -32,46 +33,38 @@ const SharedStorageHost = ({
group,
}: {
group: AnvilSharedStorageGroup;
}): JSX.Element => (
}): JSX.Element => {
const { storage_group_free: sgFree, storage_group_total: sgTotal } = group;
const nFree = useMemo(() => BigInt(sgFree), [sgFree]);
const nTotal = useMemo(() => BigInt(sgTotal), [sgTotal]);
const nAllocated = useMemo(() => nTotal - nFree, [nFree, nTotal]);
const percentAllocated = useMemo(
() => Number((nAllocated * BigInt(100)) / nTotal),
[nAllocated, nTotal],
);
return (
<StyledDiv>
<Box display="flex" width="100%" className={classes.fs}>
<Box flexGrow={1}>
<BodyText
text={`Used: ${prettyBytes.default(
group.storage_group_total - group.storage_group_free,
{
binary: true,
},
)}`}
/>
<BodyText text={`Used: ${toBinaryByte(nTotal - nFree)}`} />
</Box>
<Box>
<BodyText
text={`Free: ${prettyBytes.default(group.storage_group_free, {
binary: true,
})}`}
/>
<BodyText text={`Free: ${toBinaryByte(nFree)}`} />
</Box>
</Box>
<Box display="flex" width="100%" className={classes.bar}>
<Box flexGrow={1}>
<AllocationBar
allocated={
((group.storage_group_total - group.storage_group_free) /
group.storage_group_total) *
100
}
/>
<AllocationBar allocated={percentAllocated} />
</Box>
</Box>
<Box display="flex" justifyContent="center" width="100%">
<BodyText
text={`Total Storage: ${prettyBytes.default(group.storage_group_total, {
binary: true,
})}`}
/>
<BodyText text={`Total Storage: ${toBinaryByte(nTotal)}`} />
</Box>
</StyledDiv>
);
};
export default SharedStorageHost;

@ -1,53 +0,0 @@
import { Grid } from '@mui/material';
import * as prettyBytes from 'pretty-bytes';
import { useMemo } from 'react';
import { AllocationBar } from './Bars';
import { Panel } from './Panels';
import periodicFetch from '../lib/fetchers/periodicFetch';
import Spinner from './Spinner';
import { HeaderText, BodyText } from './Text';
// TODO: need to be removed or revised because it's likely unused.
const Storage = ({ uuid }: { uuid: string }): JSX.Element => {
const { data: { free = 0, total = 0 } = {}, isLoading } =
periodicFetch<AnvilMemory>(
`${process.env.NEXT_PUBLIC_API_URL}/get_memory?anvil_uuid=${uuid}`,
);
const contentLayoutElement = useMemo(
() => (
<Grid container alignItems="center" justifyContent="space-around">
<Grid item xs={12}>
<HeaderText text="Storage Resync" />
</Grid>
<Grid item xs={5}>
<BodyText
text={`Allocated: ${prettyBytes.default(total - free, {
binary: true,
})}`}
/>
</Grid>
<Grid item xs={4}>
<BodyText
text={`Free: ${prettyBytes.default(free, {
binary: true,
})}`}
/>
</Grid>
<Grid item xs={10}>
<AllocationBar allocated={((total - free) / total) * 100} />
</Grid>
</Grid>
),
[free, total],
);
const contentAreaElement = useMemo(
() => (isLoading ? <Spinner /> : contentLayoutElement),
[contentLayoutElement, isLoading],
);
return <Panel>{contentAreaElement}</Panel>;
};
export default Storage;

@ -3,6 +3,7 @@ import Head from 'next/head';
import { useRouter } from 'next/router';
import { useContext, useEffect, useMemo } from 'react';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME';
import AnvilProvider, { AnvilContext } from '../../components/AnvilContext';
@ -65,7 +66,7 @@ const Anvil = (): JSX.Element => {
const { anvil_uuid: queryAnvilUUID } = router.query;
const { uuid: contextAnvilUUID, setAnvilUuid } = useContext(AnvilContext);
const { data, isLoading } = periodicFetch<AnvilList>(
`${process.env.NEXT_PUBLIC_API_URL}/get_anvils`,
`${API_BASE_URL}/anvil/summary`,
);
const contentLayoutElement = useMemo(() => {

@ -0,0 +1,88 @@
type AnvilCPU = {
allocated: number;
cores: number;
threads: number;
};
type AnvilMemory = {
allocated: string;
reserved: string;
total: string;
};
type AnvilNetworkBondLink = {
link_name: string;
link_uuid: string;
link_speed: number;
link_state: 'optimal' | 'degraded' | 'down';
is_active: boolean;
};
type AnvilNetworkHostBond = {
bond_name: string;
bond_uuid: string;
links: AnvilNetworkBondLink[];
};
type AnvilNetworkHosts = {
host_name: string;
host_uuid: string;
bonds: AnvilNetworkHostBond[];
};
type AnvilNetwork = {
hosts: AnvilNetworkHosts[];
};
type AnvilServer = {
anvilName: string;
anvilUUID: string;
serverName: string;
serverUUID: string;
serverState:
| 'running'
| 'idle'
| 'paused'
| 'in shutdown'
| 'shut off'
| 'crashed'
| 'pmsuspended'
| 'migrating';
serverHostUUID: string;
};
type AnvilServers = AnvilServer[];
type AnvilSharedStorageGroup = {
storage_group_free: string;
storage_group_name: string;
storage_group_total: string;
storage_group_uuid: string;
};
type AnvilSharedStorage = {
storage_groups: AnvilSharedStorageGroup[];
};
type AnvilStatusHost = {
state: 'offline' | 'booted' | 'crmd' | 'in_ccm' | 'online';
host_uuid: string;
host_name: string;
state_percent: number;
state_message: string;
removable: boolean;
};
type AnvilStatus = {
anvil_state: 'optimal' | 'not_ready' | 'degraded';
hosts: AnvilStatusHost[];
};
type AnvilListItem = {
anvil_name: string;
anvil_uuid: string;
} & AnvilStatus;
type AnvilList = {
anvils: AnvilListItem[];
};

@ -1,5 +0,0 @@
declare type AnvilCPU = {
cores: number;
threads: number;
allocated: number;
};

@ -1,16 +0,0 @@
declare type AnvilFileSystemHost = {
host_uuid: string;
host_name: string;
is_mounted: boolean;
total: number;
free: number;
};
declare type AnvilFileSystem = {
mount_point: string;
hosts: Array<AnvilFileSystemHost>;
};
declare type AnvilFileSystems = {
file_systems: Array<AnvilFileSystem>;
};

@ -1,8 +0,0 @@
declare type AnvilListItem = {
anvil_name: string;
anvil_uuid: string;
} & AnvilStatus;
declare type AnvilList = {
anvils: Array<AnvilListItem>;
};

@ -1,6 +0,0 @@
declare type AnvilMemory = {
allocated: number;
free: number;
reserved: number;
total: number;
};

@ -1,45 +0,0 @@
declare type AnvilNetworkBondLink = {
link_name: string;
link_uuid: string;
link_speed: number;
link_state: 'optimal' | 'degraded' | 'down';
is_active: boolean;
};
declare type AnvilNetworkHostBond = {
bond_name: string;
bond_uuid: string;
links: Array<AnvilNetworkBondLink>;
};
declare type AnvilNetworkHosts = {
host_name: string;
host_uuid: string;
bonds: Array<AnvilNetworkHostBond>;
};
declare type AnvilNetwork = {
hosts: Array<AnvilNetworkHosts>;
};
declare type ProcessedBond = {
bond_name: string;
bond_uuid: string;
bond_speed: number;
bond_state: 'optimal' | 'degraded' | 'down';
hosts: Array<{
host_name: string;
host_uuid: string;
link: {
link_name: string;
link_uuid: string;
link_speed: number;
link_state: 'optimal' | 'degraded' | 'down';
is_active: boolean;
};
}>;
};
declare type ProcessedNetwork = {
bonds: Array<ProcessedBond>;
};

@ -1,18 +0,0 @@
declare type AnvilServer = {
server_name: string;
server_uuid: string;
server_state:
| 'running'
| 'idle'
| 'paused'
| 'in shutdown'
| 'shut off'
| 'crashed'
| 'pmsuspended'
| 'migrating';
server_host_uuid: string;
};
declare type AnvilServers = {
servers: Array<AnvilServer>;
};

@ -1,10 +0,0 @@
declare type AnvilSharedStorageGroup = {
storage_group_name: string;
storage_group_uuid: string;
storage_group_total: number;
storage_group_free: number;
};
declare type AnvilSharedStorage = {
storage_groups: Array<AnvilSharedStorageGroup>;
};

@ -1,13 +0,0 @@
declare type AnvilStatusHost = {
state: 'offline' | 'booted' | 'crmd' | 'in_ccm' | 'online';
host_uuid: string;
host_name: string;
state_percent: number;
state_message: string;
removable: boolean;
};
declare type AnvilStatus = {
anvil_state: 'optimal' | 'not_ready' | 'degraded';
hosts: Array<AnvilStatusHost>;
};

@ -0,0 +1,21 @@
type ProcessedBond = {
bond_name: string;
bond_uuid: string;
bond_speed: number;
bond_state: 'optimal' | 'degraded' | 'down';
hosts: Array<{
host_name: string;
host_uuid: string;
link: {
link_name: string;
link_uuid: string;
link_speed: number;
link_state: 'optimal' | 'degraded' | 'down';
is_active: boolean;
};
}>;
};
type ProcessedNetwork = {
bonds: ProcessedBond[];
};
Loading…
Cancel
Save