Add high-level REST client API for `_freeze` and `_unfreeze` (#35723)

This change adds support for `_freeze` and `_unfreeze` to the HLRC

Relates to #34352
This commit is contained in:
Simon Willnauer 2018-11-28 15:42:12 +01:00 committed by GitHub
parent 0588dad80b
commit 89e4ac8fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 701 additions and 15 deletions

View File

@ -59,6 +59,9 @@ import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateReque
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.rest.RestStatus;
import java.io.IOException;
@ -836,4 +839,51 @@ public final class IndicesClient {
restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::analyze, options,
AnalyzeResponse::fromXContent, listener, emptySet());
}
/**
* Synchronously calls the _freeze API
*
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
*/
public ShardsAcknowledgedResponse freeze(FreezeIndexRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::freezeIndex, options,
ShardsAcknowledgedResponse::fromXContent, emptySet());
}
/**
* Asynchronously calls the _freeze API
*
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void freezeAsync(FreezeIndexRequest request, RequestOptions options, ActionListener<ShardsAcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::freezeIndex, options,
ShardsAcknowledgedResponse::fromXContent, listener, emptySet());
}
/**
* Synchronously calls the _unfreeze API
*
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
*/
public ShardsAcknowledgedResponse unfreeze(UnfreezeIndexRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::unfreezeIndex, options,
ShardsAcknowledgedResponse::fromXContent, emptySet());
}
/**
* Asynchronously calls the _unfreeze API
*
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void unfreezeAsync(UnfreezeIndexRequest request, RequestOptions options, ActionListener<ShardsAcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::unfreezeIndex, options,
ShardsAcknowledgedResponse::fromXContent, listener, emptySet());
}
}

View File

@ -48,6 +48,8 @@ import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.common.Strings;
import java.io.IOException;
@ -403,4 +405,26 @@ final class IndicesRequestConverters {
req.setEntity(RequestConverters.createEntity(request, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return req;
}
static Request freezeIndex(FreezeIndexRequest freezeIndexRequest) {
String endpoint = RequestConverters.endpoint(freezeIndexRequest.getIndices(), "_freeze");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params(request);
parameters.withTimeout(freezeIndexRequest.timeout());
parameters.withMasterTimeout(freezeIndexRequest.masterNodeTimeout());
parameters.withIndicesOptions(freezeIndexRequest.indicesOptions());
parameters.withWaitForActiveShards(freezeIndexRequest.getWaitForActiveShards());
return request;
}
static Request unfreezeIndex(UnfreezeIndexRequest unfreezeIndexRequest) {
String endpoint = RequestConverters.endpoint(unfreezeIndexRequest.getIndices(), "_unfreeze");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params(request);
parameters.withTimeout(unfreezeIndexRequest.timeout());
parameters.withMasterTimeout(unfreezeIndexRequest.masterNodeTimeout());
parameters.withIndicesOptions(unfreezeIndexRequest.indicesOptions());
parameters.withWaitForActiveShards(unfreezeIndexRequest.getWaitForActiveShards());
return request;
}
}

View File

@ -859,22 +859,24 @@ final class RequestConverters {
}
Params withIndicesOptions(IndicesOptions indicesOptions) {
withIgnoreUnavailable(indicesOptions.ignoreUnavailable());
putParam("allow_no_indices", Boolean.toString(indicesOptions.allowNoIndices()));
String expandWildcards;
if (indicesOptions.expandWildcardsOpen() == false && indicesOptions.expandWildcardsClosed() == false) {
expandWildcards = "none";
} else {
StringJoiner joiner = new StringJoiner(",");
if (indicesOptions.expandWildcardsOpen()) {
joiner.add("open");
if (indicesOptions != null) {
withIgnoreUnavailable(indicesOptions.ignoreUnavailable());
putParam("allow_no_indices", Boolean.toString(indicesOptions.allowNoIndices()));
String expandWildcards;
if (indicesOptions.expandWildcardsOpen() == false && indicesOptions.expandWildcardsClosed() == false) {
expandWildcards = "none";
} else {
StringJoiner joiner = new StringJoiner(",");
if (indicesOptions.expandWildcardsOpen()) {
joiner.add("open");
}
if (indicesOptions.expandWildcardsClosed()) {
joiner.add("closed");
}
expandWildcards = joiner.toString();
}
if (indicesOptions.expandWildcardsClosed()) {
joiner.add("closed");
}
expandWildcards = joiner.toString();
putParam("expand_wildcards", expandWildcards);
}
putParam("expand_wildcards", expandWildcards);
return this;
}

View File

@ -0,0 +1,57 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.core;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
public class ShardsAcknowledgedResponse extends AcknowledgedResponse {
protected static final String SHARDS_PARSE_FIELD_NAME = "shards_acknowledged";
private static ConstructingObjectParser<ShardsAcknowledgedResponse, Void> buildParser() {
ConstructingObjectParser<ShardsAcknowledgedResponse, Void> p = new ConstructingObjectParser<>("freeze", true,
args -> new ShardsAcknowledgedResponse((boolean) args[0], (boolean) args[1]));
p.declareBoolean(constructorArg(), new ParseField(AcknowledgedResponse.PARSE_FIELD_NAME));
p.declareBoolean(constructorArg(), new ParseField(SHARDS_PARSE_FIELD_NAME));
return p;
}
private static final ConstructingObjectParser<ShardsAcknowledgedResponse, Void> PARSER = buildParser();
private final boolean shardsAcknowledged;
public ShardsAcknowledgedResponse(boolean acknowledged, boolean shardsAcknowledged) {
super(acknowledged);
this.shardsAcknowledged = shardsAcknowledged;
}
public boolean isShardsAcknowledged() {
return shardsAcknowledged;
}
public static ShardsAcknowledgedResponse fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
}

View File

@ -0,0 +1,96 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.indices;
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.TimedRequest;
import java.util.Objects;
/**
* Request for the _freeze index API
*/
public final class FreezeIndexRequest extends TimedRequest {
private final String[] indices;
private IndicesOptions indicesOptions;
private ActiveShardCount waitForActiveShards;
/**
* Creates a new freeze index request
* @param indices the index to freeze
*/
public FreezeIndexRequest(String... indices) {
this.indices = Objects.requireNonNull(indices);
}
/**
* Returns the indices to freeze
*/
public String[] getIndices() {
return indices;
}
/**
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
* For example indices that don't exist.
*
* @return the current behaviour when it comes to index names and wildcard indices expressions
*/
public IndicesOptions indicesOptions() {
return indicesOptions;
}
/**
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
* For example indices that don't exist.
*
* @param indicesOptions the desired behaviour regarding indices to ignore and wildcard indices expressions
*/
public void setIndicesOptions(IndicesOptions indicesOptions) {
this.indicesOptions = indicesOptions;
}
/**
* Returns the wait for active shard cound or null if the default should be used
*/
public ActiveShardCount getWaitForActiveShards() {
return waitForActiveShards;
}
/**
* Sets the number of shard copies that should be active for indices opening to return.
* Defaults to {@link ActiveShardCount#DEFAULT}, which will wait for one shard copy
* (the primary) to become active. Set this value to {@link ActiveShardCount#ALL} to
* wait for all shards (primary and all replicas) to be active before returning.
* Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Indices opening will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link OpenIndexResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
*/
public void setWaitForActiveShards(ActiveShardCount waitForActiveShards) {
this.waitForActiveShards = waitForActiveShards;
}
}

