-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add GetRollupCaps API to high level rest client #32880
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 17 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 |
---|---|---|
|
@@ -1007,3 +1007,4 @@ private static String encodePart(String pathPart) { | |
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.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; | ||
|
||
public class GetRollupCapsRequest implements Validatable, ToXContentObject { | ||
private static final String ID = "id"; | ||
polyfractal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final String indexPattern; | ||
|
||
public GetRollupCapsRequest(final 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 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 final Map<String, RollableIndexCaps> jobs; | ||
|
||
public GetRollupCapsResponse(final 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,103 @@ | ||
/* | ||
* 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; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 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 final String indexName; | ||
private final List<RollupJobCaps> jobCaps; | ||
|
||
RollableIndexCaps(final String indexName, final List<RollupJobCaps> caps) { | ||
this.indexName = indexName; | ||
this.jobCaps = Collections.unmodifiableList(Objects.requireNonNull(caps) | ||
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. Is it sorted for XContent rendering purpose? If so maybe it could be done in the toXContent() method instead of the constructor? 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. It is... but isn't it better to sort once in the ctor instead of each time toXContent is called? Since jobcaps is final and unmodifiable, we know it will only happen once and won't ever become unsorted. 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. (also note iirc it's mainly there to make testing from yaml rest tests easier) 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. Ok, let's keep the sorting in the ctor. I wanted to avoid the sort to be done each time the object is instantiated but this is a HLRC specific object so it will be done just one time |
||
.stream() | ||
.sorted(Comparator.comparing(RollupJobCaps::getJobID)) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
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; | ||
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.