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