View File

@ -0,0 +1,97 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.indices;
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.TimedRequest;
import java.util.Objects;
/**
* Request for the _unfreeze index API
*/
public final class UnfreezeIndexRequest extends TimedRequest {
private final String[] indices;
private IndicesOptions indicesOptions;
private ActiveShardCount waitForActiveShards;
/**
* Creates a new unfreeze index request
* @param indices the index to unfreeze
*/
public UnfreezeIndexRequest(String... indices) {
this.indices = Objects.requireNonNull(indices);
}
/**
* Returns the indices to unfreeze
*/
public String[] getIndices() {
return indices;
}
/**
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
* For example indices that don't exist.
*
* @return the current behaviour when it comes to index names and wildcard indices expressions
*/
public IndicesOptions indicesOptions() {
return indicesOptions;
}
/**
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
* For example indices that don't exist.
*
* @param indicesOptions the desired behaviour regarding indices to ignore and wildcard indices expressions
*/
public void setIndicesOptions(IndicesOptions indicesOptions) {
this.indicesOptions = indicesOptions;
}
/**
* Returns the wait for active shard cound or null if the default should be used
*/
public ActiveShardCount getWaitForActiveShards() {
return waitForActiveShards;
}
/**
* Sets the number of shard copies that should be active for indices opening to return.
* Defaults to {@link ActiveShardCount#DEFAULT}, which will wait for one shard copy
* (the primary) to become active. Set this value to {@link ActiveShardCount#ALL} to
* wait for all shards (primary and all replicas) to be active before returning.
* Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Indices opening will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link OpenIndexResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
*/
public void setWaitForActiveShards(ActiveShardCount waitForActiveShards) {
this.waitForActiveShards = waitForActiveShards;
}
}

View File

