Skip to content

Commit fb90770

Browse files
committed
Merge branch 'master' into index-lifecycle
2 parents 3afb8e8 + dd3fe92 commit fb90770

File tree

95 files changed

+3540
-858
lines changed

Some content is hidden

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

95 files changed

+3540
-858
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]StoredScriptsDocumentationIT.java" id="SnippetLength" />
4343
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]TasksClientDocumentationIT.java" id="SnippetLength" />
4444
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]WatcherDocumentationIT.java" id="SnippetLength" />
45-
<!--
46-
This one is in plugins/examples/script-expert-scoring but we need to
47-
suppress it like this because we build that project twice, once in for
48-
real and once as a test for our build system. -->
49-
<suppress files="src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]example[/\\]expertscript[/\\]ExpertScriptPlugin.java" id="SnippetLength" />
5045
<suppress files="modules[/\\]reindex[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]ReindexDocumentationIT.jav" id="SnippetLength" />
5146

5247
<!-- Hopefully temporary suppression of LineLength on files that don't pass it. We should remove these when we the
@@ -166,7 +161,6 @@
166161
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]AcknowledgedRequestBuilder.java" checks="LineLength" />
167162
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]MasterNodeOperationRequestBuilder.java" checks="LineLength" />
168163
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]MasterNodeReadOperationRequestBuilder.java" checks="LineLength" />
169-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]TransportMasterNodeAction.java" checks="LineLength" />
170164
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]info[/\\]ClusterInfoRequest.java" checks="LineLength" />
171165
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]info[/\\]ClusterInfoRequestBuilder.java" checks="LineLength" />
172166
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]info[/\\]TransportClusterInfoAction.java" checks="LineLength" />

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,9 @@ public final BulkByScrollResponse updateByQuery(UpdateByQueryRequest updateByQue
492492
* @param listener the listener to be notified upon request completion
493493
*/
494494
public final void updateByQueryAsync(UpdateByQueryRequest updateByQueryRequest, RequestOptions options,
495-
ActionListener<BulkByScrollResponse> listener) {
495+
ActionListener<BulkByScrollResponse> listener) {
496496
performRequestAsyncAndParseEntity(
497-
updateByQueryRequest, RequestConverters::updateByQuery, options, BulkByScrollResponse::fromXContent, listener, emptySet()
497+
updateByQueryRequest, RequestConverters::updateByQuery, options, BulkByScrollResponse::fromXContent, listener, emptySet()
498498
);
499499
}
500500

@@ -524,36 +524,38 @@ public final BulkByScrollResponse deleteByQuery(DeleteByQueryRequest deleteByQue
524524
public final void deleteByQueryAsync(DeleteByQueryRequest deleteByQueryRequest, RequestOptions options,
525525
ActionListener<BulkByScrollResponse> listener) {
526526
performRequestAsyncAndParseEntity(
527-
deleteByQueryRequest, RequestConverters::deleteByQuery, options, BulkByScrollResponse::fromXContent, listener, emptySet()
527+
deleteByQueryRequest, RequestConverters::deleteByQuery, options, BulkByScrollResponse::fromXContent, listener, emptySet()
528528
);
529529
}
530530

531531
/**
532532
* Executes a reindex rethrottling request.
533533
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-rethrottle">
534-
* Reindex rethrottling API on elastic.co</a>
534+
* Reindex rethrottling API on elastic.co</a>
535+
*
535536
* @param rethrottleRequest the request
536-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
537+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
537538
* @return the response
538539
* @throws IOException in case there is a problem sending the request or parsing back the response
539540
*/
540541
public final ListTasksResponse reindexRethrottle(RethrottleRequest rethrottleRequest, RequestOptions options) throws IOException {
541542
return performRequestAndParseEntity(rethrottleRequest, RequestConverters::rethrottle, options, ListTasksResponse::fromXContent,
542-
emptySet());
543+
emptySet());
543544
}
544545

545546
/**
546547
* Executes a reindex rethrottling request.
547548
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-rethrottle">
548-
* Reindex rethrottling API on elastic.co</a>
549+
* Reindex rethrottling API on elastic.co</a>
550+
*
549551
* @param rethrottleRequest the request
550-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
551-
* @param listener the listener to be notified upon request completion
552+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
553+
* @param listener the listener to be notified upon request completion
552554
*/
553555
public final void reindexRethrottleAsync(RethrottleRequest rethrottleRequest, RequestOptions options,
554-
ActionListener<ListTasksResponse> listener) {
556+
ActionListener<ListTasksResponse> listener) {
555557
performRequestAsyncAndParseEntity(rethrottleRequest, RequestConverters::rethrottle, options, ListTasksResponse::fromXContent,
556-
listener, emptySet());
558+
listener, emptySet());
557559
}
558560

