org.opensearch.client.indices.SimulateIndexTemplateResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearch-rest-high-level-client Show documentation
Show all versions of opensearch-rest-high-level-client Show documentation
OpenSearch subproject :client:rest-high-level
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.client.indices;
import org.opensearch.cluster.metadata.Template;
import org.opensearch.common.Nullable;
import org.opensearch.core.ParseField;
import org.opensearch.core.xcontent.ConstructingObjectParser;
import org.opensearch.core.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 PARSER = new ConstructingObjectParser<>(
"simulate_index_templates_response",
false,
a -> new SimulateIndexTemplateResponse(
a[0] != null ? (Template) a[0] : null,
a[1] != null
? ((List) a[1]).stream()
.collect(Collectors.toMap(IndexTemplateAndPatterns::name, IndexTemplateAndPatterns::indexPatterns))
: null
)
);
@SuppressWarnings("unchecked")
private static final ConstructingObjectParser INNER_PARSER = new ConstructingObjectParser<>(
"index_template_and_patterns",
false,
a -> new IndexTemplateAndPatterns((String) a[0], (List) a[1])
);
private static class IndexTemplateAndPatterns {
String name;
List indexPatterns;
IndexTemplateAndPatterns(String name, List indexPatterns) {
this.name = name;
this.indexPatterns = indexPatterns;
}
public String name() {
return name;
}
public List 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> overlappingTemplates;
SimulateIndexTemplateResponse(@Nullable Template resolvedTemplate, @Nullable Map> 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> 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())
+ "}";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy