-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add high-level REST client API for _freeze and _unfreeze
#35723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f1f26ab
946ea10
90c0f6c
bb17ced
75ea7ac
fcff429
4c67d80
2f8f56c
a70e313
5cbcc4d
5cb84a6
afd5bcf
ed6cfe0
225f7c1
e4cb3b3
6a9bd63
d9e7501
fe49988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ | |
| 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 @@ static Request analyze(AnalyzeRequest request) throws IOException { | |
| req.setEntity(RequestConverters.createEntity(request, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); | ||
| return req; | ||
| } | ||
|
|
||
| static Request freezeIndex(FreezeIndexRequest freezeIndexRequest) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just double checking that these should be added with all the other OSS API, I think it makes sense but let's be sure.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everything is OSS in this package the serverside might not be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that its fine that indices type things can be in the IndicesClient, regardless of their status of commercial/noncommercial. |
||
| 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.