Skip to content

Commit

Permalink
Snapshot Restore, basic restore functionality with basic options. Ini…
Browse files Browse the repository at this point in the history
…tial PR (opensearch-project#276)

* Change alignment of Snapshot Management panels in pages/Main/Main.tsx

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Unify vertical button alignment across panels, ContentPanel.tsx

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Update jest snapshots, add ROUTE_STYLE variable

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add placeholder restore button to Snapshots panel

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Comment out line 20 rollups_spec.js in cypress/integration/

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove unused code and comment cypress/integration/rollups_spec.js

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Starting adaptation/use of existing code for Restore functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Adapt Snapshots.tsx to include RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add restoreSnapshot method to SMservice,RestoreSnapshotResponse int

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement RestoreSnapshotFlyout open/close

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Make Snapshot name appear on RestoreSnapshotFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add/adapt restoreSnapshot to server/SnapshotManagementService

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add route for restoreSnapshot in server/routes.ts

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Rudimentary restore from snapshot functionality reached, buggy

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix index list-snapshot restore, restrict restore to single selection

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove console.logs, commented out code

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Create Advanced options accordion for Snapshot restore.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Currently only visually functional. TODO - make it apply the options

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add initial restore/rename options to ui. Only visual functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Resolve radio button events not firing

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Split radio buttons into SnapshotRestoreOption and SnapshotRenameOptions

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Move 'restore' button between 'delete' and 'take snapshot'

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Set default rename option to 'add prefix'

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add AddPrefixInput, remove unused component RestoreSnapshotInitialOptions

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix issues with restore specific indices

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Implement first 4 Advanced restore options functionality

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Begin cypress testing for snapshots

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Passing tests for create repo and create snapshot

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Begin cypress testing Snapshots. Create repo and Create snapshot done

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement add_prefix functionality for snapshot restore

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Implement rename indices option for restore snapshot

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove console.logs, unusted variables in SnapshotFlyout, SMservice

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add full stop to help text/errors, add RESTORE_OPTIONS enum

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add back line 20 in rollups_spec, required by changes in 2.3 release.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Remove unused getRepos func, add repo prop, trim state in RestoreFlyout

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add increment to 2.3.0

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Change 2.3 to 2.3.0, cypress-workflow.yml

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Comment out line 20 rollups_spec.js causing error in PR E2E

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Change 2.2 to 2.3 unit-tests-workflow.yml

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Uncomment line 19, rollups_spec.js to attempt E2E success on github

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Fix url, change "Sample" to "sample" rollups_spec lines 17, 21

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Change "sample data" to "Add data" rollops_spec.js

Signed-off-by: Chris Hesterman <phestech@amazon.com>

All of these variations pass seamlessly when run locally.

Signed-off-by: Chris Hesterman <phestech@amazon.com>

* Add 10s wait line19, rollups_spec to help find button next step

Signed-off-by: Chris Hesterman <phestech@amazon.com>

Signed-off-by: Chris Hesterman <phestech@amazon.com>
  • Loading branch information
phestecAMZN committed Oct 6, 2022
1 parent 7f9c2c5 commit f7db4af
Show file tree
Hide file tree
Showing 28 changed files with 1,019 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches:
- "*"
env:
OPENSEARCH_DASHBOARDS_VERSION: '2.2'
OPENSEARCH_DASHBOARDS_VERSION: '2.3'
jobs:
tests:
name: Run unit tests
Expand Down
8 changes: 5 additions & 3 deletions cypress/integration/rollups_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ describe("Rollups", () => {
localStorage.setItem("home:welcome:show", "true");

// Go to sample data page
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/home#/tutorial_directory/sampleData`);
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/home#/tutorial_directory`);

// Click on "Sample data" tab
cy.contains("Sample data").click({ force: true });
cy.wait(10000)

// // Click on "Sample data" tab
// cy.contains("Add data").click({ force: true });

// Load sample eCommerce data
cy.get(`button[data-test-subj="addSampleDataSetecommerce"]`).click({ force: true });
Expand Down
102 changes: 102 additions & 0 deletions cypress/integration/snapshots_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { PLUGIN_NAME } from "../support/constants";

describe("Snapshots", () => {
before(() => {
// Delete any existing indices
cy.deleteAllIndices();

// Load ecommerce data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/ecommerce`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});

// Load flight data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/flights`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});

// Load web log data
cy.request({
method: "POST",
url: `${Cypress.env("opensearch_dashboards")}/api/sample_data/logs`,
headers: {
"osd-xsrf": true,
},
}).then((response) => {
expect(response.status).equal(200);
});
});

beforeEach(() => {
// Set welcome screen tracking to false
localStorage.setItem("home:welcome:show", "false");

// Visit ISM Snapshots Dashboard
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/snapshots`);

// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains("Restore", { timeout: 60000 });
});

describe("Repository can be created", () => {
it("successfully creates a new repository", () => {
// Create repository to store snapshots
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/repositories`);

// Route to create repository page
cy.contains("Create repository").click({ force: true });

// Type in repository name
cy.get(`input[data-test-subj="repoNameInput"]`).focus().type("test_repo");

// Type in repository location
cy.get(`input[placeholder="e.g., /mnt/snapshots"]`).focus().type("~/Desktop");

// Click Add button
cy.get("button").contains("Add").click({ force: true });

// Confirm repository created
cy.contains("test_repo");
});
});

describe("Snapshot can be created", () => {
it("successfully creates a new snapshot", () => {
// Click Take snapshot button
cy.get("button").contains("Take snapshot").click({ force: true });

// Type in Snapshot name
cy.get(`input[data-test-subj="snapshotNameInput"]`).type("test_snapshot{enter}");

// Select indexes to be included
cy.get(`[data-test-subj="indicesComboBoxInput"]`).type("open*{enter}");

// Confirm test_repo exists
cy.contains("test_repo");

// Click 'Add' button to create snapshot
cy.get("button").contains("Add").click({ force: true });

// check for success status and snapshot name
cy.contains("In_progress");
cy.contains("test_snapshot");
});
});
});
14 changes: 14 additions & 0 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ export interface LatestActivities {
cause?: string;
};
}