@ -70,6 +70,9 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
@ -1370,6 +1373,20 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
AnalyzeResponse detailsResponse = execute(detailsRequest, client.indices()::analyze, client.indices()::analyzeAsync);
assertNotNull(detailsResponse.detail());
}
public void testFreezeAndUnfreeze() throws IOException {
createIndex("test", Settings.EMPTY);
RestHighLevelClient client = highLevelClient();
ShardsAcknowledgedResponse freeze = execute(new FreezeIndexRequest("test"), client.indices()::freeze,
client.indices()::freezeAsync);
assertTrue(freeze.isShardsAcknowledged());
assertTrue(freeze.isAcknowledged());
ShardsAcknowledgedResponse unfreeze = execute(new UnfreezeIndexRequest("test"), client.indices()::unfreeze,
client.indices()::unfreezeAsync);
assertTrue(unfreeze.isShardsAcknowledged());
assertTrue(unfreeze.isAcknowledged());
}
}

View File

@ -751,7 +751,8 @@ public class RestHighLevelClientTests extends ESTestCase {
apiName.startsWith("migration.") == false &&
apiName.startsWith("security.") == false &&
apiName.startsWith("index_lifecycle.") == false &&
apiName.startsWith("ccr.") == false) {
apiName.startsWith("ccr.") == false &&
apiName.endsWith("freeze") == false) {
apiNotFound.add(apiName);
}
}

View File

@ -0,0 +1,52 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.core;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
public class ShardsAcknowledgedResponseTests extends ESTestCase {
public void testFromXContent() throws IOException {
xContentTester(this::createParser,
this::createTestInstance,
ShardsAcknowledgedResponseTests::toXContent,
ShardsAcknowledgedResponse::fromXContent)
.supportsUnknownFields(false)
.test();
}
private ShardsAcknowledgedResponse createTestInstance() {
return new ShardsAcknowledgedResponse(randomBoolean(), randomBoolean());
}
public static void toXContent(ShardsAcknowledgedResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
{
builder.field(response.getFieldName(), response.isAcknowledged());
builder.field(ShardsAcknowledgedResponse.SHARDS_PARSE_FIELD_NAME, response.isShardsAcknowledged());
}
builder.endObject();
}
}

View File

