Search in sources :

Example 1 with RestoreSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest in project elasticsearch by elastic.

the class SnapshotRequestsTests method testRestoreSnapshotRequestParsing.

public void testRestoreSnapshotRequestParsing() throws IOException {
    RestoreSnapshotRequest request = new RestoreSnapshotRequest("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());
    builder.field("rename_pattern", "rename-from");
    builder.field("rename_replacement", "rename-to");
    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("rename-from", request.renamePattern());
    assertEquals("rename-to", request.renameReplacement());
    assertEquals(partial, request.partial());
    assertEquals("val1", request.settings().get("set1"));
    assertArrayEquals(request.ignoreIndexSettings(), new String[] { "set2", "set3" });
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with RestoreSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest in project elasticsearch by elastic.

the class RestRestoreSnapshotAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RestoreSnapshotRequest restoreSnapshotRequest = restoreSnapshotRequest(request.param("repository"), request.param("snapshot"));
    restoreSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", restoreSnapshotRequest.masterNodeTimeout()));
    restoreSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
    request.applyContentParser(p -> restoreSnapshotRequest.source(p.mapOrdered()));
    return channel -> client.admin().cluster().restoreSnapshot(restoreSnapshotRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Requests.restoreSnapshotRequest(org.elasticsearch.client.Requests.restoreSnapshotRequest) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)

Example 3 with RestoreSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest in project crate by crate.

the class SnapshotRestoreDDLDispatcher method dispatch.

public CompletableFuture<Long> dispatch(final RestoreSnapshotAnalyzedStatement analysis) {
    boolean waitForCompletion = analysis.settings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
    boolean ignoreUnavailable = analysis.settings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
    // ignore_unavailable as set by statement
    IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
    FutureActionListener<RestoreSnapshotResponse, Long> listener = new FutureActionListener<>(Functions.constant(1L));
    resolveIndexNames(analysis.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction(), analysis.repositoryName()).whenComplete((List<String> indexNames, Throwable t) -> {
        if (t == null) {
            RestoreSnapshotRequest request = new RestoreSnapshotRequest(analysis.repositoryName(), analysis.snapshotName()).indices(indexNames).indicesOptions(indicesOptions).settings(analysis.settings()).waitForCompletion(waitForCompletion).includeGlobalState(false).includeAliases(true);
            transportActionProvider.transportRestoreSnapshotAction().execute(request, listener);
        } else {
            listener.onFailure(t);
        }
    });
    return listener;
}
Also used : RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) FutureActionListener(io.crate.action.FutureActionListener) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 4 with RestoreSnapshotRequest

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest in project elasticsearch by elastic.

the class SnapshotTests method testRestoreSnapshotRequestDescrptions.

public void testRestoreSnapshotRequestDescrptions() {
    RestoreSnapshotRequest restoreSnapshotRequest = new RestoreSnapshotRequest();
    restoreSnapshotRequest.snapshot("snapshot_name");
    restoreSnapshotRequest.repository("repo_name");
    assertEquals("snapshot [repo_name:snapshot_name]", restoreSnapshotRequest.getDescription());
}
Also used : RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)

Aggregations

RestoreSnapshotRequest (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)4 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)2 ImmutableList (com.google.common.collect.ImmutableList)1 FutureActionListener (io.crate.action.FutureActionListener)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)1 Requests.restoreSnapshotRequest (org.elasticsearch.client.Requests.restoreSnapshotRequest)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 POST (org.elasticsearch.rest.RestRequest.Method.POST)1 RestToXContentListener (org.elasticsearch.rest.action.RestToXContentListener)1