use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestGetSettingsAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");
final boolean renderDefaults = request.paramAsBoolean("include_defaults", false);
// This is required so the "flat_settings" parameter counts as consumed
request.paramAsBoolean("flat_settings", false);
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(Strings.splitStringByCommaToArray(request.param("index"))).indicesOptions(IndicesOptions.fromRequest(request, IndicesOptions.strictExpandOpen())).humanReadable(request.hasParam("human")).includeDefaults(renderDefaults).names(names);
getSettingsRequest.local(request.paramAsBoolean("local", getSettingsRequest.local()));
getSettingsRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", getSettingsRequest.masterNodeTimeout()));
parseDeprecatedMasterTimeoutParameter(getSettingsRequest, request, deprecationLogger, getName());
return channel -> client.admin().indices().getSettings(getSettingsRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestIndexDeleteAliasesAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
indicesAliasesRequest.addAliasAction(AliasActions.remove().indices(indices).aliases(aliases));
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", indicesAliasesRequest.masterNodeTimeout()));
parseDeprecatedMasterTimeoutParameter(indicesAliasesRequest, request, deprecationLogger, getName());
return channel -> client.admin().indices().aliases(indicesAliasesRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestIndicesSegmentsAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(Strings.splitStringByCommaToArray(request.param("index")));
indicesSegmentsRequest.verbose(request.paramAsBoolean("verbose", false));
indicesSegmentsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesSegmentsRequest.indicesOptions()));
return channel -> client.admin().indices().segments(indicesSegmentsRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestIndicesShardStoresAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesShardStoresRequest indicesShardStoresRequest = new IndicesShardStoresRequest(Strings.splitStringByCommaToArray(request.param("index")));
if (request.hasParam("status")) {
indicesShardStoresRequest.shardStatuses(Strings.splitStringByCommaToArray(request.param("status")));
}
indicesShardStoresRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesShardStoresRequest.indicesOptions()));
return channel -> client.admin().indices().shardStores(indicesShardStoresRequest, new RestBuilderListener<IndicesShardStoresResponse>(channel) {
@Override
public RestResponse buildResponse(IndicesShardStoresResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
}
use of org.opensearch.client.node.NodeClient in project OpenSearch by opensearch-project.
the class RestIndicesStatsAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.timeout(request.param("timeout"));
boolean forbidClosedIndices = request.paramAsBoolean("forbid_closed_indices", true);
IndicesOptions defaultIndicesOption = forbidClosedIndices ? indicesStatsRequest.indicesOptions() : IndicesOptions.strictExpandOpen();
assert indicesStatsRequest.indicesOptions() == IndicesOptions.strictExpandOpenAndForbidClosed() : "IndicesStats default indices " + "options changed";
indicesStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, defaultIndicesOption));
indicesStatsRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
Set<String> metrics = Strings.tokenizeByCommaToSet(request.param("metric", "_all"));
// short cut, if no metrics have been specified in URI
if (metrics.size() == 1 && metrics.contains("_all")) {
indicesStatsRequest.all();
} else if (metrics.contains("_all")) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "request [%s] contains _all and individual metrics [%s]", request.path(), request.param("metric")));
} else {
indicesStatsRequest.clear();
// use a sorted set so the unrecognized parameters appear in a reliable sorted order
final Set<String> invalidMetrics = new TreeSet<>();
for (final String metric : metrics) {
final Consumer<IndicesStatsRequest> consumer = METRICS.get(metric);
if (consumer != null) {
consumer.accept(indicesStatsRequest);
} else {
invalidMetrics.add(metric);
}
}
if (!invalidMetrics.isEmpty()) {
throw new IllegalArgumentException(unrecognized(request, invalidMetrics, METRICS.keySet(), "metric"));
}
}
if (request.hasParam("groups")) {
indicesStatsRequest.groups(Strings.splitStringByCommaToArray(request.param("groups")));
}
if (indicesStatsRequest.completion() && (request.hasParam("fields") || request.hasParam("completion_fields"))) {
indicesStatsRequest.completionFields(request.paramAsStringArray("completion_fields", request.paramAsStringArray("fields", Strings.EMPTY_ARRAY)));
}
if (indicesStatsRequest.fieldData() && (request.hasParam("fields") || request.hasParam("fielddata_fields"))) {
indicesStatsRequest.fieldDataFields(request.paramAsStringArray("fielddata_fields", request.paramAsStringArray("fields", Strings.EMPTY_ARRAY)));
}
if (indicesStatsRequest.segments()) {
indicesStatsRequest.includeSegmentFileSizes(request.paramAsBoolean("include_segment_file_sizes", false));
indicesStatsRequest.includeUnloadedSegments(request.paramAsBoolean("include_unloaded_segments", false));
}
return channel -> client.admin().indices().stats(indicesStatsRequest, new RestToXContentListener<>(channel));
}
Aggregations