Search in sources :

Example 1 with CreateSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest in project elasticsearch by elastic.

the class SnapshotRequestsTests method testCreateSnapshotRequestParsing.

public void testCreateSnapshotRequestParsing() throws IOException {
    CreateSnapshotRequest request = new CreateSnapshotRequest("test-repo", "test-snap");
    XContentBuilder builder = jsonBuilder().startObject();
    if (randomBoolean()) {
        builder.field("indices", "foo,bar,baz");
    } else {
        builder.startArray("indices");
        builder.value("foo");
        builder.value("bar");
        builder.value("baz");
        builder.endArray();
    }
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
    if (indicesOptions.expandWildcardsClosed()) {
        if (indicesOptions.expandWildcardsOpen()) {
            builder.field("expand_wildcards", "all");
        } else {
            builder.field("expand_wildcards", "closed");
        }
    } else {
        if (indicesOptions.expandWildcardsOpen()) {
            builder.field("expand_wildcards", "open");
        } else {
            builder.field("expand_wildcards", "none");
        }
    }
    builder.field("allow_no_indices", indicesOptions.allowNoIndices());
    boolean partial = randomBoolean();
    builder.field("partial", partial);
    builder.startObject("settings").field("set1", "val1").endObject();
    builder.startObject("index_settings").field("set1", "val2").endObject();
    if (randomBoolean()) {
        builder.field("ignore_index_settings", "set2,set3");
    } else {
        builder.startArray("ignore_index_settings");
        builder.value("set2");
        builder.value("set3");
        builder.endArray();
    }
    BytesReference bytes = builder.endObject().bytes();
    request.source(XContentHelper.convertToMap(bytes, true, builder.contentType()).v2());
    assertEquals("test-repo", request.repository());
    assertEquals("test-snap", request.snapshot());
    assertArrayEquals(request.indices(), new String[] { "foo", "bar", "baz" });
    assertEquals(partial, request.partial());
    assertEquals("val1", request.settings().get("set1"));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with CreateSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest in project elasticsearch by elastic.

the class SnapshotTests method testCreateSnapshotRequestDescrptions.

public void testCreateSnapshotRequestDescrptions() {
    CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest();
    createSnapshotRequest.snapshot("snapshot_name");
    createSnapshotRequest.repository("repo_name");
    assertEquals("snapshot [repo_name:snapshot_name]", createSnapshotRequest.getDescription());
}
Also used : CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)

Example 3 with CreateSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest in project crate by crate.

the class SnapshotRestoreDDLDispatcher method dispatch.

public CompletableFuture<Long> dispatch(final CreateSnapshotAnalyzedStatement statement) {
    final CompletableFuture<Long> resultFuture = new CompletableFuture<>();
    boolean waitForCompletion = statement.snapshotSettings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
    boolean ignoreUnavailable = statement.snapshotSettings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
    // ignore_unavailable as set by statement
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
    CreateSnapshotRequest request = new CreateSnapshotRequest(statement.snapshotId().getRepository(), statement.snapshotId().getSnapshot()).includeGlobalState(statement.includeMetadata()).waitForCompletion(waitForCompletion).indices(statement.indices()).indicesOptions(indicesOptions).settings(statement.snapshotSettings());
    //noinspection ThrowableResultOfMethodCallIgnored
    assert request.validate() == null : "invalid CREATE SNAPSHOT statement";
    transportActionProvider.transportCreateSnapshotAction().execute(request, new ActionListener<CreateSnapshotResponse>() {

        @Override
        public void onResponse(CreateSnapshotResponse createSnapshotResponse) {
            SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
            if (snapshotInfo == null) {
                // if wait_for_completion is false the snapshotInfo is null
                resultFuture.complete(1L);
            } else if (snapshotInfo.state() == SnapshotState.FAILED) {
                // fail request if snapshot creation failed
                String reason = createSnapshotResponse.getSnapshotInfo().reason().replaceAll("Index", "Table").replaceAll("Indices", "Tables");
                resultFuture.completeExceptionally(new CreateSnapshotException(statement.snapshotId(), reason));
            } else {
                resultFuture.complete(1L);
            }
        }

        @Override
        public void onFailure(Throwable e) {
            resultFuture.completeExceptionally(e);
        }
    });
    return resultFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CreateSnapshotException(io.crate.exceptions.CreateSnapshotException) CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 4 with CreateSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest in project crate by crate.

the class SnapshotRestoreAnalyzerTest method testCreateSnapshotUnknownSchemaIgnore.

@Test
public void testCreateSnapshotUnknownSchemaIgnore() throws Exception {
    CreateSnapshotRequest request = analyze(e, "CREATE SNAPSHOT my_repo.my_snapshot TABLE users, my_schema.t2 WITH (ignore_unavailable=true)");
    assertThat(request.indices(), arrayContaining("users"));
    assertThat(request.indicesOptions().ignoreUnavailable(), is(true));
}
Also used : CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with CreateSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest in project crate by crate.

the class SnapshotRestoreAnalyzerTest method testCreateSnapshotCreateSnapshotTables.

@Test
public void testCreateSnapshotCreateSnapshotTables() throws Exception {
    CreateSnapshotRequest request = analyze(e, "CREATE SNAPSHOT my_repo.my_snapshot TABLE users, locations " + "WITH (wait_for_completion=true)");
    assertThat(request.includeGlobalState(), is(false));
    assertThat(request.indices(), arrayContainingInAnyOrder("users", "locations"));
    assertThat(request.repository(), is("my_repo"));
    assertThat(request.snapshot(), is("my_snapshot"));
    assertThat(request.settings().getAsStructuredMap(), hasEntry("wait_for_completion", "true"));
}
Also used : CreateSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

CreateSnapshotRequest (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)12 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)6 Test (org.junit.Test)6 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)4 CreateSnapshotException (io.crate.exceptions.CreateSnapshotException)3 Settings (org.elasticsearch.common.settings.Settings)3 AnalyzedCreateSnapshot (io.crate.analyze.AnalyzedCreateSnapshot)2 GenericPropertiesConverter (io.crate.analyze.GenericPropertiesConverter)2 PartitionPropertiesAnalyzer.toPartitionName (io.crate.analyze.PartitionPropertiesAnalyzer.toPartitionName)2 SnapshotSettings (io.crate.analyze.SnapshotSettings)2 IGNORE_UNAVAILABLE (io.crate.analyze.SnapshotSettings.IGNORE_UNAVAILABLE)2 WAIT_FOR_COMPLETION (io.crate.analyze.SnapshotSettings.WAIT_FOR_COMPLETION)2 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)2 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)2 Lists2 (io.crate.common.collections.Lists2)2 Row (io.crate.data.Row)2 Row1 (io.crate.data.Row1)2 RowConsumer (io.crate.data.RowConsumer)2 PartitionUnknownException (io.crate.exceptions.PartitionUnknownException)2 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)2