Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-11492 Cluster and Cache enable/disable rebalancing #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/CacheManagers/CacheManagers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {useTranslation} from 'react-i18next';
import {useConnectedUser} from "@app/services/userManagementHook";
import {ConsoleServices} from "@services/ConsoleServices";
import {ConsoleACL} from "@services/securityService";
import {RebalancingCacheManager} from "@app/CacheManagers/RebalancingCacheManager";

const CacheManagers = () => {
const { connectedUser } = useConnectedUser();
Expand Down Expand Up @@ -207,6 +208,7 @@ const CacheManagers = () => {
<Status status={cm.cache_manager_status} />
</FlexItem>
{buildSiteDisplay(cm.local_site)}
<RebalancingCacheManager/>
</Flex>
</Flex>
{buildTabs()}
Expand Down
58 changes: 49 additions & 9 deletions src/app/CacheManagers/CacheTableDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
EmptyState,
EmptyStateBody,
EmptyStateIcon,
EmptyStateVariant,
EmptyStateVariant, Label, LabelGroup,
Pagination,
Select,
SelectGroup,
Expand All @@ -35,7 +35,7 @@ import {IgnoreCache} from '@app/Caches/IgnoreCache';
import {IExtraData, IRowData,} from '@patternfly/react-table/src/components/Table';
import {Health} from '@app/Common/Health';
import {useBanner} from '@app/utils/useApiAlert';
import {useCaches} from '@app/services/dataContainerHooks';
import {useCaches, useDataContainer} from '@app/services/dataContainerHooks';
import {useTranslation} from 'react-i18next';
import {useConnectedUser} from "@app/services/userManagementHook";
import {ConsoleServices} from "@services/ConsoleServices";
Expand All @@ -55,6 +55,7 @@ const CacheTableDisplay = (props: {
}) => {
const { setBanner } = useBanner();
const { connectedUser } = useConnectedUser();
const { cm } = useDataContainer();
const { caches, errorCaches, loadingCaches } = useCaches();
const [filteredCaches, setFilteredCaches] = useState<CacheInfo[]>([]);
const [cachesPagination, setCachesPagination] = useState({
Expand Down Expand Up @@ -178,7 +179,7 @@ const CacheTableDisplay = (props: {
}, [cachesPagination]);

const columns = [
{ title: t('cache-managers.cache-name'), transforms: [cellWidth(30), textCenter] },
{ title: t('cache-managers.cache-name'), transforms: [cellWidth(25), textCenter] },
{
title: t('cache-managers.cache-mode'),
transforms: [cellWidth(15), textCenter],
Expand All @@ -190,13 +191,13 @@ const CacheTableDisplay = (props: {
},
{
title: t('cache-managers.cache-features'),
transforms: [textCenter],
transforms: [textCenter, cellWidth(30)],
cellTransforms: [textCenter],
},
{
// Will display 'ignored' if the cache is ignored
title: t('cache-managers.cache-status'),
transforms: [cellWidth(15), textCenter],
transforms: [textCenter],
cellTransforms: [textCenter],
},
];
Expand Down Expand Up @@ -345,7 +346,7 @@ const CacheTableDisplay = (props: {
),
},
{ title: displayCacheFeatures(cacheInfo) },
{ title: displayIfIgnored(cacheInfo) },
{ title: displayBadges(cacheInfo) },
],
};
});
Expand All @@ -363,14 +364,53 @@ const CacheTableDisplay = (props: {
);
};

const displayIfIgnored = (cacheInfo: CacheInfo) => {
const ignoreCacheBadge = (cacheInfo: CacheInfo) => {
if (!isCacheIgnored(cacheInfo)) {
return '';
}
return (
<Badge key={`ignore-${cacheInfo.name}`} isRead>
<Label key={`ignore-${cacheInfo.name}`}>
{t('cache-managers.ignored-status')}
</Badge>
</Label>);
}

/**
* Display the badge only of rebalancing is enabled at cluster level
* and the cache has rebalancing disabled. Check cluster level since we
* don't want to display a badge for all the caches
*
* @param cacheInfo
*/
const rebalancingOffBadge = (cacheInfo: CacheInfo) => {
if(!cm.rebalancing_enabled) {
return '';
}

if (cacheInfo.rebalancing_enabled != undefined && cacheInfo.rebalancing_enabled) {
return '';
}

return (
<Label key={`ignore-${cacheInfo.name}`}>
{t('cache-managers.rebalancing-disabled-status')}
</Label>
)
}

const displayBadges = (cacheInfo: CacheInfo) => {
const badgeIgnore = ignoreCacheBadge(cacheInfo);
const badgeRebalancing = rebalancingOffBadge(cacheInfo);

if (badgeIgnore == '' && badgeRebalancing == '') {
return '';
}

return (
<LabelGroup>
{badgeIgnore}
{badgeRebalancing}
</LabelGroup>

);
};

Expand Down
51 changes: 51 additions & 0 deletions src/app/CacheManagers/RebalancingCacheManager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import {Divider, FlexItem, Spinner, Switch} from '@patternfly/react-core';
import {useConnectedUser} from "@app/services/userManagementHook";
import {ConsoleServices} from "@services/ConsoleServices";
import {ConsoleACL} from "@services/securityService";
import {useTranslation} from "react-i18next";
import {useApiAlert} from "@app/utils/useApiAlert";
import {useDataContainer} from "@app/services/dataContainerHooks";

const RebalancingCacheManager = () => {
const { addAlert } = useApiAlert();
const { t } = useTranslation();
const { connectedUser } = useConnectedUser();
const { cm, loading, reload } = useDataContainer();

if (loading || !cm) {
return (
<FlexItem>
<Spinner size={'md'} />
</FlexItem>
);
}

if (ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser) && cm.rebalancing_enabled != undefined) {
return (
<React.Fragment>
<Divider isVertical />
<FlexItem>
<Switch
id="rebalancing-switch"
label={t('cache-managers.rebalancing-enabled')}
labelOff={t('cache-managers.rebalancing-disabled')}
isChecked={cm.rebalancing_enabled}
onChange={() => {
ConsoleServices.dataContainer().rebalancing(cm.name, !cm.rebalancing_enabled)
.then(r => {
addAlert(r);
reload();
})
}}
/>
</FlexItem>
</React.Fragment>
);
}

// Return nothing if the connected user is not ADMIN
return (<FlexItem></FlexItem>);
};

export { RebalancingCacheManager };
34 changes: 21 additions & 13 deletions src/app/Caches/DetailCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {ConsoleServices} from "@services/ConsoleServices";
import {ConsoleACL} from "@services/securityService";
import {useConnectedUser} from "@app/services/userManagementHook";
import {useTranslation} from "react-i18next";
import {RebalancingCache} from "@app/Caches/RebalancingCache";

const DetailCache = (props: { cacheName: string }) => {
const cacheName = props.cacheName;
Expand Down Expand Up @@ -104,17 +105,7 @@ const DetailCache = (props: { cacheName: string }) => {
};

const buildDetailContent = () => {
if (loading) {
return (
<Card>
<CardBody>
<Spinner size="xl" />
</CardBody>
</Card>
);
}

if (error.length > 0 || !cache) {
if (error.length > 0) {
return (
<Card>
<CardBody>
Expand Down Expand Up @@ -142,6 +133,16 @@ const DetailCache = (props: { cacheName: string }) => {
);
}

if (loading || !cache) {
return (
<Card>
<CardBody>
<Spinner size="xl" />
</CardBody>
</Card>
);
}

if(activeTabKey1 == 0
&& cache.editable
&& ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser)) {
Expand All @@ -162,6 +163,8 @@ const DetailCache = (props: { cacheName: string }) => {
};

const buildRebalancing = () => {
if (!cache) return ;

if (!cache?.rehash_in_progress) {
return (
<ToolbarItem>
Expand Down Expand Up @@ -308,7 +311,7 @@ const DetailCache = (props: { cacheName: string }) => {
</ToolbarItem>
</ToolbarGroup>
<ToolbarGroup>
{buildRebalancing()}
<RebalancingCache/>
{buildBackupsManage()}
{buildIndexManage()}
</ToolbarGroup>
Expand Down Expand Up @@ -416,7 +419,12 @@ const DetailCache = (props: { cacheName: string }) => {
activeKey={activeTabKey1}
isSecondary={true}
component={TabsComponent.nav}
onSelect={(event, tabIndex) => setActiveTabKey1(tabIndex)}
onSelect={(event, tabIndex) => {
setActiveTabKey1(tabIndex);
if (tabIndex == 0) {
loadCache(cacheName);
}
}}
>
{displayCacheEntries()}
{displayConfiguration()}
Expand Down
79 changes: 79 additions & 0 deletions src/app/Caches/RebalancingCache.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import {Label, Spinner, Switch, ToolbarItem} from '@patternfly/react-core';
import {useCacheDetail} from "@app/services/cachesHook";
import {useConnectedUser} from "@app/services/userManagementHook";
import {ConsoleServices} from "@services/ConsoleServices";
import {ConsoleACL} from "@services/securityService";
import {useTranslation} from "react-i18next";
import {useApiAlert} from "@app/utils/useApiAlert";
import {useDataContainer} from "@app/services/dataContainerHooks";

const RebalancingCache = () => {
const { addAlert } = useApiAlert();
const { t } = useTranslation();
const { connectedUser } = useConnectedUser();
const { cache, cacheManager, loading, reload } = useCacheDetail();

// If rebalancing is not activated at cluster level, don't display anything
if (!cacheManager.rebalancing_enabled || cache.rebalancing_enabled == undefined) {
return ( <ToolbarItem/>)
}

if (loading || !cache) {
return (
<ToolbarItem>
<Spinner size={'md'} />
</ToolbarItem>
);
}

/**
* When the rehash is in progress just display the value
*/
if (cache?.rehash_in_progress) {
return (
<ToolbarItem>
<Spinner size={'md'} /> {t('caches.info.rebalancing')}
</ToolbarItem>
);
}

/**
* If the user is ADMIN, can enable and disable rebalancing
*/
if (ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser)) {
return (
<ToolbarItem>
<Switch
id="rebalancing-switch"
label={t('caches.info.rebalancing-enabled')}
labelOff={t('caches.info.rebalancing-disabled')}
isChecked={cache.rebalancing_enabled}
onChange={() => {
ConsoleServices.caches().rebalancing(cache.name, !cache.rebalancing_enabled)
.then(r => {
addAlert(r);
reload();
})
}}
/>
</ToolbarItem>
);
}

if (cache.rebalancing_enabled) {
return (
<ToolbarItem>
<Label>{t('caches.info.rebalanced')}</Label>
</ToolbarItem>
);
}

return (
<ToolbarItem>
<Label>{t('caches.info.rebalancing-disabled')}</Label>
</ToolbarItem>
);
};

export { RebalancingCache };
8 changes: 6 additions & 2 deletions src/app/assets/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"ignore" : "Hide",
"undo-ignore" : "Show",
"ignored-status" : "Hidden",
"rebalancing-disabled-status" : "Rebalancing off",
"delete" : "Delete",
"clear-all-button" : "Clear all",
"no-caches-status" : "No caches found",
Expand Down Expand Up @@ -104,7 +105,9 @@
"allowed-role" : "Allowed role",
"allowed-role-null" : "-",
"no-tasks-status" : "No tasks yet",
"no-tasks-body" : "Create tasks with the CLI or a remote client."
"no-tasks-body" : "Create tasks with the CLI or a remote client.",
"rebalancing-enabled": "Rebalancing is on",
"rebalancing-disabled": "Rebalancing is off"
},
"caches" : {
"configuration" : {
Expand All @@ -129,7 +132,8 @@
"loading" : "Loading cache {{cacheName}} ...",
"error" : "An error occurred while loading {{cacheName}}",
"rebalanced" : "Rebalanced",
"rebalancing" : "Rebalancing"
"rebalancing-enabled" : "Rebalancing is on",
"rebalancing-disabled" : "Rebalancing is off"
},
"actions" : {
"action-see-less" : "See fewer cache details",
Expand Down