Skip to content

Commit c30265a

Browse files
committed
Merge remote-tracking branch 'origin/master' into slm-retention
2 parents f520f42 + 597194c commit c30265a

File tree

85 files changed

+2813
-713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2813
-713
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
2525
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
2626
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
27-
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
2827
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
2928
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3029
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
@@ -47,6 +46,8 @@
4746
import org.elasticsearch.client.core.ShardsAcknowledgedResponse;
4847
import org.elasticsearch.client.indices.AnalyzeRequest;
4948
import org.elasticsearch.client.indices.AnalyzeResponse;
49+
import org.elasticsearch.client.indices.CloseIndexRequest;
50+
import org.elasticsearch.client.indices.CloseIndexResponse;
5051
import org.elasticsearch.client.indices.CreateIndexRequest;
5152
import org.elasticsearch.client.indices.CreateIndexResponse;
5253
import org.elasticsearch.client.indices.FreezeIndexRequest;
@@ -471,9 +472,9 @@ public void openAsync(OpenIndexRequest openIndexRequest, RequestOptions options,
471472
* @return the response
472473
* @throws IOException in case there is a problem sending the request or parsing back the response
473474
*/
474-
public AcknowledgedResponse close(CloseIndexRequest closeIndexRequest, RequestOptions options) throws IOException {
475+
public CloseIndexResponse close(CloseIndexRequest closeIndexRequest, RequestOptions options) throws IOException {
475476
return restHighLevelClient.performRequestAndParseEntity(closeIndexRequest, IndicesRequestConverters::closeIndex, options,
476-
AcknowledgedResponse::fromXContent, emptySet());
477+
CloseIndexResponse::fromXContent, emptySet());
477478
}
478479

479480
/**
@@ -484,9 +485,9 @@ public AcknowledgedResponse close(CloseIndexRequest closeIndexRequest, RequestOp
484485
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
485486
* @param listener the listener to be notified upon request completion
486487
*/
487-
public void closeAsync(CloseIndexRequest closeIndexRequest, RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
488+
public void closeAsync(CloseIndexRequest closeIndexRequest, RequestOptions options, ActionListener<CloseIndexResponse> listener) {
488489
restHighLevelClient.performRequestAsyncAndParseEntity(closeIndexRequest, IndicesRequestConverters::closeIndex, options,
489-
AcknowledgedResponse::fromXContent, listener, emptySet());
490+
CloseIndexResponse::fromXContent, listener, emptySet());
490491
}
491492

492493

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
2828
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
2929
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
30-
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
3130
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3231
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3332
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
@@ -41,6 +40,7 @@
4140
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
4241
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
4342
import org.elasticsearch.client.indices.AnalyzeRequest;
43+
import org.elasticsearch.client.indices.CloseIndexRequest;
4444
import org.elasticsearch.client.indices.CreateIndexRequest;
4545
import org.elasticsearch.client.indices.FreezeIndexRequest;
4646
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.indices;
21+
22+
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
23+
import org.elasticsearch.action.support.ActiveShardCount;
24+
import org.elasticsearch.action.support.IndicesOptions;
25+
import org.elasticsearch.client.TimedRequest;
26+
import org.elasticsearch.client.Validatable;
27+
import org.elasticsearch.client.ValidationException;
28+
29+
import java.util.Optional;
30+
31+
/**
32+
* A request to close an index.
33+
*/
34+
public class CloseIndexRequest extends TimedRequest implements Validatable {
35+
36+
private String[] indices;
37+
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
38+
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;
39+
40+
/**
41+
* Creates a new close index request
42+
*
43+
* @param indices the indices to close
44+
*/
45+
public CloseIndexRequest(String... indices) {
46+
this.indices = indices;
47+
}
48+
49+
/**
50+
* Returns the indices to close
51+
*/
52+
public String[] indices() {
53+
return indices;
54+
}
55+
56+
/**
57+
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
58+
* For example indices that don't exist.
59+
*
60+
* @return the current behaviour when it comes to index names and wildcard indices expressions
61+
*/
62+
public IndicesOptions indicesOptions() {
63+
return indicesOptions;
64+
}
65+
66+
/**
67+
* Specifies what type of requested indices to ignore and how to deal with wildcard expressions.
68+
* For example indices that don't exist.
69+
*
70+
* @param indicesOptions the desired behaviour regarding indices to ignore and wildcard indices expressions
71+
*/
72+
public CloseIndexRequest indicesOptions(IndicesOptions indicesOptions) {
73+
this.indicesOptions = indicesOptions;
74+
return this;
75+
}
76+
77+
/**
78+
* Returns the wait for active shard count or null if the default should be used
79+
*/
80+
public ActiveShardCount waitForActiveShards() {
81+
return waitForActiveShards;
82+
}
83+
84+
/**
85+
* Sets the number of shard copies that should be active for indices opening to return.
86+
* Defaults to {@link ActiveShardCount#DEFAULT}, which will wait for one shard copy
87+
* (the primary) to become active. Set this value to {@link ActiveShardCount#ALL} to
88+
* wait for all shards (primary and all replicas) to be active before returning.
89+
* Otherwise, use {@link ActiveShardCount#from(int)} to set this value to any
90+
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
91+
* to wait for the desired amount of shard copies to become active before returning.
92+
* Indices opening will only wait up until the timeout value for the number of shard copies
93+
* to be active before returning. Check {@link OpenIndexResponse#isShardsAcknowledged()} to
94+
* determine if the requisite shard copies were all started before returning or timing out.
95+
*
96+
* @param waitForActiveShards number of active shard copies to wait on
97+
*/
98+
public CloseIndexRequest waitForActiveShards(ActiveShardCount waitForActiveShards) {
99+
this.waitForActiveShards = waitForActiveShards;
100+
return this;
101+
}
102+
103+
@Override
104+
public Optional<ValidationException> validate() {
105+
if (indices == null || indices.length == 0) {
106+
ValidationException validationException = new ValidationException();
107+
validationException.addValidationError("index is missing");
108+
return Optional.of(validationException);
109+
} else {
110+
return Optional.empty();
111+
}
112+
}
113+
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.client.indices;
20+
21+
import org.elasticsearch.ElasticsearchException;
22+
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
23+
import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse;
24+
import org.elasticsearch.common.Nullable;
25+
import org.elasticsearch.common.ParseField;
26+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
27+
import org.elasticsearch.common.xcontent.XContentParser;
28+
import org.elasticsearch.common.xcontent.XContentParserUtils;
29+
30+
import java.util.List;
31+
import java.util.Objects;
32+
33+
import static java.util.Collections.emptyList;
34+
import static java.util.Collections.unmodifiableList;
35+
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
36+
import static org.elasticsearch.common.xcontent.ObjectParser.ValueType;
37+
38+
public class CloseIndexResponse extends ShardsAcknowledgedResponse {
39+
40+
@SuppressWarnings("unchecked")
41+
private static final ConstructingObjectParser<CloseIndexResponse, Void> PARSER = new ConstructingObjectParser<>("close_index_response",
42+
true, args -> {
43+
boolean acknowledged = (boolean) args[0];
44+
boolean shardsAcknowledged = args[1] != null ? (boolean) args[1] : acknowledged;
45+
List<CloseIndexResponse.IndexResult> indices = args[2] != null ? (List<CloseIndexResponse.IndexResult>) args[2] : emptyList();
46+
return new CloseIndexResponse(acknowledged, shardsAcknowledged, indices);
47+
});
48+
49+
static {
50+
declareAcknowledgedField(PARSER);
51+
PARSER.declareField(optionalConstructorArg(), (parser, context) -> parser.booleanValue(), SHARDS_ACKNOWLEDGED, ValueType.BOOLEAN);
52+
PARSER.declareNamedObjects(optionalConstructorArg(), (p, c, name) -> IndexResult.fromXContent(p, name), new ParseField("indices"));
53+
}
54+
55+
private final List<CloseIndexResponse.IndexResult> indices;
56+
57+
public CloseIndexResponse(final boolean acknowledged, final boolean shardsAcknowledged, final List<IndexResult> indices) {
58+
super(acknowledged, shardsAcknowledged);
59+
this.indices = unmodifiableList(Objects.requireNonNull(indices));
60+
}
61+
62+
public List<IndexResult> getIndices() {
63+
return indices;
64+
}
65+
66+
public static CloseIndexResponse fromXContent(final XContentParser parser) {
67+
return PARSER.apply(parser, null);
68+
}
69+
70+
public static class IndexResult {
71+
72+
@SuppressWarnings("unchecked")
73+
private static final ConstructingObjectParser<IndexResult, String> PARSER = new ConstructingObjectParser<>("index_result", true,
74+
(args, index) -> {
75+
Exception exception = (Exception) args[1];
76+
if (exception != null) {
77+
assert (boolean) args[0] == false;
78+
return new IndexResult(index, exception);
79+
}
80+
ShardResult[] shardResults = args[2] != null ? ((List<ShardResult>) args[2]).toArray(new ShardResult[0]) : null;
81+
if (shardResults != null) {
82+
assert (boolean) args[0] == false;
83+
return new IndexResult(index, shardResults);
84+
}
85+
assert (boolean) args[0];
86+
return new IndexResult(index);
87+
});
88+
static {
89+
PARSER.declareBoolean(optionalConstructorArg(), new ParseField("closed"));
90+
PARSER.declareObject(optionalConstructorArg(), (p, c) -> {
91+
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, p.currentToken(), p::getTokenLocation);
92+
XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, p.nextToken(), p::getTokenLocation);
93+
Exception e = ElasticsearchException.failureFromXContent(p);
94+
XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, p.nextToken(), p::getTokenLocation);
95+
return e;
96+
}, new ParseField("exception"));
97+
PARSER.declareNamedObjects(optionalConstructorArg(),
98+
(p, c, id) -> ShardResult.fromXContent(p, id), new ParseField("failedShards"));
99+
}
100+
101+
private final String index;
102+
private final @Nullable Exception exception;
103+
private final @Nullable ShardResult[] shards;
104+
105+
IndexResult(final String index) {
106+
this(index, null, null);
107+
}
108+
109+
IndexResult(final String index, final Exception failure) {
110+
this(index, Objects.requireNonNull(failure), null);
111+
}
112+
113+
IndexResult(final String index, final ShardResult[] shards) {
114+
this(index, null, Objects.requireNonNull(shards));
115+
}
116+
117+
private IndexResult(final String index, @Nullable final Exception exception, @Nullable final ShardResult[] shards) {
118+
this.index = Objects.requireNonNull(index);
119+
this.exception = exception;
120+
this.shards = shards;
121+
}
122+
123+
public String getIndex() {
124+
return index;
125+
}
126+
127+
public @Nullable Exception getException() {
128+
return exception;
129+
}
130+
131+
public @Nullable ShardResult[] getShards() {
132+
return shards;
133+
}
134+
135+
public boolean hasFailures() {
136+
if (exception != null) {
137+
return true;
138+
}
139+
if (shards != null) {
140+
for (ShardResult shard : shards) {
141+
if (shard.hasFailures()) {
142+
return true;
143+
}
144+
}
145+
}
146+
return false;
147+
}
148+
149+
static IndexResult fromXContent(final XContentParser parser, final String name) {
150+
return PARSER.apply(parser, name);
151+
}
152+
}
153+
154+
public static class ShardResult {
155+
156+
@SuppressWarnings("unchecked")
157+
private static final ConstructingObjectParser<ShardResult, String> PARSER = new ConstructingObjectParser<>("shard_result", true,
158+
(arg, id) -> {
159+
Failure[] failures = arg[0] != null ? ((List<Failure>) arg[0]).toArray(new Failure[0]) : new Failure[0];
160+
return new ShardResult(Integer.parseInt(id), failures);
161+
});
162+
163+
static {
164+
PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> Failure.PARSER.apply(p, null), new ParseField("failures"));
165+
}
166+
167+
private final int id;
168+
private final Failure[] failures;
169+
170+
ShardResult(final int id, final Failure[] failures) {
171+
this.id = id;
172+
this.failures = failures;
173+
}
174+
175+
public boolean hasFailures() {
176+
return failures != null && failures.length > 0;
177+
}
178+
179+
public int getId() {
180+
return id;
181+
}
182+
183+
public Failure[] getFailures() {
184+
return failures;
185+
}
186+
187+
static ShardResult fromXContent(final XContentParser parser, final String id) {
188+
return PARSER.apply(parser, id);
189+
}
190+
191+
public static class Failure extends DefaultShardOperationFailedException {
192+
193+
static final ConstructingObjectParser<Failure, Void> PARSER = new ConstructingObjectParser<>("failure", true,
194+
arg -> new Failure((String) arg[0], (int) arg[1], (Throwable) arg[2], (String) arg[3]));
195+
196+
static {
197+
declareFields(PARSER);
198+
PARSER.declareStringOrNull(optionalConstructorArg(), new ParseField("node"));
199+
}
200+
201+
private @Nullable String nodeId;
202+
203+
Failure(final String index, final int shardId, final Throwable reason, final String nodeId) {
204+
super(index, shardId, reason);
205+
this.nodeId = nodeId;
206+
}
207+
208+
public String getNodeId() {
209+
return nodeId;
210+
}
211+
}
212+
}
213+
}

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/FreezeIndexRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void setIndicesOptions(IndicesOptions indicesOptions) {
7070
}
7171

7272
/**
73-
* Returns the wait for active shard cound or null if the default should be used
73+
* Returns the wait for active shard count or null if the default should be used
7474
*/
7575
public ActiveShardCount getWaitForActiveShards() {
7676
return waitForActiveShards;

0 commit comments

Comments
 (0)