co.elastic.clients.elasticsearch.cluster.PutComponentTemplateRequest Maven / Gradle / Ivy
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. 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 co.elastic.clients.elasticsearch.cluster;
import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.Time;
import co.elastic.clients.elasticsearch.indices.IndexState;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.endpoints.SimpleEndpoint;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import jakarta.json.stream.JsonGenerator;
import java.lang.Boolean;
import java.lang.Long;
import java.lang.String;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
//----------------------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------------------
//
// This code is generated from the Elasticsearch API specification
// at https://github.com/elastic/elasticsearch-specification
//
// Manual updates to this file will be lost when the code is
// re-generated.
//
// If you find a property that is missing or wrongly typed, please
// open an issue or a PR on the API specification repository.
//
//----------------------------------------------------------------
// typedef: cluster.put_component_template.Request
/**
* Create or update a component template. Creates or updates a component
* template. Component templates are building blocks for constructing index
* templates that specify index mappings, settings, and aliases.
*
* An index template can be composed of multiple component templates. To use a
* component template, specify it in an index template’s
* composed_of
list. Component templates are only applied to new
* data streams and indices as part of a matching index template.
*
* Settings and mappings specified directly in the index template or the create
* index request override any settings or mappings specified in a component
* template.
*
* Component templates are only used during index creation. For data streams,
* this includes data stream creation and the creation of a stream’s backing
* indices. Changes to component templates do not affect existing indices,
* including a stream’s backing indices.
*
* You can use C-style /* *\/
block comments in component
* templates. You can include comments anywhere in the request body except
* before the opening curly bracket.
*
* @see API
* specification
*/
@JsonpDeserializable
public class PutComponentTemplateRequest extends RequestBase implements JsonpSerializable {
private final Map meta;
@Nullable
private final Boolean create;
@Nullable
private final Boolean deprecated;
@Nullable
private final Time masterTimeout;
private final String name;
private final IndexState template;
@Nullable
private final Long version;
// ---------------------------------------------------------------------------------------------
private PutComponentTemplateRequest(Builder builder) {
this.meta = ApiTypeHelper.unmodifiable(builder.meta);
this.create = builder.create;
this.deprecated = builder.deprecated;
this.masterTimeout = builder.masterTimeout;
this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name");
this.template = ApiTypeHelper.requireNonNull(builder.template, this, "template");
this.version = builder.version;
}
public static PutComponentTemplateRequest of(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* Optional user metadata about the component template. May have any contents.
* This map is not automatically generated by Elasticsearch. This information is
* stored in the cluster state, so keeping it short is preferable. To unset
* _meta
, replace the template without specifying this information.
*
* API name: {@code _meta}
*/
public final Map meta() {
return this.meta;
}
/**
* If true
, this request cannot replace or update existing
* component templates.
*
* API name: {@code create}
*/
@Nullable
public final Boolean create() {
return this.create;
}
/**
* Marks this index template as deprecated. When creating or updating a
* non-deprecated index template that uses deprecated components, Elasticsearch
* will emit a deprecation warning.
*
* API name: {@code deprecated}
*/
@Nullable
public final Boolean deprecated() {
return this.deprecated;
}
/**
* Period to wait for a connection to the master node. If no response is
* received before the timeout expires, the request fails and returns an error.
*
* API name: {@code master_timeout}
*/
@Nullable
public final Time masterTimeout() {
return this.masterTimeout;
}
/**
* Required - Name of the component template to create. Elasticsearch includes
* the following built-in component templates: logs-mappings
;
* logs-settings
; metrics-mappings
;
* metrics-settings
;synthetics-mapping
;
* synthetics-settings
. Elastic Agent uses these templates to
* configure backing indices for its data streams. If you use Elastic Agent and
* want to overwrite one of these templates, set the version
for
* your replacement template higher than the current version. If you don’t use
* Elastic Agent and want to disable all built-in component and index templates,
* set stack.templates.enabled
to false
using the
* cluster update settings API.
*
* API name: {@code name}
*/
public final String name() {
return this.name;
}
/**
* Required - The template to be applied which includes mappings, settings, or
* aliases configuration.
*
* API name: {@code template}
*/
public final IndexState template() {
return this.template;
}
/**
* Version number used to manage component templates externally. This number
* isn't automatically generated or incremented by Elasticsearch. To unset a
* version, replace the template without specifying a version.
*
* API name: {@code version}
*/
@Nullable
public final Long version() {
return this.version;
}
/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (ApiTypeHelper.isDefined(this.meta)) {
generator.writeKey("_meta");
generator.writeStartObject();
for (Map.Entry item0 : this.meta.entrySet()) {
generator.writeKey(item0.getKey());
item0.getValue().serialize(generator, mapper);
}
generator.writeEnd();
}
if (this.deprecated != null) {
generator.writeKey("deprecated");
generator.write(this.deprecated);
}
generator.writeKey("template");
this.template.serialize(generator, mapper);
if (this.version != null) {
generator.writeKey("version");
generator.write(this.version);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link PutComponentTemplateRequest}.
*/
public static class Builder extends RequestBase.AbstractBuilder
implements
ObjectBuilder {
@Nullable
private Map meta;
@Nullable
private Boolean create;
@Nullable
private Boolean deprecated;
@Nullable
private Time masterTimeout;
private String name;
private IndexState template;
@Nullable
private Long version;
/**
* Optional user metadata about the component template. May have any contents.
* This map is not automatically generated by Elasticsearch. This information is
* stored in the cluster state, so keeping it short is preferable. To unset
* _meta
, replace the template without specifying this information.
*
* API name: {@code _meta}
*
* Adds all entries of map
to meta
.
*/
public final Builder meta(Map map) {
this.meta = _mapPutAll(this.meta, map);
return this;
}
/**
* Optional user metadata about the component template. May have any contents.
* This map is not automatically generated by Elasticsearch. This information is
* stored in the cluster state, so keeping it short is preferable. To unset
* _meta
, replace the template without specifying this information.
*
* API name: {@code _meta}
*
* Adds an entry to meta
.
*/
public final Builder meta(String key, JsonData value) {
this.meta = _mapPut(this.meta, key, value);
return this;
}
/**
* If true
, this request cannot replace or update existing
* component templates.
*
* API name: {@code create}
*/
public final Builder create(@Nullable Boolean value) {
this.create = value;
return this;
}
/**
* Marks this index template as deprecated. When creating or updating a
* non-deprecated index template that uses deprecated components, Elasticsearch
* will emit a deprecation warning.
*
* API name: {@code deprecated}
*/
public final Builder deprecated(@Nullable Boolean value) {
this.deprecated = value;
return this;
}
/**
* Period to wait for a connection to the master node. If no response is
* received before the timeout expires, the request fails and returns an error.
*
* API name: {@code master_timeout}
*/
public final Builder masterTimeout(@Nullable Time value) {
this.masterTimeout = value;
return this;
}
/**
* Period to wait for a connection to the master node. If no response is
* received before the timeout expires, the request fails and returns an error.
*
* API name: {@code master_timeout}
*/
public final Builder masterTimeout(Function> fn) {
return this.masterTimeout(fn.apply(new Time.Builder()).build());
}
/**
* Required - Name of the component template to create. Elasticsearch includes
* the following built-in component templates: logs-mappings
;
* logs-settings
; metrics-mappings
;
* metrics-settings
;synthetics-mapping
;
* synthetics-settings
. Elastic Agent uses these templates to
* configure backing indices for its data streams. If you use Elastic Agent and
* want to overwrite one of these templates, set the version
for
* your replacement template higher than the current version. If you don’t use
* Elastic Agent and want to disable all built-in component and index templates,
* set stack.templates.enabled
to false
using the
* cluster update settings API.
*
* API name: {@code name}
*/
public final Builder name(String value) {
this.name = value;
return this;
}
/**
* Required - The template to be applied which includes mappings, settings, or
* aliases configuration.
*
* API name: {@code template}
*/
public final Builder template(IndexState value) {
this.template = value;
return this;
}
/**
* Required - The template to be applied which includes mappings, settings, or
* aliases configuration.
*
* API name: {@code template}
*/
public final Builder template(Function> fn) {
return this.template(fn.apply(new IndexState.Builder()).build());
}
/**
* Version number used to manage component templates externally. This number
* isn't automatically generated or incremented by Elasticsearch. To unset a
* version, replace the template without specifying a version.
*
* API name: {@code version}
*/
public final Builder version(@Nullable Long value) {
this.version = value;
return this;
}
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link PutComponentTemplateRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public PutComponentTemplateRequest build() {
_checkSingleUse();
return new PutComponentTemplateRequest(this);
}
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link PutComponentTemplateRequest}
*/
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, PutComponentTemplateRequest::setupPutComponentTemplateRequestDeserializer);
protected static void setupPutComponentTemplateRequestDeserializer(
ObjectDeserializer op) {
op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::deprecated, JsonpDeserializer.booleanDeserializer(), "deprecated");
op.add(Builder::template, IndexState._DESERIALIZER, "template");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
}
// ---------------------------------------------------------------------------------------------
/**
* Endpoint "{@code cluster.put_component_template}".
*/
public static final Endpoint _ENDPOINT = new SimpleEndpoint<>(
"es/cluster.put_component_template",
// Request method
request -> {
return "PUT";
},
// Request path
request -> {
final int _name = 1 << 0;
int propsSet = 0;
propsSet |= _name;
if (propsSet == (_name)) {
StringBuilder buf = new StringBuilder();
buf.append("/_component_template");
buf.append("/");
SimpleEndpoint.pathEncode(request.name, buf);
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");
},
// Path parameters
request -> {
Map params = new HashMap<>();
final int _name = 1 << 0;
int propsSet = 0;
propsSet |= _name;
if (propsSet == (_name)) {
params.put("name", request.name);
}
return params;
},
// Request parameters
request -> {
Map params = new HashMap<>();
if (request.masterTimeout != null) {
params.put("master_timeout", request.masterTimeout._toJsonString());
}
if (request.create != null) {
params.put("create", String.valueOf(request.create));
}
return params;
}, SimpleEndpoint.emptyMap(), true, PutComponentTemplateResponse._DESERIALIZER);
}