export enum RESTORE_OPTIONS {
restore_specific_indices = "restore_specific_indices",
restore_all_indices = "restore_all_indices",
do_not_rename = "do_not_rename",
add_prefix = "add_prefix",
rename_indices = "rename_indices",
restore_aliases = "restore_aliases",
include_global_state = "include_global_state",
ignore_unavailable = "ignore_unavailable",
partial = "partial",
customize_index_settings = "customize_index_settings",
ignore_index_settings = "ignore_index_settings",
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const SnapshotIndicesRepoInput = ({
onSearchChange={getIndexOptions}
onCreateOption={onCreateOption}
isClearable={true}
data-test-subj="indicesComboBoxInput"
/>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ export default class CreateRepositoryFlyout extends Component<CreateRepositoryPr
<EuiFlyoutBody>
<CustomLabel title="Repository name" />
<EuiFormRow isInvalid={!!repoNameError} error={repoNameError}>
<EuiFieldText disabled={!!editRepo} value={repoName} onChange={(e) => this.setState({ repoName: e.target.value })} />
<EuiFieldText
disabled={!!editRepo}
value={repoName}
data-test-subj="repoNameInput"
onChange={(e) => this.setState({ repoName: e.target.value })}
/>
</EuiFormRow>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiFormRow, EuiFieldText, EuiSpacer } from "@elastic/eui";
import React, { useState, ChangeEvent } from "react";
import CustomLabel from "../../../../components/CustomLabel";

interface AddPrefixesInputProps {
getPrefix: (prefix: string) => void;
}

const AddPrefixesInput = ({ getPrefix }: AddPrefixesInputProps) => {
const [prefix, setPrefix] = useState("");

const onPrefixChange = (e: ChangeEvent<HTMLInputElement>) => {
setPrefix(e.target.value);
getPrefix(e.target.value);
};

return (
<>
<EuiSpacer size="l" />

<CustomLabel title="Specify prefix for restored index names" helpText="A prefix will be added to any restored index names." />
<EuiFormRow>
<EuiFieldText value={prefix} onChange={onPrefixChange} />
</EuiFormRow>

<EuiSpacer size="m" />
</>
);
};

export default AddPrefixesInput;
8 changes: 8 additions & 0 deletions public/pages/Snapshots/components/AddPrefixInput/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import AddPrefixInput from "./AddPrefixInput";

export default AddPrefixInput;
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export default class CreateSnapshotFlyout extends Component<CreateSnapshotProps,
onChange={(e) => {
this.setState({ snapshotId: e.target.value });
}}
data-test-subj="snapshotNameInput"
/>
</EuiFormRow>

Expand Down
53 changes: 53 additions & 0 deletions public/pages/Snapshots/components/RenameInput/RenameInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiFormRow, EuiFieldText, EuiSpacer } from "@elastic/eui";
import React, { useState, ChangeEvent } from "react";
import CustomLabel from "../../../../components/CustomLabel";

interface RenameInputProps {
getRenamePattern: (prefix: string) => void;
getRenameReplacement: (prefix: string) => void;
}

const RenameInput = ({ getRenamePattern, getRenameReplacement }: RenameInputProps) => {
const [renamePattern, setRenamePattern] = useState("");
const [renameReplacement, setRenameReplacement] = useState("");

const onPatternChange = (e: ChangeEvent<HTMLInputElement>) => {
setRenamePattern(e.target.value);
getRenamePattern(e.target.value);
};

const onReplacementChange = (e: ChangeEvent<HTMLInputElement>) => {
setRenameReplacement(e.target.value);
getRenameReplacement(e.target.value);
};

const patternHelpText =
"Use regular expressiojn to define how index names will be renamed. By default, input (.+) to reuse the entire index name. [Learn more]";
const replacementHelpText =
"Define the format of renamed indices. Use $0 to include the entire matching index name, $1 to include the content of the first capture group, etc. [Learn more]";

return (
<>
<EuiSpacer size="l" />

<CustomLabel title="Rename Pattern" helpText={patternHelpText} />
<EuiFormRow>
<EuiFieldText value={renamePattern} onChange={onPatternChange} />
</EuiFormRow>

<EuiSpacer size="m" />

<CustomLabel title="Rename Replacement" helpText={replacementHelpText} />
<EuiFormRow>
<EuiFieldText value={renameReplacement} onChange={onReplacementChange} />
</EuiFormRow>
</>
);
};

export default RenameInput;
8 changes: 8 additions & 0 deletions public/pages/Snapshots/components/RenameInput/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import RenameInput from "./RenameInput";

export default RenameInput;
Loading

0 comments on commit f7db4af

Please sign in to comment.