[WIFI-13169] Add support for master/slave nodes

Signed-off-by: Charles <charles.bourque96@gmail.com>
This commit is contained in:
Charles
2023-11-21 17:18:08 +00:00
parent d759749a43
commit ea6d16cae4
6 changed files with 81 additions and 9 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "owls-ui",
"version": "3.0.0(2)",
"version": "3.0.0(3)",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "owls-ui",
"version": "3.0.0(2)",
"version": "3.0.0(3)",
"license": "BSD-3-Clause",
"dependencies": {
"@chakra-ui/icons": "^2.0.18",

View File

@@ -1,6 +1,6 @@
{
"name": "owls-ui",
"version": "3.0.0(2)",
"version": "3.0.0(3)",
"description": "",
"private": true,
"main": "index.tsx",

View File

@@ -32,12 +32,17 @@ export const AuthProvider = ({ token, defaultEndpoints, children }: AuthProvider
const { data: configurationDescriptions } = useGetConfigurationDescriptions({
enabled: loadedEndpoints && defaultEndpoints === undefined,
});
const [owlsAdminCount, setOwlsAdminCount] = useState(0);
const { data: user, refetch: refetchUser } = useGetProfile();
const { refetch: refetchEndpoints } = useGetEndpoints({
onSuccess: async (newEndpoints: Endpoint[]) => {
const foundEndpoints: { [key: string]: string } = {};
// @ts-ignore
const owlsAdmin = await getOwlsAdmin(newEndpoints, axiosSec.defaults.headers.common.Authorization ?? '');
const { endpoint: owlsAdmin, owlsAdminCount: owlsCount } = await getOwlsAdmin(
newEndpoints,
// @ts-ignore
axiosSec.defaults.headers.common.Authorization ?? '',
);
setOwlsAdminCount(owlsCount);
if (owlsAdmin) {
axiosOwls.defaults.baseURL = `${owlsAdmin.uri}/api/v1`;
}
@@ -178,8 +183,19 @@ export const AuthProvider = ({ token, defaultEndpoints, children }: AuthProvider
endpoints,
configurationDescriptions,
isUserLoaded: preferences !== undefined && user !== undefined && loadedEndpoints,
owlsAdminCount,
}),
[currentToken, user, avatar, preferences, loadedEndpoints, configurationDescriptions, endpoints, ref],
[
currentToken,
user,
avatar,
preferences,
loadedEndpoints,
configurationDescriptions,
endpoints,
ref,
owlsAdminCount,
],
);
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;

View File

@@ -37,6 +37,7 @@ export interface AuthProviderReturn {
endpoints: { [key: string]: string } | null;
configurationDescriptions: Record<string, unknown>;
isUserLoaded: boolean;
owlsAdminCount: number;
}
export const getOwlsStatus = (endpoint: Endpoint, token: string) =>
@@ -70,6 +71,7 @@ export const useGetOwlStatus = ({
export const getOwlsAdmin = async (endpoints: Endpoint[], token: string) => {
let owlsTypeCount = 0;
let owlsAdminCount = 0;
let owlsAdmin: Endpoint | undefined;
for (const endpoint of endpoints) {
if (endpoint.type === 'owls') {
@@ -79,14 +81,15 @@ export const getOwlsAdmin = async (endpoints: Endpoint[], token: string) => {
if (res && res.master) {
owlsAdmin = endpoint;
break;
owlsAdminCount += 1;
}
}
}
if (owlsTypeCount === 1) {
return endpoints.find((endpoint) => endpoint.type === 'owls');
owlsAdminCount = 1;
return { endpoint: endpoints.find((endpoint) => endpoint.type === 'owls'), owlsAdminCount };
}
return owlsAdmin;
return { endpoint: owlsAdmin, owlsAdminCount };
};

View File

@@ -0,0 +1,46 @@
import * as React from 'react';
import {
Alert,
AlertTitle,
Code,
Heading,
ListItem,
Modal,
ModalBody,
ModalContent,
ModalOverlay,
UnorderedList,
} from '@chakra-ui/react';
type Props = {
count: number;
};
const AdminOwlsModal = ({ count }: Props) => (
<Modal onClose={() => {}} isOpen closeOnOverlayClick={false} closeOnEsc={false}>
<ModalOverlay />
<ModalContent>
<ModalBody>
<Alert status="warning" my={4}>
<AlertTitle>
There are {count} OWLS master nodes. The system will encounter issues if there is not exactly one master
node
</AlertTitle>
</Alert>
<Heading size="sm" mb={2}>
To fix this issue:
</Heading>
<UnorderedList>
<ListItem>
Add <Code>simulator.master = true</Code> to the configuration of the master node
</ListItem>
<ListItem>
Add <Code>simulator.master = false</Code> to the configuration(s) of any of your secondary nodes (if any)
</ListItem>
</UnorderedList>
</ModalBody>
</ModalContent>
</Modal>
);
export default AdminOwlsModal;

View File

@@ -3,12 +3,14 @@ import { useBoolean, useColorMode } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { Route, Routes, useLocation } from 'react-router-dom';
import { v4 as uuid } from 'uuid';
import AdminOwlsModal from './AdminOwlsModal';
import { Navbar } from './Navbar';
import { PageContainer } from './PageContainer';
import { Sidebar } from './Sidebar';
import darkLogo from 'assets/Logo_Dark_Mode.svg';
import lightLogo from 'assets/Logo_Light_Mode.svg';
import LanguageSwitcher from 'components/LanguageSwitcher';
import { useAuth } from 'contexts/AuthProvider';
import { RouteName } from 'models/Routes';
import NotFoundPage from 'pages/NotFound';
import routes from 'router/routes';
@@ -19,6 +21,7 @@ const Layout = () => {
const { colorMode } = useColorMode();
const [isSidebarOpen, { toggle: toggleSidebar }] = useBoolean(false);
document.documentElement.dir = 'ltr';
const { isUserLoaded, owlsAdminCount } = useAuth();
const activeRoute = React.useMemo(() => {
let name: RouteName = '';
@@ -73,6 +76,10 @@ const Layout = () => {
return instances;
}, []);
if (isUserLoaded && owlsAdminCount !== 1) {
return <AdminOwlsModal count={owlsAdminCount} />;
}
return (
<>
<Sidebar