mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Add REST tests for reset index settings and for listing defaults.
This commit is contained in:
parent
651819ca6c
commit
13e5547537
@ -26,6 +26,7 @@ import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.IndexScopeSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
@ -42,9 +43,12 @@ import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestGetSettingsAction extends BaseRestHandler {
|
||||
|
||||
private final IndexScopeSettings indexScopeSettings;
|
||||
|
||||
@Inject
|
||||
public RestGetSettingsAction(Settings settings, RestController controller, Client client) {
|
||||
public RestGetSettingsAction(Settings settings, RestController controller, Client client, IndexScopeSettings indexScopeSettings) {
|
||||
super(settings, controller, client);
|
||||
this.indexScopeSettings = indexScopeSettings;
|
||||
controller.registerHandler(GET, "/{index}/_settings/{name}", this);
|
||||
controller.registerHandler(GET, "/_settings/{name}", this);
|
||||
controller.registerHandler(GET, "/{index}/_setting/{name}", this);
|
||||
@ -53,6 +57,7 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");
|
||||
final boolean renderDefaults = request.paramAsBoolean("defaults", false);
|
||||
GetSettingsRequest getSettingsRequest = new GetSettingsRequest()
|
||||
.indices(Strings.splitStringByCommaToArray(request.param("index")))
|
||||
.indicesOptions(IndicesOptions.fromRequest(request, IndicesOptions.strictExpandOpen()))
|
||||
@ -71,9 +76,14 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
||||
continue;
|
||||
}
|
||||
builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE);
|
||||
builder.startObject(Fields.SETTINGS);
|
||||
builder.startObject("settings");
|
||||
cursor.value.toXContent(builder, request);
|
||||
builder.endObject();
|
||||
if (renderDefaults) {
|
||||
builder.startObject("defaults");
|
||||
indexScopeSettings.diff(cursor.value, settings).toXContent(builder, request);
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
@ -81,8 +91,4 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static class Fields {
|
||||
static final XContentBuilderString SETTINGS = new XContentBuilderString("settings");
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,11 @@
|
||||
"timeout": {
|
||||
"type" : "time",
|
||||
"description" : "Explicit operation timeout"
|
||||
},
|
||||
"defaults": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to return all default clusters setting.",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -42,6 +42,11 @@
|
||||
"type": "boolean",
|
||||
"description": "Whether to return version and creation date values in human-readable format.",
|
||||
"default": false
|
||||
},
|
||||
"defaults": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to return all default setting for each of the indices.",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -0,0 +1,39 @@
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: test-index
|
||||
body:
|
||||
settings:
|
||||
index:
|
||||
refresh_interval: "10s"
|
||||
|
||||
---
|
||||
"Test reset index settings":
|
||||
- do:
|
||||
indices.get_settings:
|
||||
index: test-index
|
||||
flat_settings: true
|
||||
|
||||
- match:
|
||||
test-index.settings.index.refresh_interval: "10s"
|
||||
|
||||
- do:
|
||||
indices.put_settings:
|
||||
body:
|
||||
refresh_interval: null
|
||||
|
||||
- do:
|
||||
indices.get_settings:
|
||||
flat_settings: false
|
||||
|
||||
- match:
|
||||
- match: {index.settings: {}}
|
||||
|
||||
- do:
|
||||
indices.get_settings:
|
||||
flat_settings: true
|
||||
defaults: true
|
||||
|
||||
- match:
|
||||
test-index.settings.index.refresh_interval: "1s"
|
||||
|
Loading…
x
Reference in New Issue
Block a user