559561
/**

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.client;
2121

2222
import org.elasticsearch.action.ActionListener;
23+
import org.elasticsearch.client.rollup.GetRollupJobRequest;
24+
import org.elasticsearch.client.rollup.GetRollupJobResponse;
2325
import org.elasticsearch.client.rollup.PutRollupJobRequest;
2426
import org.elasticsearch.client.rollup.PutRollupJobResponse;
2527

@@ -73,4 +75,37 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option
7375
PutRollupJobResponse::fromXContent,
7476
listener, Collections.emptySet());
7577
}
78+
79+
/**
80+
* Get a rollup job from the cluster.
81+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html">
82+
* the docs</a> for more.
83+
* @param request the request
84+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
85+
* @return the response
86+
* @throws IOException in case there is a problem sending the request or parsing back the response
87+
*/
88+
public GetRollupJobResponse getRollupJob(GetRollupJobRequest request, RequestOptions options) throws IOException {
89+
return restHighLevelClient.performRequestAndParseEntity(request,
90+
RollupRequestConverters::getJob,
91+
options,
92+
GetRollupJobResponse::fromXContent,
93+
Collections.emptySet());
94+
}
95+
96+
/**
97+
* Asynchronously get a rollup job from the cluster.
98+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html">
99+
* the docs</a> for more.
100+
* @param request the request
101+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
102+
* @param listener the listener to be notified upon request completion
103+
*/
104+
public void getRollupJobAsync(GetRollupJobRequest request, RequestOptions options, ActionListener<GetRollupJobResponse> listener) {
105+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
106+
RollupRequestConverters::getJob,
107+
options,
108+
GetRollupJobResponse::fromXContent,
109+
listener, Collections.emptySet());
110+
}
76111
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*/
1919
package org.elasticsearch.client;
2020

21+
import org.apache.http.client.methods.HttpGet;
2122
import org.apache.http.client.methods.HttpPut;
23+
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2224
import org.elasticsearch.client.rollup.PutRollupJobRequest;
2325

2426
import java.io.IOException;
@@ -42,4 +44,14 @@ static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOEx
4244
request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE));
4345
return request;
4446
}
47+
48+
static Request getJob(final GetRollupJobRequest getRollupJobRequest) {
49+
String endpoint = new RequestConverters.EndpointBuilder()
50+
.addPathPartAsIs("_xpack")
51+
.addPathPartAsIs("rollup")
52+
.addPathPartAsIs("job")
53+
.addPathPart(getRollupJobRequest.getJobId())
54+
.build();
55+
return new Request(HttpGet.METHOD_NAME, endpoint);
56+
}
4557
}

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

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.client.security.PutUserRequest;
2626
import org.elasticsearch.client.security.PutUserResponse;
2727
import org.elasticsearch.client.security.EmptyResponse;
28+
import org.elasticsearch.client.security.ChangePasswordRequest;
2829

2930
import java.io.IOException;
3031

