Skip to content

Commit 1aa3606

Browse files
committed
[HLRC] Add GetRollupIndexCaps API (#35102)
Also refactors the caps response tests a bit to share the same abstract class to reduce duplication of test code
1 parent 9e764bd commit 1aa3606

File tree

13 files changed

+834
-185
lines changed

13 files changed

+834
-185
lines changed

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

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import org.elasticsearch.action.ActionListener;
2323
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
2424
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
25-
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
26-
import org.elasticsearch.client.rollup.GetRollupCapsResponse;
25+
import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest;
26+
import org.elasticsearch.client.rollup.GetRollupIndexCapsResponse;
2727
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2828
import org.elasticsearch.client.rollup.GetRollupJobResponse;
29+
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
30+
import org.elasticsearch.client.rollup.GetRollupCapsResponse;
2931
import org.elasticsearch.client.rollup.PutRollupJobRequest;
3032
import org.elasticsearch.client.rollup.PutRollupJobResponse;
3133
import org.elasticsearch.client.rollup.StartRollupJobRequest;
@@ -60,10 +62,10 @@ public class RollupClient {
6062
*/
6163
public PutRollupJobResponse putRollupJob(PutRollupJobRequest request, RequestOptions options) throws IOException {
6264
return restHighLevelClient.performRequestAndParseEntity(request,
63-
RollupRequestConverters::putJob,
64-
options,
65-
PutRollupJobResponse::fromXContent,
66-
Collections.emptySet());
65+
RollupRequestConverters::putJob,
66+
options,
67+
PutRollupJobResponse::fromXContent,
68+
Collections.emptySet());
6769
}
6870

6971
/**
@@ -76,10 +78,10 @@ public PutRollupJobResponse putRollupJob(PutRollupJobRequest request, RequestOpt
7678
*/
7779
public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions options, ActionListener<PutRollupJobResponse> listener) {
7880
restHighLevelClient.performRequestAsyncAndParseEntity(request,
79-
RollupRequestConverters::putJob,
80-
options,
81-
PutRollupJobResponse::fromXContent,
82-
listener, Collections.emptySet());
81+
RollupRequestConverters::putJob,
82+
options,
83+
PutRollupJobResponse::fromXContent,
84+
listener, Collections.emptySet());
8385
}
8486

8587
/**
@@ -93,10 +95,10 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option
9395
*/
9496
public StartRollupJobResponse startRollupJob(StartRollupJobRequest request, RequestOptions options) throws IOException {
9597
return restHighLevelClient.performRequestAndParseEntity(request,
96-
RollupRequestConverters::startJob,
97-
options,
98-
StartRollupJobResponse::fromXContent,
99-
Collections.emptySet());
98+
RollupRequestConverters::startJob,
99+
options,
100+
StartRollupJobResponse::fromXContent,
101+
Collections.emptySet());
100102
}
101103

102104
/**
@@ -110,10 +112,10 @@ public StartRollupJobResponse startRollupJob(StartRollupJobRequest request, Requ
110112
public void startRollupJobAsync(StartRollupJobRequest request, RequestOptions options,
111113
ActionListener<StartRollupJobResponse> listener) {
112114
restHighLevelClient.performRequestAsyncAndParseEntity(request,
113-
RollupRequestConverters::startJob,
114-
options,
115-
StartRollupJobResponse::fromXContent,
116-
listener, Collections.emptySet());
115+
RollupRequestConverters::startJob,
116+
options,
117+
StartRollupJobResponse::fromXContent,
118+
listener, Collections.emptySet());
117119
}
118120

119121
/**
@@ -161,10 +163,10 @@ public void deleteRollupJobAsync(DeleteRollupJobRequest request,
161163
*/
162164
public GetRollupJobResponse getRollupJob(GetRollupJobRequest request, RequestOptions options) throws IOException {
163165
return restHighLevelClient.performRequestAndParseEntity(request,
164-
RollupRequestConverters::getJob,
165-
options,
166-
GetRollupJobResponse::fromXContent,
167-
Collections.emptySet());
166+
RollupRequestConverters::getJob,
167+
options,
168+
GetRollupJobResponse::fromXContent,
169+
Collections.emptySet());
168170
}
169171

