Skip to content

Add support for Convert Index to Remote action #1319

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ export interface SnapshotAction extends Action {
};
}

export interface ConvertIndexToRemoteAction extends Action {
convert_index_to_remote: {
repository: string;
snapshot: string;
};
}

export interface IndexPriorityAction extends Action {
index_priority: {
priority?: number;
Expand Down
2 changes: 1 addition & 1 deletion public/pages/Aliases/containers/Aliases/Aliases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("<Aliases /> spec", () => {
userEvent.type(getByPlaceholderText("Specify alias name"), testAliasId);
userEvent.click(getByTestId("createAliasButton"));
await waitFor(() => {
expect(browserServicesMock.commonService.apiCaller).toBeCalledTimes(17);
expect(browserServicesMock.commonService.apiCaller).toBeCalledTimes(15);
expect(browserServicesMock.commonService.apiCaller).toBeCalledWith({
data: {
index: ["1"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { ChangeEvent } from "react";
import { EuiCompressedFormRow, EuiCompressedFieldText, EuiSpacer } from "@elastic/eui";
import { ConvertIndexToRemoteAction, UIAction } from "../../../../../models/interfaces";
import { makeId } from "../../../../utils/helpers";
import { ActionType } from "../../utils/constants";
import EuiFormCustomLabel from "../EuiFormCustomLabel";

export default class ConvertIndexToRemoteUIAction implements UIAction<ConvertIndexToRemoteAction> {
id: string;
action: ConvertIndexToRemoteAction;
type = ActionType.ConvertIndexToRemote;

constructor(action: ConvertIndexToRemoteAction, id: string = makeId()) {
this.action = action;
this.id = id;
}

content = () => `Convert Index To Remote`;

clone = (action: ConvertIndexToRemoteAction) => new ConvertIndexToRemoteUIAction(action, this.id);

isValid = () => {
return !!this.action.convert_index_to_remote.snapshot && !!this.action.convert_index_to_remote.repository;
};

render = (action: UIAction<ConvertIndexToRemoteAction>, onChangeAction: (action: UIAction<ConvertIndexToRemoteAction>) => void) => {
return (
<>
<EuiFormCustomLabel
title="Repository"
helpText="The repository name that you register through the native snapshot API operations."
isInvalid={!this.isValid()}
/>
<EuiCompressedFormRow fullWidth isInvalid={!this.isValid()} error={null}>
<EuiCompressedFieldText
fullWidth
value={(action.action as ConvertIndexToRemoteAction).convert_index_to_remote.repository}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
const repository = e.target.value;
onChangeAction(
this.clone({
convert_index_to_remote: {
...action.action.convert_index_to_remote,
repository,
},
})
);
}}
data-test-subj="action-render-convert-index-to-remote-repository"
/>
</EuiCompressedFormRow>
<EuiSpacer size="s" />
<EuiFormCustomLabel title="Snapshot" helpText="The name of the snapshot." isInvalid={!this.isValid()} />
<EuiCompressedFormRow fullWidth isInvalid={!this.isValid()} error={null}>
<EuiCompressedFieldText
fullWidth
value={(action.action as ConvertIndexToRemoteAction).convert_index_to_remote.snapshot}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
const snapshot = e.target.value;
onChangeAction(
this.clone({
convert_index_to_remote: {
...action.action.convert_index_to_remote,
snapshot,
},
})
);
}}
data-test-subj="action-render-convert-index-to-remote-snapshot"
/>
</EuiCompressedFormRow>
</>
);
};

toAction = () => this.action;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import AliasUIAction from "./AliasUIAction/AliasUIAction";
import AllocationUIAction from "./AllocationUIAction";
import CloseUIAction from "./CloseUIAction";
import ConvertIndexToRemoteUIAction from "./ConvertIndexToRemoteUIAction";
import DeleteUIAction from "./DeleteUIAction";
import ForceMergeUIAction from "./ForceMergeUIAction";
import IndexPriorityUIAction from "./IndexPriorityUIAction";
Expand All @@ -23,6 +24,7 @@ export {
AliasUIAction,
AllocationUIAction,
CloseUIAction,
ConvertIndexToRemoteUIAction,
DeleteUIAction,
ForceMergeUIAction,
IndexPriorityUIAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ exports[`<CreateAction /> spec renders the component 1`] = `
>
Close
</option>
<option
value="convert_index_to_remote"
>
Convert Index To Remote
</option>
<option
value="delete"
>
Expand Down
8 changes: 8 additions & 0 deletions public/pages/VisualCreatePolicy/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum ActionType {
Alias = "alias",
Allocation = "allocation",
Close = "close",
ConvertIndexToRemote = "convert_index_to_remote",
Delete = "delete",
ForceMerge = "force_merge",
IndexPriority = "index_priority",
Expand Down Expand Up @@ -82,6 +83,12 @@ export const DEFAULT_ALLOCATION: AllocationAction = {
export const DEFAULT_CLOSE = {
close: {},
};
export const DEFAULT_CONVERT_INDEX_TO_REMOTE = {
convert_index_to_remote: {
repository: "example-repository",
snapshot: "example-snapshot",
},
};
export const DEFAULT_DELETE = {
delete: {},
};
Expand Down Expand Up @@ -199,6 +206,7 @@ export const actions = [
DEFAULT_ALIAS,
DEFAULT_ALLOCATION,
DEFAULT_CLOSE,
DEFAULT_CONVERT_INDEX_TO_REMOTE,
DEFAULT_DELETE,
DEFAULT_FORCE_MERGE,
DEFAULT_INDEX_PRIORITY,
Expand Down
4 changes: 2 additions & 2 deletions public/pages/VisualCreatePolicy/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class DummyUIAction implements UIAction<DummyAction> {
}

test("action repository usage", () => {
expect(actionRepoSingleton.getAllActionTypes().length).toBe(15);
actionRepoSingleton.registerAction("dummy", DummyUIAction, DEFAULT_DUMMY);
expect(actionRepoSingleton.getAllActionTypes().length).toBe(16);
actionRepoSingleton.registerAction("dummy", DummyUIAction, DEFAULT_DUMMY);
expect(actionRepoSingleton.getAllActionTypes().length).toBe(17);
expect(actionRepoSingleton.getUIAction("dummy") instanceof DummyUIAction).toBe(true);
expect(actionRepoSingleton.getUIActionFromData(DEFAULT_DUMMY) instanceof DummyUIAction).toBe(true);
});
Expand Down
5 changes: 5 additions & 0 deletions public/pages/VisualCreatePolicy/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DEFAULT_ALIAS,
DEFAULT_ALLOCATION,
DEFAULT_CLOSE,
DEFAULT_CONVERT_INDEX_TO_REMOTE,
DEFAULT_DELETE,
DEFAULT_FORCE_MERGE,
DEFAULT_INDEX_PRIORITY,
Expand All @@ -26,6 +27,7 @@ import {
AliasUIAction,
AllocationUIAction,
CloseUIAction,
ConvertIndexToRemoteUIAction,
DeleteUIAction,
ForceMergeUIAction,
IndexPriorityUIAction,
Expand Down Expand Up @@ -75,6 +77,8 @@ export const getUIAction = (actionType: string): UIAction<any> => {
return new AllocationUIAction(DEFAULT_ALLOCATION);
case ActionType.Close:
return new CloseUIAction(DEFAULT_CLOSE);
case ActionType.ConvertIndexToRemote:
return new ConvertIndexToRemoteUIAction(DEFAULT_CONVERT_INDEX_TO_REMOTE);
case ActionType.Delete:
return new DeleteUIAction(DEFAULT_DELETE);
case ActionType.ForceMerge:
Expand Down Expand Up @@ -127,6 +131,7 @@ class ActionRepository {
alias: [AliasUIAction, DEFAULT_ALIAS],
allocation: [AllocationUIAction, DEFAULT_ALLOCATION],
close: [CloseUIAction, DEFAULT_CLOSE],
convert_index_to_remote: [ConvertIndexToRemoteUIAction, DEFAULT_CONVERT_INDEX_TO_REMOTE],
delete: [DeleteUIAction, DEFAULT_DELETE],
force_merge: [ForceMergeUIAction, DEFAULT_FORCE_MERGE],
index_priority: [IndexPriorityUIAction, DEFAULT_INDEX_PRIORITY],
Expand Down