@@ -47,6 +48,7 @@ public final class SecurityClient {
4748
* Create/update a user in the native realm synchronously.
4849
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-users.html">
4950
* the docs</a> for more.
51+
*
5052
* @param request the request with the user's information
5153
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
5254
* @return the response from the put user call
@@ -61,8 +63,9 @@ public PutUserResponse putUser(PutUserRequest request, RequestOptions options) t
6163
* Asynchronously create/update a user in the native realm.
6264
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-users.html">
6365
* the docs</a> for more.
64-
* @param request the request with the user's information
65-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
66+
*
67+
* @param request the request with the user's information
68+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
6669
* @param listener the listener to be notified upon request completion
6770
*/
6871
public void putUserAsync(PutUserRequest request, RequestOptions options, ActionListener<PutUserResponse> listener) {
@@ -74,6 +77,7 @@ public void putUserAsync(PutUserRequest request, RequestOptions options, ActionL
7477
* Enable a native realm or built-in user synchronously.
7578
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html">
7679
* the docs</a> for more.
80+
*
7781
* @param request the request with the user to enable
7882
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
7983
* @return the response from the enable user call
@@ -88,12 +92,13 @@ public EmptyResponse enableUser(EnableUserRequest request, RequestOptions option
8892
* Enable a native realm or built-in user asynchronously.
8993
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html">
9094
* the docs</a> for more.
91-
* @param request the request with the user to enable
92-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
95+
*
96+
* @param request the request with the user to enable
97+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
9398
* @param listener the listener to be notified upon request completion
9499
*/
95100
public void enableUserAsync(EnableUserRequest request, RequestOptions options,
96-
ActionListener<EmptyResponse> listener) {
101+
ActionListener<EmptyResponse> listener) {
97102
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::enableUser, options,
98103
EmptyResponse::fromXContent, listener, emptySet());
99104
}
@@ -102,6 +107,7 @@ public void enableUserAsync(EnableUserRequest request, RequestOptions options,
102107
* Disable a native realm or built-in user synchronously.
103108
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html">
104109
* the docs</a> for more.
110+
*
105111
* @param request the request with the user to disable
106112
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
107113
* @return the response from the enable user call
@@ -116,13 +122,44 @@ public EmptyResponse disableUser(DisableUserRequest request, RequestOptions opti
116122
* Disable a native realm or built-in user asynchronously.
117123
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html">
118124
* the docs</a> for more.
119-
* @param request the request with the user to disable
120-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
125+
*
126+
* @param request the request with the user to disable
127+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
121128
* @param listener the listener to be notified upon request completion
122129
*/
123130
public void disableUserAsync(DisableUserRequest request, RequestOptions options,
124-
ActionListener<EmptyResponse> listener) {
131+
ActionListener<EmptyResponse> listener) {
125132
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::disableUser, options,
126133
EmptyResponse::fromXContent, listener, emptySet());
127134
}
135+
136+
/**
137+
* Change the password of a user of a native realm or built-in user synchronously.
138+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html">
139+
* the docs</a> for more.
140+
*
141+
* @param request the request with the user's new password
142+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
143+
* @return the response from the change user password call
144+
* @throws IOException in case there is a problem sending the request or parsing back the response
145+
*/
146+
public EmptyResponse changePassword(ChangePasswordRequest request, RequestOptions options) throws IOException {
147+
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::changePassword, options,
148+
EmptyResponse::fromXContent, emptySet());
149+
}
150+
151+
/**
152+
* Change the password of a user of a native realm or built-in user asynchronously.
153+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html">
154+
* the docs</a> for more.
155+
*
156+
* @param request the request with the user's new password
157+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
158+
* @param listener the listener to be notified upon request completion
159+
*/
160+
public void changePasswordAsync(ChangePasswordRequest request, RequestOptions options,
161+
ActionListener<EmptyResponse> listener) {
162+
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::changePassword, options,
163+
EmptyResponse::fromXContent, listener, emptySet());
164+
}
128165
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
package org.elasticsearch.client;
2121

22+
import org.apache.http.client.methods.HttpPost;
2223
import org.apache.http.client.methods.HttpPut;
2324
import org.elasticsearch.client.security.DisableUserRequest;
2425
import org.elasticsearch.client.security.EnableUserRequest;
26+
import org.elasticsearch.client.security.ChangePasswordRequest;
2527
import org.elasticsearch.client.security.PutUserRequest;
2628
import org.elasticsearch.client.security.SetUserEnabledRequest;
2729

@@ -34,6 +36,19 @@ final class SecurityRequestConverters {
3436

3537
private SecurityRequestConverters() {}
3638

39+
static Request changePassword(ChangePasswordRequest changePasswordRequest) throws IOException {
40+
String endpoint = new RequestConverters.EndpointBuilder()
41+
.addPathPartAsIs("_xpack/security/user")
42+
.addPathPart(changePasswordRequest.getUsername())
43+
.addPathPartAsIs("_password")
44+
.build();
45+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
46+
request.setEntity(createEntity(changePasswordRequest, REQUEST_BODY_CONTENT_TYPE));
47+
RequestConverters.Params params = new RequestConverters.Params(request);
48+
params.withRefreshPolicy(changePasswordRequest.getRefreshPolicy());
49+
return request;
50+
}
51+
3752
static Request putUser(PutUserRequest putUserRequest) throws IOException {
3853
String endpoint = new RequestConverters.EndpointBuilder()
3954
.addPathPartAsIs("_xpack/security/user")
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.rollup;
21+
22+
import org.elasticsearch.client.Validatable;
23+
import org.elasticsearch.client.ValidationException;
24+
25+
import java.util.Objects;
26+
import java.util.Optional;
27+
28+
/**
29+
* Request to fetch rollup jobs.
30+
*/
31+
public class GetRollupJobRequest implements Validatable {
32+
private final String jobId;
33+
34+
/**
35+
* Create a requets .
36+
* @param jobId id of the job to return or {@code _all} to return all jobs
37+
*/
38+
public GetRollupJobRequest(final String jobId) {
39+
Objects.requireNonNull(jobId, "jobId is required");
40+
if ("_all".equals(jobId)) {
41+
throw new IllegalArgumentException("use the default ctor to ask for all jobs");
42+
}
43+
this.jobId = jobId;
44+
}
45+
46+
/**
47+
* Create a request to load all rollup jobs.
48+
*/
49+
public GetRollupJobRequest() {
50+
this.jobId = "_all";
51+
}
52+
53+
/**
54+
* ID of the job to return.
55+
*/
56+
public String getJobId() {
57+
return jobId;
58+
}
59+
60+
@Override
61+
public Optional<ValidationException> validate() {
62+
return Optional.empty();
63+
}
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
if (this == o) return true;
68+
if (o == null || getClass() != o.getClass()) return false;
69+
final GetRollupJobRequest that = (GetRollupJobRequest) o;
70+
return jobId.equals(that.jobId);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(jobId);
76+
}
77+
}

0 commit comments

Comments
 (0)