170172
/**
@@ -179,10 +181,10 @@ public GetRollupJobResponse getRollupJob(GetRollupJobRequest request, RequestOpt
179181

180182
public void getRollupJobAsync(GetRollupJobRequest request, RequestOptions options, ActionListener<GetRollupJobResponse> listener) {
181183
restHighLevelClient.performRequestAsyncAndParseEntity(request,
182-
RollupRequestConverters::getJob,
183-
options,
184-
GetRollupJobResponse::fromXContent,
185-
listener, Collections.emptySet());
184+
RollupRequestConverters::getJob,
185+
options,
186+
GetRollupJobResponse::fromXContent,
187+
listener, Collections.emptySet());
186188
}
187189

188190
/**
@@ -196,10 +198,10 @@ public void getRollupJobAsync(GetRollupJobRequest request, RequestOptions option
196198
*/
197199
public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, RequestOptions options) throws IOException {
198200
return restHighLevelClient.performRequestAndParseEntity(request,
199-
RollupRequestConverters::getRollupCaps,
200-
options,
201-
GetRollupCapsResponse::fromXContent,
202-
Collections.emptySet());
201+
RollupRequestConverters::getRollupCaps,
202+
options,
203+
GetRollupCapsResponse::fromXContent,
204+
Collections.emptySet());
203205
}
204206

205207
/**
@@ -211,12 +213,48 @@ public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request,
211213
* @param listener the listener to be notified upon request completion
212214
*/
213215
public void getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOptions options,
214-
ActionListener<GetRollupCapsResponse> listener) {
216+
ActionListener<GetRollupCapsResponse> listener) {
215217
restHighLevelClient.performRequestAsyncAndParseEntity(request,
216-
RollupRequestConverters::getRollupCaps,
217-
options,
218-
GetRollupCapsResponse::fromXContent,
219-
listener,
220-
Collections.emptySet());
218+
RollupRequestConverters::getRollupCaps,
219+
options,
220+
GetRollupCapsResponse::fromXContent,
221+
listener,
222+
Collections.emptySet());
223+
}
224+
225+
/**
226+
* Get the Rollup Index Capabilities of a rollup index or pattern
227+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">
228+
* the docs</a> for more.
229+
* @param request the request
230+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
231+
* @return the response
232+
* @throws IOException in case there is a problem sending the request or parsing back the response
233+
*/
234+
public GetRollupIndexCapsResponse getRollupIndexCapabilities(GetRollupIndexCapsRequest request,
235+
RequestOptions options) throws IOException {
236+
return restHighLevelClient.performRequestAndParseEntity(request,
237+
RollupRequestConverters::getRollupIndexCaps,
238+
options,
239+
GetRollupIndexCapsResponse::fromXContent,
240+
Collections.emptySet());
241+
}
242+
243+
/**
244+
* Asynchronously Get the Rollup Index Capabilities of a rollup index or pattern
245+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-index-caps.html">
246+
* the docs</a> for more.
247+
* @param request the request
248+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
249+
* @param listener the listener to be notified upon request completion
250+
*/
251+
public void getRollupIndexCapabilitiesAsync(GetRollupIndexCapsRequest request, RequestOptions options,
252+
ActionListener<GetRollupIndexCapsResponse> listener) {
253+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
254+
RollupRequestConverters::getRollupIndexCaps,
255+
options,
256+
GetRollupIndexCapsResponse::fromXContent,
257+
listener,
258+
Collections.emptySet());
221259
}
222260
}

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import org.apache.http.client.methods.HttpGet;
2323
import org.apache.http.client.methods.HttpPost;
2424
import org.apache.http.client.methods.HttpPut;
25-
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
2625
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
26+
import org.elasticsearch.client.rollup.GetRollupCapsRequest;
27+
import org.elasticsearch.client.rollup.GetRollupIndexCapsRequest;
2728
import org.elasticsearch.client.rollup.GetRollupJobRequest;
2829
import org.elasticsearch.client.rollup.PutRollupJobRequest;
2930
import org.elasticsearch.client.rollup.StartRollupJobRequest;
@@ -40,43 +41,52 @@ private RollupRequestConverters() {
4041

4142
static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOException {
4243
String endpoint = new RequestConverters.EndpointBuilder()
43-
.addPathPartAsIs("_xpack", "rollup", "job")
44-
.addPathPart(putRollupJobRequest.getConfig().getId())
45-
.build();
44+
.addPathPartAsIs("_xpack", "rollup", "job")
45+
.addPathPart(putRollupJobRequest.getConfig().getId())
46+
.build();
4647
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
4748
request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE));
4849
return request;
4950
}
5051

