-
Notifications
You must be signed in to change notification settings - Fork 25k
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 HLRC support for simulate index template api #55936
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2631807
Add HLRC support for simulate index template api.
andreidan c13c548
Fix checkstyle
andreidan da81b9c
Fix testApiNamingConventions test
andreidan 4324df9
Update description rest spec
andreidan 1013b89
Validate indexName in setter
andreidan 50b1956
Drop toXContent
andreidan e391eb6
Remove unused fields
andreidan 011e5fa
Unused import
andreidan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...gh-level/src/main/java/org/elasticsearch/client/indices/SimulateIndexTemplateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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.indices; | ||
|
||
import org.elasticsearch.client.TimedRequest; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A request to simulate matching a provided index name and an optional new index template against the existing index templates. | ||
*/ | ||
public class SimulateIndexTemplateRequest extends TimedRequest implements ToXContentObject { | ||
|
||
private static final ParseField INDEX_NAME = new ParseField("index_name"); | ||
private static final ParseField INDEX_TEMPLATE = new ParseField("index_template"); | ||
|
||
private String indexName; | ||
|
||
@Nullable | ||
private PutIndexTemplateV2Request indexTemplateV2Request; | ||
|
||
public SimulateIndexTemplateRequest(String indexName) { | ||
if (Strings.isNullOrEmpty(indexName)) { | ||
throw new IllegalArgumentException("index name cannot be null or empty"); | ||
} | ||
this.indexName = indexName; | ||
} | ||
|
||
/** | ||
* Return the index name for which we simulate the index template matching. | ||
*/ | ||
public String indexName() { | ||
return indexName; | ||
} | ||
|
||
/** | ||
* Set the index name to simulate template matching against the index templates in the system. | ||
*/ | ||
public SimulateIndexTemplateRequest indexName(String indexName) { | ||
this.indexName = indexName; | ||
return this; | ||
} | ||
|
||
/** | ||
* An optional new template request will be part of the index template simulation. | ||
*/ | ||
@Nullable | ||
public PutIndexTemplateV2Request indexTemplateV2Request() { | ||
return indexTemplateV2Request; | ||
} | ||
|
||
/** | ||
* Optionally, define a new template request which will included in the index simulation as if it was an index template stored in the | ||
* system. The new template will be validated just as a regular, standalone, live, new index template request. | ||
*/ | ||
public SimulateIndexTemplateRequest indexTemplateV2Request(@Nullable PutIndexTemplateV2Request indexTemplateV2Request) { | ||
this.indexTemplateV2Request = indexTemplateV2Request; | ||
return this; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) 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. It seems strange to have a toXContent that produces a body that isn't actually what gets sent (since we don't include the index name in the request body for simulation), do we actually need this method? Can we remove it entirely? |
||
builder.startObject(); | ||
builder.field(INDEX_NAME.getPreferredName(), indexName); | ||
if (indexTemplateV2Request != null) { | ||
indexTemplateV2Request.toXContent(builder, params); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
...h-level/src/main/java/org/elasticsearch/client/indices/SimulateIndexTemplateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* 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.indices; | ||
|
||
import org.elasticsearch.cluster.metadata.Template; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class SimulateIndexTemplateResponse { | ||
|
||
private static final ParseField TEMPLATE = new ParseField("template"); | ||
private static final ParseField OVERLAPPING = new ParseField("overlapping"); | ||
private static final ParseField NAME = new ParseField("name"); | ||
private static final ParseField INDEX_PATTERNS = new ParseField("index_patterns"); | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<SimulateIndexTemplateResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("simulate_index_templates_response", false, | ||
a -> new SimulateIndexTemplateResponse( | ||
a[0] != null ? (Template) a[0] : null, | ||
a[1] != null ? | ||
((List<IndexTemplateAndPatterns>) a[1]).stream() | ||
.collect(Collectors.toMap(IndexTemplateAndPatterns::name, IndexTemplateAndPatterns::indexPatterns)) : null | ||
) | ||
); | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<IndexTemplateAndPatterns, Void> INNER_PARSER = | ||
new ConstructingObjectParser<>("index_template_and_patterns", false, | ||
a -> new IndexTemplateAndPatterns((String) a[0], (List<String>) a[1])); | ||
|
||
private static class IndexTemplateAndPatterns { | ||
String name; | ||
List<String> indexPatterns; | ||
|
||
IndexTemplateAndPatterns(String name, List<String> indexPatterns) { | ||
this.name = name; | ||
this.indexPatterns = indexPatterns; | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public List<String> indexPatterns() { | ||
return indexPatterns; | ||
} | ||
} | ||
|
||
static { | ||
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), Template.PARSER, TEMPLATE); | ||
INNER_PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME); | ||
INNER_PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), INDEX_PATTERNS); | ||
PARSER.declareObjectArray(ConstructingObjectParser.optionalConstructorArg(), INNER_PARSER, OVERLAPPING); | ||
} | ||
|
||
@Nullable | ||
// the resolved settings, mappings and aliases for the matched templates, if any | ||
private Template resolvedTemplate; | ||
|
||
@Nullable | ||
// a map of template names and their index patterns that would overlap when matching the given index name | ||
private Map<String, List<String>> overlappingTemplates; | ||
|
||
SimulateIndexTemplateResponse(@Nullable Template resolvedTemplate, @Nullable Map<String, List<String>> overlappingTemplates) { | ||
this.resolvedTemplate = resolvedTemplate; | ||
this.overlappingTemplates = overlappingTemplates; | ||
} | ||
|
||
public static SimulateIndexTemplateResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
public Template resolvedTemplate() { | ||
return resolvedTemplate; | ||
} | ||
|
||
public Map<String, List<String>> overlappingTemplates() { | ||
return overlappingTemplates; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
SimulateIndexTemplateResponse that = (SimulateIndexTemplateResponse) o; | ||
return Objects.equals(resolvedTemplate, that.resolvedTemplate) | ||
&& Objects.deepEquals(overlappingTemplates, that.overlappingTemplates); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(resolvedTemplate, overlappingTemplates); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SimulateIndexTemplateResponse{" + "resolved template=" + resolvedTemplate + ", overlapping templates=" | ||
+ String.join("|", overlappingTemplates.keySet()) + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We validate the
indexName
in the constructor but maybe we should also validate it here?