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" });
}
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));
}
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;
}
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());
}
Aggregations