5152
static Request startJob(final StartRollupJobRequest startRollupJobRequest) throws IOException {
5253
String endpoint = new RequestConverters.EndpointBuilder()
53-
.addPathPartAsIs("_xpack", "rollup", "job")
54-
.addPathPart(startRollupJobRequest.getJobId())
55-
.addPathPartAsIs("_start")
56-
.build();
54+
.addPathPartAsIs("_xpack", "rollup", "job")
55+
.addPathPart(startRollupJobRequest.getJobId())
56+
.addPathPartAsIs("_start")
57+
.build();
5758
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
5859
return request;
5960
}
6061

6162
static Request getJob(final GetRollupJobRequest getRollupJobRequest) {
6263
String endpoint = new RequestConverters.EndpointBuilder()
63-
.addPathPartAsIs("_xpack", "rollup", "job")
64-
.addPathPart(getRollupJobRequest.getJobId())
65-
.build();
64+
.addPathPartAsIs("_xpack", "rollup", "job")
65+
.addPathPart(getRollupJobRequest.getJobId())
66+
.build();
6667
return new Request(HttpGet.METHOD_NAME, endpoint);
6768
}
6869

69-
7070
static Request getRollupCaps(final GetRollupCapsRequest getRollupCapsRequest) throws IOException {
7171
String endpoint = new RequestConverters.EndpointBuilder()
72-
.addPathPartAsIs("_xpack", "rollup", "data")
73-
.addPathPart(getRollupCapsRequest.getIndexPattern())
74-
.build();
72+
.addPathPartAsIs("_xpack", "rollup", "data")
73+
.addPathPart(getRollupCapsRequest.getIndexPattern())
74+
.build();
7575
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
7676
request.setEntity(createEntity(getRollupCapsRequest, REQUEST_BODY_CONTENT_TYPE));
7777
return request;
7878
}
7979

