|
@@ -1,133 +0,0 @@
|
|
|
-/*
|
|
|
- * Licensed to Elasticsearch under one or more contributor
|
|
|
- * license agreements. See the NOTICE file distributed with
|
|
|
- * this work for additional information regarding copyright
|
|
|
- * ownership. Elasticsearch licenses this file to you under
|
|
|
- * the Apache License, Version 2.0 (the "License"); you may
|
|
|
- * not use this file except in compliance with the License.
|
|
|
- * You may obtain a copy of the License at
|
|
|
- *
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
- *
|
|
|
- * Unless required by applicable law or agreed to in writing,
|
|
|
- * software distributed under the License is distributed on an
|
|
|
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
- * KIND, either express or implied. See the License for the
|
|
|
- * specific language governing permissions and limitations
|
|
|
- * under the License.
|
|
|
- */
|
|
|
-
|
|
|
-package org.elasticsearch.repositories.azure;
|
|
|
-
|
|
|
-
|
|
|
-import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
|
|
|
-import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
|
|
-import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
|
|
-import org.elasticsearch.client.Client;
|
|
|
-import org.elasticsearch.cloud.azure.AbstractAzureRepositoryServiceIntegTestCase;
|
|
|
-import org.elasticsearch.cluster.ClusterState;
|
|
|
-import org.elasticsearch.common.settings.Settings;
|
|
|
-import org.elasticsearch.common.unit.ByteSizeUnit;
|
|
|
-import org.elasticsearch.snapshots.SnapshotInfo;
|
|
|
-import org.elasticsearch.snapshots.SnapshotShardFailure;
|
|
|
-import org.elasticsearch.snapshots.SnapshotState;
|
|
|
-import org.elasticsearch.test.ESIntegTestCase;
|
|
|
-
|
|
|
-import static org.hamcrest.Matchers.equalTo;
|
|
|
-import static org.hamcrest.Matchers.greaterThan;
|
|
|
-import static org.hamcrest.Matchers.is;
|
|
|
-
|
|
|
-@ESIntegTestCase.ClusterScope(
|
|
|
- scope = ESIntegTestCase.Scope.SUITE,
|
|
|
- supportsDedicatedMasters = false,
|
|
|
- numDataNodes = 1,
|
|
|
- numClientNodes = 0,
|
|
|
- transportClientRatio = 0.0)
|
|
|
-public class AzureSnapshotRestoreServiceIntegTests extends AbstractAzureRepositoryServiceIntegTestCase {
|
|
|
- public AzureSnapshotRestoreServiceIntegTests() {
|
|
|
- super("/snapshot-test/repo-" + randomInt());
|
|
|
- }
|
|
|
-
|
|
|
- public void testSimpleWorkflow() {
|
|
|
- Client client = client();
|
|
|
- logger.info("--> creating azure repository with path [{}]", basePath);
|
|
|
- PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo")
|
|
|
- .setType("azure").setSettings(Settings.builder()
|
|
|
- .put("base_path", basePath)
|
|
|
- .put("chunk_size", randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)
|
|
|
- ).get();
|
|
|
- assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
|
|
|
-
|
|
|
- createIndex("test-idx-1", "test-idx-2", "test-idx-3");
|
|
|
- ensureGreen();
|
|
|
-
|
|
|
- logger.info("--> indexing some data");
|
|
|
- for (int i = 0; i < 100; i++) {
|
|
|
- index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
|
|
|
- index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i);
|
|
|
- index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
|
|
- }
|
|
|
- refresh();
|
|
|
- assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
|
|
- assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
|
|
- assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
|
|
-
|
|
|
- logger.info("--> snapshot");
|
|
|
- CreateSnapshotResponse createSnapshotResponse = client.admin().cluster()
|
|
|
- .prepareCreateSnapshot("test-repo", "test-snap")
|
|
|
- .setWaitForCompletion(true)
|
|
|
- .setIndices("test-idx-*", "-test-idx-3")
|
|
|
- .get();
|
|
|
-
|
|
|
- final SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
|
|
|
- if (snapshotInfo.shardFailures() != null) {
|
|
|
- for (SnapshotShardFailure shardFailure : snapshotInfo.shardFailures()) {
|
|
|
- logger.warn("shard failure during snapshot: {}", shardFailure::toString);
|
|
|
- }
|
|
|
- }
|
|
|
- assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS));
|
|
|
- assertEquals(snapshotInfo.failedShards(), 0);
|
|
|
-
|
|
|
- logger.info("--> delete some data");
|
|
|
- for (int i = 0; i < 50; i++) {
|
|
|
- client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get();
|
|
|
- }
|
|
|
- for (int i = 50; i < 100; i++) {
|
|
|
- client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get();
|
|
|
- }
|
|
|
- for (int i = 0; i < 100; i += 2) {
|
|
|
- client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
|
|
|
- }
|
|
|
- refresh();
|
|
|
- assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
|
|
- assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
|
|
- assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
|
|
-
|
|
|
- logger.info("--> close indices");
|
|
|
- client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
|
|
|
-
|
|
|
- logger.info("--> restore all indices from the snapshot");
|
|
|
- RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap")
|
|
|
- .setWaitForCompletion(true).get();
|
|
|
- assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
|
|
-
|
|
|
- ensureGreen();
|
|
|
- assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
|
|
- assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
|
|
- assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
|
|
-
|
|
|
- // Test restore after index deletion
|
|
|
- logger.info("--> delete indices");
|
|
|
- cluster().wipeIndices("test-idx-1", "test-idx-2");
|
|
|
- logger.info("--> restore one index after deletion");
|
|
|
- restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true)
|
|
|
- .setIndices("test-idx-*", "-test-idx-2").get();
|
|
|
- assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
|
|
- ensureGreen();
|
|
|
- assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
|
|
- ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
|
|
- assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
|
|
- assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
|
|
|
- }
|
|
|
-
|
|
|
-}
|