-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Add GetRollupCaps API to high level rest client #32880
Changes from 10 commits
38fca66
7667ed9
2f340dd
dfb0b14
310e690
ff85234
a38379a
19cfc2c
7754803
89ab8a9
157db4a
6dd3fd0
dda7039
5edd406
0dac0d0
98b0585
39fb7dd
9613d19
0716c29
a74dc3e
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 |
---|---|---|
|
@@ -993,3 +993,4 @@ private static String encodePart(String pathPart) { | |
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
package org.elasticsearch.client; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.client.rollup.GetRollupCapsRequest; | ||
import org.elasticsearch.client.rollup.GetRollupCapsResponse; | ||
import org.elasticsearch.client.rollup.PutRollupJobRequest; | ||
import org.elasticsearch.client.rollup.PutRollupJobResponse; | ||
|
||
|
@@ -73,4 +75,35 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option | |
PutRollupJobResponse::fromXContent, | ||
listener, Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Get the Rollup Capabilities of a target (non-rollup) index or pattern | ||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/rollup-get-rollup-caps.html"> | ||
* the docs</a> for more. | ||
* @param request the request | ||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @return the response | ||
* @throws IOException in case there is a problem sending the request or parsing back the response | ||
*/ | ||
public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, | ||
RollupRequestConverters::getRollupCaps, | ||
options, | ||
GetRollupCapsResponse::fromXContent, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Asynchronously put a rollup job into the cluster | ||
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. Nit: doc not up to date |
||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html"> | ||
* the docs</a> for more. | ||
* @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 getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOptions options, | ||
ActionListener<GetRollupCapsResponse> listener) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RollupRequestConverters::getRollupCaps, options, | ||
GetRollupCapsResponse::fromXContent, listener, Collections.emptySet()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
*/ | ||
package org.elasticsearch.client; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.elasticsearch.client.rollup.GetRollupCapsRequest; | ||
import org.elasticsearch.client.rollup.PutRollupJobRequest; | ||
|
||
import java.io.IOException; | ||
|
@@ -42,4 +44,16 @@ static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOEx | |
request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE)); | ||
return request; | ||
} | ||
|
||
static Request getRollupCaps(GetRollupCapsRequest getRollupCapsRequest) throws IOException { | ||
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. getRollupCapsRequest can be final |
||
String endpoint = new RequestConverters.EndpointBuilder() | ||
.addPathPartAsIs("_xpack") | ||
.addPathPartAsIs("rollup") | ||
.addPathPartAsIs("data") | ||
.addPathPart(getRollupCapsRequest.getIndexPattern()) | ||
.build(); | ||
Request request = new Request(HttpGet.METHOD_NAME, endpoint); | ||
request.setEntity(createEntity(getRollupCapsRequest, REQUEST_BODY_CONTENT_TYPE)); | ||
return request; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.rollup; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.ValidationException; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class GetRollupCapsRequest implements Validatable, ToXContentObject { | ||
private String indexPattern; | ||
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. Can be final too |
||
private static final String ID = "id"; | ||
polyfractal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public GetRollupCapsRequest(String indexPattern) { | ||
if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { | ||
this.indexPattern = MetaData.ALL; | ||
} else { | ||
this.indexPattern = indexPattern; | ||
} | ||
} | ||
|
||
public String getIndexPattern() { | ||
return indexPattern; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(ID, indexPattern); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { | ||
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. You don't need this, this is the default implementation |
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(indexPattern); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetRollupCapsRequest other = (GetRollupCapsRequest) obj; | ||
return Objects.equals(indexPattern, other.indexPattern); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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.rollup; | ||
|
||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class GetRollupCapsResponse implements ToXContentObject { | ||
|
||
private Map<String, RollableIndexCaps> jobs = Collections.emptyMap(); | ||
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. Could be final |
||
|
||
public GetRollupCapsResponse(Map<String, RollableIndexCaps> jobs) { | ||
this.jobs = Collections.unmodifiableMap(Objects.requireNonNull(jobs)); | ||
} | ||
|
||
public Map<String, RollableIndexCaps> getJobs() { | ||
return jobs; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
for (Map.Entry<String, RollableIndexCaps> entry : jobs.entrySet()) { | ||
entry.getValue().toXContent(builder, params); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public static GetRollupCapsResponse fromXContent(final XContentParser parser) throws IOException { | ||
Map<String, RollableIndexCaps> jobs = new HashMap<>(); | ||
XContentParser.Token token = parser.nextToken(); | ||
if (token.equals(XContentParser.Token.START_OBJECT)) { | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
if (token.equals(XContentParser.Token.FIELD_NAME)) { | ||
String pattern = parser.currentName(); | ||
|
||
RollableIndexCaps cap = RollableIndexCaps.PARSER.apply(pattern).apply(parser, null); | ||
jobs.put(pattern, cap); | ||
} | ||
} | ||
} | ||
return new GetRollupCapsResponse(jobs); | ||
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. Maybe convert |
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobs); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetRollupCapsResponse other = (GetRollupCapsResponse) obj; | ||
return Objects.equals(jobs, other.jobs); | ||
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. deepEquals instead? 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 believe deepEquals is only needed for arrays (jobs is a map)? 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. Oh right sorry |
||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.rollup; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentFragment; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Represents the rollup capabilities of a non-rollup index. E.g. what values/aggregations | ||
* were rolled up for this index, in what rollup jobs that data is stored and where those | ||
* concrete rollup indices exist | ||
* | ||
* The index name can either be a single index, or an index pattern (logstash-*) | ||
*/ | ||
public class RollableIndexCaps implements ToXContentFragment { | ||
private static final ParseField ROLLUP_JOBS = new ParseField("rollup_jobs"); | ||
|
||
public static final Function<String, ConstructingObjectParser<RollableIndexCaps, Void>> PARSER = indexName -> { | ||
@SuppressWarnings("unchecked") | ||
ConstructingObjectParser<RollableIndexCaps, Void> p | ||
= new ConstructingObjectParser<>(indexName, | ||
a -> new RollableIndexCaps(indexName, (List<RollupJobCaps>) a[0])); | ||
|
||
p.declareObjectArray(ConstructingObjectParser.constructorArg(), RollupJobCaps.PARSER::apply, | ||
ROLLUP_JOBS); | ||
return p; | ||
}; | ||
|
||
private String indexName; | ||
private List<RollupJobCaps> jobCaps; | ||
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. Both can be final |
||
|
||
public RollableIndexCaps(String indexName, List<RollupJobCaps> caps) { | ||
this.indexName = indexName; | ||
this.jobCaps = Objects.requireNonNull(caps); | ||
this.jobCaps.sort(Comparator.comparing(RollupJobCaps::getJobID)); | ||
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. You should create a copy of the list, then sort it, then make it unmodifiable |
||
this.jobCaps = Collections.unmodifiableList(jobCaps); | ||
} | ||
|
||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
public List<RollupJobCaps> getJobCaps() { | ||
return jobCaps; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(indexName); | ||
builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
RollableIndexCaps that = (RollableIndexCaps) other; | ||
|
||
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. extra line |
||
return Objects.deepEquals(this.jobCaps, that.jobCaps) | ||
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. You can use Objects.equals() here |
||
&& Objects.equals(this.indexName, that.indexName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobCaps, indexName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason these two methods have drastically different indentation? one of them is a newline every param and the Async below is just 2 lines.