80+
static Request getRollupIndexCaps(final GetRollupIndexCapsRequest getRollupIndexCapsRequest) throws IOException {
81+
String endpoint = new RequestConverters.EndpointBuilder()
82+
.addCommaSeparatedPathParts(getRollupIndexCapsRequest.indices())
83+
.addPathPartAsIs("_xpack", "rollup", "data")
84+
.build();
85+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
86+
request.setEntity(createEntity(getRollupIndexCapsRequest, REQUEST_BODY_CONTENT_TYPE));
87+
return request;
88+
}
89+
8090
static Request deleteJob(final DeleteRollupJobRequest deleteRollupJobRequest) throws IOException {
8191
String endpoint = new RequestConverters.EndpointBuilder()
8292
.addPathPartAsIs("_xpack")

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
*/
1919
package org.elasticsearch.client.rollup;
2020

21-
import org.elasticsearch.common.Strings;
22-
import org.elasticsearch.common.xcontent.ToXContent;
23-
import org.elasticsearch.common.xcontent.ToXContentObject;
24-
import org.elasticsearch.common.xcontent.XContentBuilder;
2521
import org.elasticsearch.common.xcontent.XContentParser;
2622

2723
import java.io.IOException;
@@ -30,7 +26,7 @@
3026
import java.util.Map;
3127
import java.util.Objects;
3228

33-
public class GetRollupCapsResponse implements ToXContentObject {
29+
public class GetRollupCapsResponse {
3430

3531
private final Map<String, RollableIndexCaps> jobs;
3632

@@ -42,16 +38,6 @@ public Map<String, RollableIndexCaps> getJobs() {
4238
return jobs;
4339
}
4440

45-
@Override
46-
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
47-
builder.startObject();
48-
for (Map.Entry<String, RollableIndexCaps> entry : jobs.entrySet()) {
49-
entry.getValue().toXContent(builder, params);
50-
}
51-
builder.endObject();
52-
return builder;
53-
}
54-
5541
public static GetRollupCapsResponse fromXContent(final XContentParser parser) throws IOException {
5642
Map<String, RollableIndexCaps> jobs = new HashMap<>();
5743
XContentParser.Token token = parser.nextToken();
@@ -84,9 +70,4 @@ public boolean equals(Object obj) {
8470
GetRollupCapsResponse other = (GetRollupCapsResponse) obj;
8571
return Objects.equals(jobs, other.jobs);
8672
}
87-
88-
@Override
89-
public final String toString() {
90-
return Strings.toString(this);
91-
}
9273
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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.rollup;
20+
21+
import org.elasticsearch.action.support.IndicesOptions;
22+
import org.elasticsearch.client.Validatable;
23+
import org.elasticsearch.common.Strings;
24+
import org.elasticsearch.common.xcontent.ToXContentObject;
25+
import org.elasticsearch.common.xcontent.XContentBuilder;
26+
27+
import java.io.IOException;
28+
import java.util.Arrays;
29+
import java.util.Objects;
30+
31+
public class GetRollupIndexCapsRequest implements Validatable, ToXContentObject {
32+
private static final String INDICES = "indices";
33+
private static final String INDICES_OPTIONS = "indices_options";
34+
35+
private String[] indices;
36+
private IndicesOptions options;
37+
38+
public GetRollupIndexCapsRequest(final String... indices) {
39+
this(indices, IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED);
40+
}
41+
42+
public GetRollupIndexCapsRequest(final String[] indices, final IndicesOptions options) {
43+
if (indices == null || indices.length == 0) {
44+
throw new IllegalArgumentException("[indices] must not be null or empty");
45+
}
46+
for (String index : indices) {
47+
if (Strings.isNullOrEmpty(index)) {
48+
throw new IllegalArgumentException("[index] must not be null or empty");
49+
}
50+
}
51+
this.indices = indices;
52+
this.options = Objects.requireNonNull(options);
53+
}
54+
55+
public IndicesOptions indicesOptions() {
56+
return options;
57+
}
58+
59+
public String[] indices() {
60+
return indices;
61+
}
62+
63+
@Override
64+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
65+
builder.startObject();
66+
{
67+
builder.array(INDICES, indices);
68+
builder.startObject(INDICES_OPTIONS);
69+
{
70+
options.toXContent(builder, params);
71+
}
72+
builder.endObject();
73+
}
74+
builder.endObject();
75+
return builder;
76+
}
77+
78+
@Override
79+
public int hashCode() {
80+
return Objects.hash(Arrays.hashCode(indices), options);
81+
}
82+
83+
@Override
84+
public boolean equals(Object obj) {
85+
if (obj == null) {
86+
return false;
87+
}
88+
if (getClass() != obj.getClass()) {
89+
return false;
90+
}
91+
GetRollupIndexCapsRequest other = (GetRollupIndexCapsRequest) obj;
92+
return Arrays.equals(indices, other.indices)
93+
&& Objects.equals(options, other.options);
94+
}
95+
}

0 commit comments

Comments
 (0)