Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ public boolean includeGlobalState() {
* @param source snapshot definition
* @return this request
*/
@SuppressWarnings("unchecked")
public CreateSnapshotRequest source(Map<String, Object> source) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) source).entrySet()) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
String name = entry.getKey();
if (name.equals("indices")) {
if (entry.getValue() instanceof String) {
Expand All @@ -402,7 +403,7 @@ public CreateSnapshotRequest source(Map<String, Object> source) {
includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
}
}
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ public Settings indexSettings() {
* @param source restore definition
* @return this request
*/
@SuppressWarnings("unchecked")
public RestoreSnapshotRequest source(Map<String, Object> source) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
String name = entry.getKey();
Expand Down Expand Up @@ -558,7 +559,7 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
}
}
}
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testRestoreSnapshotRequestParsing() throws IOException {

XContentBuilder builder = jsonBuilder().startObject();

if(randomBoolean()) {
if (randomBoolean()) {
builder.field("indices", "foo,bar,baz");
} else {
builder.startArray("indices");
Expand Down Expand Up @@ -76,6 +76,10 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
builder.value("set3");
builder.endArray();
}
boolean includeIgnoreUnavailable = randomBoolean();
if (includeIgnoreUnavailable) {
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
}

BytesReference bytes = builder.endObject().bytes();

Expand All @@ -89,15 +93,18 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
assertEquals(partial, request.partial());
assertEquals("val1", request.settings().get("set1"));
assertArrayEquals(request.ignoreIndexSettings(), new String[]{"set2", "set3"});

boolean expectedIgnoreAvailable = includeIgnoreUnavailable
? indicesOptions.ignoreUnavailable()
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
}

public void testCreateSnapshotRequestParsing() throws IOException {
CreateSnapshotRequest request = new CreateSnapshotRequest("test-repo", "test-snap");

XContentBuilder builder = jsonBuilder().startObject();

if(randomBoolean()) {
if (randomBoolean()) {
builder.field("indices", "foo,bar,baz");
} else {
builder.startArray("indices");
Expand Down Expand Up @@ -134,6 +141,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
builder.value("set3");
builder.endArray();
}
boolean includeIgnoreUnavailable = randomBoolean();
if (includeIgnoreUnavailable) {
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
}

BytesReference bytes = builder.endObject().bytes();

Expand All @@ -144,6 +155,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
assertArrayEquals(request.indices(), new String[]{"foo", "bar", "baz"});
assertEquals(partial, request.partial());
assertEquals("val1", request.settings().get("set1"));
boolean expectedIgnoreAvailable = includeIgnoreUnavailable
? indicesOptions.ignoreUnavailable()
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,38 @@ setup:
snapshot: test_snapshot

- match: { acknowledged: true }

---
"Create a snapshot for missing index":
- skip:
version: " - 6.99.99"
reason: ignore_unavailable default is false in 7.0.0

- do:
catch: missing
snapshot.create:
repository: test_repo_create_1
snapshot: test_snapshot_1
wait_for_completion: true
body: |
{ "indices": "missing_1" }

- do:
snapshot.create:
repository: test_repo_create_1
snapshot: test_snapshot_2
wait_for_completion: true
body: |
{ "indices": "missing_2", "ignore_unavailable": true }

- match: { snapshot.snapshot: test_snapshot_2 }
- match: { snapshot.state : SUCCESS }
- match: { snapshot.shards.successful: 0 }
- match: { snapshot.shards.failed : 0 }

- do:
snapshot.delete:
repository: test_repo_create_1
snapshot: test_snapshot_2

- match: { acknowledged: true }