@ -70,10 +70,13 @@ import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.GetAliasesResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.SyncedFlushResponse;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
@ -2527,4 +2530,160 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
}
}
public void testFreezeIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
}
{
// tag::freeze-index-request
FreezeIndexRequest request = new FreezeIndexRequest("index"); // <1>
// end::freeze-index-request
// tag::freeze-index-request-timeout
request.setTimeout(TimeValue.timeValueMinutes(2)); // <1>
// end::freeze-index-request-timeout
// tag::freeze-index-request-masterTimeout
request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1>
// end::freeze-index-request-masterTimeout
// tag::freeze-index-request-waitForActiveShards
request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <1>
// end::freeze-index-request-waitForActiveShards
// tag::freeze-index-request-indicesOptions
request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1>
// end::freeze-index-request-indicesOptions
// tag::freeze-index-execute
ShardsAcknowledgedResponse openIndexResponse = client.indices().freeze(request, RequestOptions.DEFAULT);
// end::freeze-index-execute
// tag::freeze-index-response
boolean acknowledged = openIndexResponse.isAcknowledged(); // <1>
boolean shardsAcked = openIndexResponse.isShardsAcknowledged(); // <2>
// end::freeze-index-response
assertTrue(acknowledged);
assertTrue(shardsAcked);
// tag::freeze-index-execute-listener
ActionListener<ShardsAcknowledgedResponse> listener =
new ActionListener<ShardsAcknowledgedResponse>() {
@Override
public void onResponse(ShardsAcknowledgedResponse freezeIndexResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::freeze-index-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::freeze-index-execute-async
client.indices().freezeAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::freeze-index-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
{
// tag::freeze-index-notfound
try {
FreezeIndexRequest request = new FreezeIndexRequest("does_not_exist");
client.indices().freeze(request, RequestOptions.DEFAULT);
} catch (ElasticsearchException exception) {
if (exception.status() == RestStatus.BAD_REQUEST) {
// <1>
}
}
// end::freeze-index-notfound
}
}
public void testUnfreezeIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
}
{
// tag::unfreeze-index-request
UnfreezeIndexRequest request = new UnfreezeIndexRequest("index"); // <1>
// end::unfreeze-index-request
// tag::unfreeze-index-request-timeout
request.setTimeout(TimeValue.timeValueMinutes(2)); // <1>
// end::unfreeze-index-request-timeout
// tag::unfreeze-index-request-masterTimeout
request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1>
// end::unfreeze-index-request-masterTimeout
// tag::unfreeze-index-request-waitForActiveShards
request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <1>
// end::unfreeze-index-request-waitForActiveShards
// tag::unfreeze-index-request-indicesOptions
request.setIndicesOptions(IndicesOptions.strictExpandOpen()); // <1>
// end::unfreeze-index-request-indicesOptions
// tag::unfreeze-index-execute
ShardsAcknowledgedResponse openIndexResponse = client.indices().unfreeze(request, RequestOptions.DEFAULT);
// end::unfreeze-index-execute
// tag::unfreeze-index-response
boolean acknowledged = openIndexResponse.isAcknowledged(); // <1>
boolean shardsAcked = openIndexResponse.isShardsAcknowledged(); // <2>
// end::unfreeze-index-response
assertTrue(acknowledged);
assertTrue(shardsAcked);
// tag::unfreeze-index-execute-listener
ActionListener<ShardsAcknowledgedResponse> listener =
new ActionListener<ShardsAcknowledgedResponse>() {
@Override
public void onResponse(ShardsAcknowledgedResponse freezeIndexResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::unfreeze-index-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::unfreeze-index-execute-async
client.indices().unfreezeAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::unfreeze-index-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
{
// tag::unfreeze-index-notfound
try {
UnfreezeIndexRequest request = new UnfreezeIndexRequest("does_not_exist");
client.indices().unfreeze(request, RequestOptions.DEFAULT);
} catch (ElasticsearchException exception) {
if (exception.status() == RestStatus.BAD_REQUEST) {
// <1>
}
}
// end::unfreeze-index-notfound
}
}
}

View File

@ -0,0 +1,65 @@
--
:api: freeze-index
:request: FreezeIndexRequest
:response: FreezeIndexResponse
--
[id="{upid}-{api}"]
=== Freeze Index API
[id="{upid}-{api}-request"]
==== Freeze Index Request
An +{request}+ requires an `index` argument:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> The index to freeze
==== Optional arguments
The following arguments can optionally be provided:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-timeout]
--------------------------------------------------
<1> Timeout to wait for the all the nodes to acknowledge the index is frozen
as a `TimeValue`
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-masterTimeout]
--------------------------------------------------
<1> Timeout to connect to the master node as a `TimeValue`
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards]
--------------------------------------------------
<1> The number of active shard copies to wait for before the freeze index API
returns a response, as an `ActiveShardCount`
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
--------------------------------------------------
<1> Setting `IndicesOptions` controls how unavailable indices are resolved and
how wildcard expressions are expanded
include::../execution.asciidoc[]
[id="{upid}-{api}-response"]
==== Freeze Index Response
The returned +{response}+ allows to retrieve information about the
executed operation as follows:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-response]
--------------------------------------------------
<1> Indicates whether all of the nodes have acknowledged the request
<2> Indicates whether the requisite number of shard copies were started for
each shard in the index before timing out

View File

@ -0,0 +1,64 @@
--
:api: freeze-index
:request: UnfreezeIndexRequest
:response: UnfreezeIndexResponse
--
[id="{upid}-{api}"]
=== Unfreeze Index API
[id="{upid}-{api}-request"]
==== Unfreeze Index Request
An +{request}+ requires an `index` argument:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> The index to unreeze
==== Optional arguments
The following arguments can optionally be provided:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-timeout]
--------------------------------------------------
<1> Timeout to wait for the all the nodes to acknowledge the index is frozen
as a `TimeValue`
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-masterTimeout]
--------------------------------------------------
<1> Timeout to connect to the master node as a `TimeValue`
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards]
--------------------------------------------------
<1> The number of active shard copies to wait for before the unfreeze index API
returns a response, as an `ActiveShardCount`
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
--------------------------------------------------
<1> Setting `IndicesOptions` controls how unavailable indices are resolved and
how wildcard expressions are expanded
include::../execution.asciidoc[]
[id="{upid}-{api}-response"]
==== Unfreeze Index Response
The returned +{response}+ allows to retrieve information about the
executed operation as follows:
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-response]
--------------------------------------------------
<1> Indicates whether all of the nodes have acknowledged the request
<2> Indicates whether the requisite number of shard copies were started for
each shard in the index before timing out

View File

@ -146,6 +146,8 @@ include::indices/put_template.asciidoc[]
include::indices/validate_query.asciidoc[]
include::indices/get_templates.asciidoc[]
include::indices/get_index.asciidoc[]
include::indices/freeze_index.asciidoc[]
include::indices/unfreeze_index.asciidoc[]
== Cluster APIs