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-16482 Adds update schema action #479

Merged
merged 1 commit into from
Sep 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cypress/e2e/2_cache-detail-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ describe('Cache Detail Overview', () => {

cy.get('[data-cy=detailCacheActions]').click();
cy.get("[data-cy=manageIndexesLink]").click();

cy.get("[data-cy=updateSchemaIndexButton]").click();
cy.contains("Update schema?");
cy.get("[data-cy=cancelButton]").click();
cy.get("[data-cy=updateSchemaIndexButton]").click();
cy.contains("Update schema?");
cy.get("[data-cy=updateCacheSchema]").click();
cy.contains("Schema of cache indexed-cache updated.").click();

cy.get("[data-cy=clearIndexButton]").click();
cy.contains("Permanently clear index?");
cy.get("[data-cy=cancelButton]").click();
Expand Down
36 changes: 35 additions & 1 deletion src/app/IndexManagement/IndexManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ConsoleACL } from '@services/securityService';
import { useConnectedUser } from '@app/services/userManagementHook';
import { useSearchStats } from '@app/services/statsHook';
import { DatabaseIcon } from '@patternfly/react-icons';
import { UpdateSchema } from '@app/IndexManagement/UpdateSchema';

const IndexManagement = () => {
const { t } = useTranslation();
Expand All @@ -47,6 +48,7 @@ const IndexManagement = () => {
const { stats, loading, error, setLoading } = useSearchStats(cacheName);
const [purgeModalOpen, setPurgeModalOpen] = useState<boolean>(false);
const [reindexModalOpen, setReindexModalOpen] = useState<boolean>(false);
const [updateSchemaModalOpen, setUpdateSchemaModalOpen] = useState<boolean>(false);

const closePurgeModal = () => {
setPurgeModalOpen(false);
Expand All @@ -58,6 +60,32 @@ const IndexManagement = () => {
setLoading(true);
};

const closeUpdateSchemaModal = () => {
setUpdateSchemaModalOpen(false);
setLoading(true);
};

const buildUpdateSchemaAction = () => {
if (!ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser)) {
return;
}

if (stats?.reindexing) {
return <Spinner size={'md'} />;
}
return (
<ToolbarItem>
<Button
data-cy="updateSchemaIndexButton"
variant={ButtonVariant.primary}
onClick={() => setUpdateSchemaModalOpen(true)}
>
{t('caches.index.button-update-schema')}
</Button>
</ToolbarItem>
);
};

const buildReindexAction = () => {
if (!ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser)) {
return;
Expand All @@ -68,7 +96,11 @@ const IndexManagement = () => {
}
return (
<ToolbarItem>
<Button data-cy="rebuildIndexButton" variant={ButtonVariant.primary} onClick={() => setReindexModalOpen(true)}>
<Button
data-cy="rebuildIndexButton"
variant={ButtonVariant.secondary}
onClick={() => setReindexModalOpen(true)}
>
{t('caches.index.button-rebuild')}
</Button>
</ToolbarItem>
Expand Down Expand Up @@ -165,6 +197,7 @@ const IndexManagement = () => {
{buildIndexPageContent()}
<Toolbar id="indexing-page-toolbar">
<ToolbarContent style={{ paddingLeft: 0, paddingTop: global_spacer_md.value }}>
{buildUpdateSchemaAction()}
{buildReindexAction()}
{buildPurgeIndexButton()}
<ToolbarItem>
Expand All @@ -186,6 +219,7 @@ const IndexManagement = () => {
</PageSection>
<PurgeIndex cacheName={cacheName} isModalOpen={purgeModalOpen} closeModal={closePurgeModal} />
<Reindex cacheName={cacheName} isModalOpen={reindexModalOpen} closeModal={closeReindexModal} />
<UpdateSchema cacheName={cacheName} isModalOpen={updateSchemaModalOpen} closeModal={closeUpdateSchemaModal} />
</React.Fragment>
);
};
Expand Down
11 changes: 5 additions & 6 deletions src/app/IndexManagement/PurgeIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ConsoleServices } from '@services/ConsoleServices';
*/
const PurgeIndex = (props: { cacheName: string; isModalOpen: boolean; closeModal: () => void }) => {
const { t } = useTranslation();
const brandname = t('brandname.brandname');
const { addAlert } = useApiAlert();

const onClickPurgeButton = () => {
Expand All @@ -24,24 +23,24 @@ const PurgeIndex = (props: { cacheName: string; isModalOpen: boolean; closeModal
return (
<Modal
titleIconVariant={'warning'}
className="pf-m-redhat-font"
width={'50%'}
isOpen={props.isModalOpen}
title={'Permanently clear index?'}
title={t('caches.index.purge.title')}
onClose={props.closeModal}
aria-label="Clear index modal"
actions={[
<Button data-cy="clearIndex" key="purge" variant={ButtonVariant.danger} onClick={onClickPurgeButton}>
Clear
{t('common.actions.clear')}
</Button>,
<Button data-cy="cancelButton" key="cancel" variant="link" onClick={props.closeModal}>
Cancel
{t('common.actions.cancel')}
</Button>
]}
>
<TextContent>
<Text>
All indexes in <strong>{props.cacheName}</strong> will be deleted.
{t('caches.index.purge.description1')} <strong>{props.cacheName}</strong>{' '}
{t('caches.index.purge.description2')}
</Text>
</TextContent>
</Modal>
Expand Down
16 changes: 5 additions & 11 deletions src/app/IndexManagement/Reindex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { ConsoleServices } from '@services/ConsoleServices';
const Reindex = (props: { cacheName: string; isModalOpen: boolean; closeModal: () => void }) => {
const { addAlert } = useApiAlert();
const { t } = useTranslation();
const brandname = t('brandname.brandname');

const onClickReindex = () => {
ConsoleServices.search()
.reindex(props.cacheName)
Expand All @@ -24,27 +22,23 @@ const Reindex = (props: { cacheName: string; isModalOpen: boolean; closeModal: (
return (
<Modal
titleIconVariant={'info'}
className="pf-m-redhat-font"
width={'50%'}
isOpen={props.isModalOpen}
title={'Rebuild index?'}
title={t('caches.index.reindex.title')}
onClose={props.closeModal}
aria-label="Reindex modal"
actions={[
<Button key="reindex" onClick={onClickReindex} data-cy="reindexButton">
Rebuild index
{t('caches.index.reindex.button-rebuild-index')}
</Button>,
<Button key="cancel" variant="link" onClick={props.closeModal} data-cy="cancelReindexButton">
Cancel
{t('common.actions.cancel')}
</Button>
]}
>
<TextContent>
<Text>
All indexes will be rebuilt. To ensure accurate results, do not query caches until rebuilding is complete.
<br />
This process may take a few minutes.
</Text>
<Text>{t('caches.index.reindex.description1')}</Text>
<Text>{t('caches.index.reindex.description2')}</Text>
</TextContent>
</Modal>
);
Expand Down
48 changes: 48 additions & 0 deletions src/app/IndexManagement/UpdateSchema.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { Button, ButtonVariant, Modal, Text, TextContent } from '@patternfly/react-core';
import { useApiAlert } from '@app/utils/useApiAlert';
import { useTranslation } from 'react-i18next';
import { ConsoleServices } from '@services/ConsoleServices';

/**
* Update schema modal
*/
const UpdateSchema = (props: { cacheName: string; isModalOpen: boolean; closeModal: () => void }) => {
const { t } = useTranslation();
const { addAlert } = useApiAlert();

const onClickPurgeButton = () => {
ConsoleServices.search()
.updateSchema(props.cacheName)
.then((actionResponse) => {
props.closeModal();
addAlert(actionResponse);
});
};

return (
<Modal
titleIconVariant={'info'}
width={'50%'}
isOpen={props.isModalOpen}
title={t('caches.index.update-schema.title')}
onClose={props.closeModal}
aria-label="update schema modal"
actions={[
<Button data-cy="updateCacheSchema" key="purge" variant={ButtonVariant.primary} onClick={onClickPurgeButton}>
{t('common.actions.update')}
</Button>,
<Button data-cy="cancelButton" key="cancel" variant="link" onClick={props.closeModal}>
{t('common.actions.cancel')}
</Button>
]}
>
<TextContent>
<Text>{t('caches.index.update-schema.description1')}</Text>
<Text>{t('caches.index.update-schema.description2')}</Text>
</TextContent>
</Modal>
);
};

export { UpdateSchema };
23 changes: 21 additions & 2 deletions src/app/assets/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"cancel": "Cancel",
"save": "Save",
"delete": "Delete",
"remove": "Remove"
"remove": "Remove",
"clear": "Clear",
"update": "Update"
},
"loading-error-message": "There was an error retrieving data. Check your connection and try again.",
"tracing": {
Expand Down Expand Up @@ -677,7 +679,24 @@
"size": "Index size in bytes",
"indexing-status": "Indexing",
"button-clear": "Clear index",
"button-rebuild": "Rebuild index"
"button-rebuild": "Rebuild index",
"button-update-schema": "Update schema",
"reindex": {
"title": "Rebuild index?",
"button-rebuild-index": "Rebuild index",
"description1": "All indexes will be rebuilt. To ensure accurate results, do not query caches until rebuilding is complete.",
"description2": "This process may take a few minutes."
},
"purge": {
"title": "Permanently clear index?",
"description1": "All indexes in",
"description2": "will be deleted."
},
"update-schema": {
"title": "Update schema?",
"description1": "Add new fields to the existing schema without having to rebuild the entire index.",
"description2": "This process may take a few minutes."
}
},
"tracing": {
"title": "Tracing management",
Expand Down
13 changes: 13 additions & 0 deletions src/services/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ export class SearchService {
});
}

/**
* Update schema for the cache name
*
* @param cacheName
*/
public async updateSchema(cacheName: string): Promise<ActionResponse> {
return this.utils.post({
url: this.endpoint + encodeURIComponent(cacheName) + '/search/indexes?action=updateSchema',
successMessage: `Schema of cache ${cacheName} updated.`,
errorMessage: `An error occurred when updating the schema for cache ${cacheName}.`
});
}

/**
* Reindex cache
*
Expand Down
Loading